From 0d52e07688cfa96bd558493d11898dfe2bbec580 Mon Sep 17 00:00:00 2001 From: avinash-bharti Date: Tue, 30 Aug 2022 02:21:56 +0530 Subject: [PATCH 1/8] Add w3c support --- Gemfile | 2 +- README.md | 8 ++++- android/browserstack_sample.rb | 45 ++++++++++++------------ android/browserstack_sample_local.rb | 51 ++++++++++++++-------------- ios/browserstack_sample.rb | 45 ++++++++++++------------ ios/browserstack_sample_local.rb | 44 ++++++++++++------------ 6 files changed, 102 insertions(+), 93 deletions(-) diff --git a/Gemfile b/Gemfile index 6d4947a..3a562e1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ source 'http://rubygems.org' -gem 'appium_lib', ">=10.5.0" +gem 'appium_lib', ">=12.0.1" gem 'browserstack-local', ">=1.3.0" \ No newline at end of file diff --git a/README.md b/README.md index 400f7ef..5b7726a 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,12 @@ This repository demonstrates how to run Appium Ruby tests on BrowserStack App Automate. +## Based on + +These code samples are currently based on: + +- **appium_lib:** `12.0.1` +- **Protocol:** `W3C` ## Setup ### Requirements @@ -94,7 +100,7 @@ Open `browserstack_sample_local.rb` file in `android` or `ios` directory : - Set the device and OS version -- Ensure that `browserstack.local` capability is set to `true`. Within the test script, there is code snippet that automatically establishes Local Testing connection to BrowserStack servers using Ruby binding for BrowserStack Local. +- Ensure that `local` capability is set to `true`. Within the test script, there is code snippet that automatically establishes Local Testing connection to BrowserStack servers using Ruby binding for BrowserStack Local. - If you have uploaded your own app update the test case diff --git a/android/browserstack_sample.rb b/android/browserstack_sample.rb index f0aac8f..4e1710c 100644 --- a/android/browserstack_sample.rb +++ b/android/browserstack_sample.rb @@ -2,32 +2,35 @@ require 'appium_lib' require 'selenium-webdriver' -caps = {} -# Set your access credentials -caps['browserstack.user'] = 'YOUR_USERNAME' -caps['browserstack.key'] = 'YOUR_ACCESS_KEY' - -# Set URL of the application under test -caps['app'] = 'bs://' - -# Specify device and os_version for testing -caps['device'] = 'Google Pixel 3' -caps['os_version'] = '9.0' - -# Set other BrowserStack capabilities -caps['project'] = 'First Ruby project' -caps['build'] = 'browserstack-build-1' -caps['name'] = 'single_test' - -#Set the platform name -caps['platformName'] = 'android' +capabilities = { + # Specify device and os_version for testing + "platformName" => "android", + "platformVersion" => "9.0", + "deviceName" => "Google Pixel 3", + + # Set URL of the application under test + "app" => "bs://b8fc2f550dee29a650835da5c1e1a1cfac4d1821", + + # Set other BrowserStack capabilities + 'bstack:options' => { + "projectName" => "First Ruby project", + "buildName" => "browserstack-build-1", + "sessionName" => "single_test", + "debug" => "true", + "networkLogs" => "true", + + # Set your access credentials + "userName": "avinashbharti_2VdzKZ", + "accessKey": "F7EkSyLimdVXj7JXyjWz" + }, +} # Initialize the remote Webdriver using BrowserStack remote URL # and desired capabilities defined above appium_driver = Appium::Driver.new({ - 'caps' => caps, + 'caps' => capabilities, 'appium_lib' => { - :server_url => "http://hub-cloud.browserstack.com/wd/hub" + :server_url => "http://hub.browserstack.com/wd/hub" }}, true) driver = appium_driver.start_driver diff --git a/android/browserstack_sample_local.rb b/android/browserstack_sample_local.rb index 861aae5..58156d9 100644 --- a/android/browserstack_sample_local.rb +++ b/android/browserstack_sample_local.rb @@ -3,30 +3,29 @@ require 'selenium-webdriver' require 'browserstack/local' -username = 'YOUR_USERNAME' -access_key = 'YOUR_ACCESS_KEY' - -caps = {} -# Set your access credentials -caps['browserstack.user'] = username -caps['browserstack.key'] = access_key - -# Set URL of the application under test -caps['app'] = 'bs://' - -# Specify device and os_version for testing -caps['device'] = 'Google Pixel 3' -caps['os_version'] = '9.0' - -# Set browserstack.local capability as true -caps['browserstack.local'] = true - -# Set other BrowserStack capabilities -caps['project'] = 'First Ruby project' -caps['build'] = 'browserstack-build-1' -caps['name'] = 'local_test' -caps['platformName'] = 'android' -caps['browserstack.debug'] = true +capabilities = { + # Specify device and os_version for testing + "platformName" => "android", + "platformVersion" => "9.0", + "deviceName" => "Google Pixel 3", + + # Set URL of the application under test + "app" => "bs://", + + # Set other BrowserStack capabilities + 'bstack:options' => { + "projectName" => "First Ruby project", + "buildName" => "browserstack-build-1", + "sessionName" => "local_test", + "debug" => "true", + "local" => "true", + "networkLogs" => "true", + + # Set your access credentials + "userName": "BROWSERSTACK_USERNAME", + "accessKey": "BROWSERSTACK_ACCESS_KEY" + }, +} # Start browserstack local bs_local = BrowserStack::Local.new @@ -36,9 +35,9 @@ # Initialize the remote Webdriver using BrowserStack remote URL # and desired capabilities defined above appium_driver = Appium::Driver.new({ - 'caps' => caps, + 'caps' => capabilities, 'appium_lib' => { - :server_url => "http://hub-cloud.browserstack.com/wd/hub" + :server_url => "http://hub.browserstack.com/wd/hub" }}, true) driver = appium_driver.start_driver diff --git a/ios/browserstack_sample.rb b/ios/browserstack_sample.rb index 152d65d..a2db50e 100644 --- a/ios/browserstack_sample.rb +++ b/ios/browserstack_sample.rb @@ -2,32 +2,35 @@ require 'appium_lib' require 'selenium-webdriver' -caps = {} -# Set your access credentials -caps['browserstack.user'] = 'YOUR_USERNAME' -caps['browserstack.key'] = 'YOUR_ACCESS_KEY' - -# Set URL of the application under test -caps['app'] = 'bs://' - -# Specify device and os_version for testing -caps['device'] = "iPhone 11 Pro" -caps['os_version'] = "13" - -# Set other BrowserStack capabilities -caps['project'] = 'First Ruby project' -caps['build'] = 'browserstack-build-1' -caps['name'] = 'single_test' - -#Set the platform name -caps['platformName'] = 'iOS' +capabilities = { + # Specify device and os_version for testing + "platformName" => "iOS", + "platformVersion" => "13", + "deviceName" => "iPhone 11 Pro", + + # Set URL of the application under test + "app" => "bs://bs://", + + # Set other BrowserStack capabilities + 'bstack:options' => { + "projectName" => "First Ruby project", + "buildName" => "browserstack-build-1", + "sessionName" => "single_test", + "debug" => "true", + "networkLogs" => "true", + + # Set your access credentials + "userName": "BROWSERSTACK_USERNAME", + "accessKey": "BROWSERSTACK_ACCESS_KEY" + }, +} # Initialize the remote Webdriver using BrowserStack remote URL # and desired capabilities defined above appium_driver = Appium::Driver.new({ - 'caps' => caps, + 'caps' => capabilities, 'appium_lib' => { - :server_url => "http://hub-cloud.browserstack.com/wd/hub" + :server_url => "http://hub.browserstack.com/wd/hub" }}, true) driver = appium_driver.start_driver diff --git a/ios/browserstack_sample_local.rb b/ios/browserstack_sample_local.rb index 26c8fb1..9fec09b 100644 --- a/ios/browserstack_sample_local.rb +++ b/ios/browserstack_sample_local.rb @@ -3,31 +3,29 @@ require 'selenium-webdriver' require 'browserstack/local' +capabilities = { + # Specify device and os_version for testing + "platformName" => "iOS", + "platformVersion" => "12", + "deviceName" => "iPhone XS", -username = 'YOUR_USERNAME' -access_key = 'YOUR_ACCESS_KEY' + # Set URL of the application under test + "app" => "bs://bs://", -caps = {} -# Set your access credentials -caps['browserstack.user'] = username -caps['browserstack.key'] = access_key + # Set other BrowserStack capabilities + 'bstack:options' => { + "projectName" => "First Ruby project", + "buildName" => "browserstack-build-1", + "sessionName" => "single_test", + "debug" => "true", + "local" => "true" + "networkLogs" => "true", -# Set URL of the application under test -caps['app'] = 'bs://' - -# Specify device and os_version for testing -caps['device'] = "iPhone 11 Pro" -caps['os_version'] = "13" - -# Set browserstack.local capability as true -caps['browserstack.local'] = true - -# Set other BrowserStack capabilities -caps['project'] = 'First Ruby project' -caps['build'] = 'browserstack-build-1' -caps['name'] = 'local_test' -caps['platformName'] = 'iOS' -caps['browserstack.debug'] = true + # Set your access credentials + "userName": "BROWSERSTACK_USERNAME", + "accessKey": "BROWSERSTACK_ACCESS_KEY" + }, +} # Start browserstack local bs_local = BrowserStack::Local.new @@ -39,7 +37,7 @@ appium_driver = Appium::Driver.new({ 'caps' => caps, 'appium_lib' => { - :server_url => "http://hub-cloud.browserstack.com/wd/hub" + :server_url => "http://hub.browserstack.com/wd/hub" }}, true) driver = appium_driver.start_driver From d05d110f31c1cdf24ea2b26be414d1223a2f97d1 Mon Sep 17 00:00:00 2001 From: avinash-bharti Date: Tue, 30 Aug 2022 10:06:26 +0530 Subject: [PATCH 2/8] revert keys --- android/browserstack_sample.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/android/browserstack_sample.rb b/android/browserstack_sample.rb index 4e1710c..e78e164 100644 --- a/android/browserstack_sample.rb +++ b/android/browserstack_sample.rb @@ -9,7 +9,7 @@ "deviceName" => "Google Pixel 3", # Set URL of the application under test - "app" => "bs://b8fc2f550dee29a650835da5c1e1a1cfac4d1821", + "app" => "bs://bs://", # Set other BrowserStack capabilities 'bstack:options' => { @@ -20,8 +20,8 @@ "networkLogs" => "true", # Set your access credentials - "userName": "avinashbharti_2VdzKZ", - "accessKey": "F7EkSyLimdVXj7JXyjWz" + "userName": "BROWSERSTACK_USERNAME", + "accessKey": "BROWSERSTACK_ACCESS_KEY" }, } From 19d9f3cc6f4d3feb642c23730416642d78c2ec98 Mon Sep 17 00:00:00 2001 From: avinash-bharti Date: Tue, 30 Aug 2022 10:10:33 +0530 Subject: [PATCH 3/8] Fix typo in appid --- android/browserstack_sample.rb | 2 +- ios/browserstack_sample.rb | 2 +- ios/browserstack_sample_local.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/android/browserstack_sample.rb b/android/browserstack_sample.rb index e78e164..5e0b35e 100644 --- a/android/browserstack_sample.rb +++ b/android/browserstack_sample.rb @@ -9,7 +9,7 @@ "deviceName" => "Google Pixel 3", # Set URL of the application under test - "app" => "bs://bs://", + "app" => "bs://", # Set other BrowserStack capabilities 'bstack:options' => { diff --git a/ios/browserstack_sample.rb b/ios/browserstack_sample.rb index a2db50e..9bc1c04 100644 --- a/ios/browserstack_sample.rb +++ b/ios/browserstack_sample.rb @@ -9,7 +9,7 @@ "deviceName" => "iPhone 11 Pro", # Set URL of the application under test - "app" => "bs://bs://", + "app" => "bs://", # Set other BrowserStack capabilities 'bstack:options' => { diff --git a/ios/browserstack_sample_local.rb b/ios/browserstack_sample_local.rb index 9fec09b..ecae0c6 100644 --- a/ios/browserstack_sample_local.rb +++ b/ios/browserstack_sample_local.rb @@ -10,7 +10,7 @@ "deviceName" => "iPhone XS", # Set URL of the application under test - "app" => "bs://bs://", + "app" => "bs://", # Set other BrowserStack capabilities 'bstack:options' => { From d73683d7c10ac23dd248948575487812f631c7d6 Mon Sep 17 00:00:00 2001 From: avinash-bharti Date: Tue, 30 Aug 2022 10:11:43 +0530 Subject: [PATCH 4/8] Fix missing comma --- ios/browserstack_sample_local.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/browserstack_sample_local.rb b/ios/browserstack_sample_local.rb index ecae0c6..4d38aae 100644 --- a/ios/browserstack_sample_local.rb +++ b/ios/browserstack_sample_local.rb @@ -18,7 +18,7 @@ "buildName" => "browserstack-build-1", "sessionName" => "single_test", "debug" => "true", - "local" => "true" + "local" => "true", "networkLogs" => "true", # Set your access credentials From da57d7e1f567173e6c3e1e4d6d22e0e506df819a Mon Sep 17 00:00:00 2001 From: avinash-bharti Date: Tue, 30 Aug 2022 10:22:06 +0530 Subject: [PATCH 5/8] Use creds from variable --- android/browserstack_sample_local.rb | 10 +++++++--- ios/browserstack_sample_local.rb | 8 ++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/android/browserstack_sample_local.rb b/android/browserstack_sample_local.rb index 58156d9..541a866 100644 --- a/android/browserstack_sample_local.rb +++ b/android/browserstack_sample_local.rb @@ -3,6 +3,10 @@ require 'selenium-webdriver' require 'browserstack/local' +# Set your access credentials +user_name = "BROWSERSTACK_USERNAME" +access_key = "BROWSERSTACK_ACCESS_KEY" + capabilities = { # Specify device and os_version for testing "platformName" => "android", @@ -21,9 +25,9 @@ "local" => "true", "networkLogs" => "true", - # Set your access credentials - "userName": "BROWSERSTACK_USERNAME", - "accessKey": "BROWSERSTACK_ACCESS_KEY" + + "userName": user_name, + "accessKey": access_key }, } diff --git a/ios/browserstack_sample_local.rb b/ios/browserstack_sample_local.rb index 4d38aae..1da51ac 100644 --- a/ios/browserstack_sample_local.rb +++ b/ios/browserstack_sample_local.rb @@ -3,6 +3,10 @@ require 'selenium-webdriver' require 'browserstack/local' +# Set your access credentials +user_name = "BROWSERSTACK_USERNAME" +access_key = "BROWSERSTACK_ACCESS_KEY" + capabilities = { # Specify device and os_version for testing "platformName" => "iOS", @@ -22,8 +26,8 @@ "networkLogs" => "true", # Set your access credentials - "userName": "BROWSERSTACK_USERNAME", - "accessKey": "BROWSERSTACK_ACCESS_KEY" + "userName": user_name, + "accessKey": access_key }, } From 7471ba2f208fb5d05a0463d721e8361cea9b3a5f Mon Sep 17 00:00:00 2001 From: avinash-bharti Date: Tue, 30 Aug 2022 10:43:35 +0530 Subject: [PATCH 6/8] Fix wrong variable --- ios/browserstack_sample_local.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/browserstack_sample_local.rb b/ios/browserstack_sample_local.rb index 1da51ac..3e06520 100644 --- a/ios/browserstack_sample_local.rb +++ b/ios/browserstack_sample_local.rb @@ -39,7 +39,7 @@ # Initialize the remote Webdriver using BrowserStack remote URL # and desired capabilities defined above appium_driver = Appium::Driver.new({ - 'caps' => caps, + 'caps' => capabilities, 'appium_lib' => { :server_url => "http://hub.browserstack.com/wd/hub" }}, true) From 6b0604dd5e58495575cdb126b56e0bd964408d82 Mon Sep 17 00:00:00 2001 From: avinash-bharti Date: Tue, 30 Aug 2022 10:45:56 +0530 Subject: [PATCH 7/8] Fix session name --- android/browserstack_sample.rb | 2 +- android/browserstack_sample_local.rb | 2 +- ios/browserstack_sample.rb | 2 +- ios/browserstack_sample_local.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/android/browserstack_sample.rb b/android/browserstack_sample.rb index 5e0b35e..9036b0d 100644 --- a/android/browserstack_sample.rb +++ b/android/browserstack_sample.rb @@ -15,7 +15,7 @@ 'bstack:options' => { "projectName" => "First Ruby project", "buildName" => "browserstack-build-1", - "sessionName" => "single_test", + "sessionName" => "BStack single_test", "debug" => "true", "networkLogs" => "true", diff --git a/android/browserstack_sample_local.rb b/android/browserstack_sample_local.rb index 541a866..da46f01 100644 --- a/android/browserstack_sample_local.rb +++ b/android/browserstack_sample_local.rb @@ -20,7 +20,7 @@ 'bstack:options' => { "projectName" => "First Ruby project", "buildName" => "browserstack-build-1", - "sessionName" => "local_test", + "sessionName" => "BStack local_test", "debug" => "true", "local" => "true", "networkLogs" => "true", diff --git a/ios/browserstack_sample.rb b/ios/browserstack_sample.rb index 9bc1c04..6f5f248 100644 --- a/ios/browserstack_sample.rb +++ b/ios/browserstack_sample.rb @@ -15,7 +15,7 @@ 'bstack:options' => { "projectName" => "First Ruby project", "buildName" => "browserstack-build-1", - "sessionName" => "single_test", + "sessionName" => "BStack single_test", "debug" => "true", "networkLogs" => "true", diff --git a/ios/browserstack_sample_local.rb b/ios/browserstack_sample_local.rb index 3e06520..7ff0015 100644 --- a/ios/browserstack_sample_local.rb +++ b/ios/browserstack_sample_local.rb @@ -20,7 +20,7 @@ 'bstack:options' => { "projectName" => "First Ruby project", "buildName" => "browserstack-build-1", - "sessionName" => "single_test", + "sessionName" => "BStack local_test", "debug" => "true", "local" => "true", "networkLogs" => "true", From 798c0745f0ca91251a8242fb45c803540ce4e814 Mon Sep 17 00:00:00 2001 From: avinash-bharti Date: Tue, 30 Aug 2022 10:47:14 +0530 Subject: [PATCH 8/8] Remove unnecessary comment --- android/browserstack_sample_local.rb | 1 - ios/browserstack_sample_local.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/android/browserstack_sample_local.rb b/android/browserstack_sample_local.rb index da46f01..1587bae 100644 --- a/android/browserstack_sample_local.rb +++ b/android/browserstack_sample_local.rb @@ -25,7 +25,6 @@ "local" => "true", "networkLogs" => "true", - "userName": user_name, "accessKey": access_key }, diff --git a/ios/browserstack_sample_local.rb b/ios/browserstack_sample_local.rb index 7ff0015..2c8a280 100644 --- a/ios/browserstack_sample_local.rb +++ b/ios/browserstack_sample_local.rb @@ -25,7 +25,6 @@ "local" => "true", "networkLogs" => "true", - # Set your access credentials "userName": user_name, "accessKey": access_key },