From fd9e6244b78cba6a1b1ed215070d5eaa4635940e Mon Sep 17 00:00:00 2001 From: Ankit Singh <2501.ankit@gmail.com> Date: Fri, 7 Oct 2022 14:56:57 +0530 Subject: [PATCH 01/22] update: add SDk changes, remove extra files --- browserstack.yml | 70 ++++++++++++++++++++++++++++++++++ config/Config.py | 36 ++++------------- config/KeywordsFile.robot | 33 +--------------- config/manage-local-testing.py | 19 --------- config/mark-test-status.py | 9 ----- requirements.txt | 3 +- tests/LocalTest.robot | 24 ++++-------- tests/parallel/Suite01.robot | 9 +---- tests/parallel/Suite02.robot | 9 +---- tests/parallel/Suite03.robot | 9 +---- tests/testcases.robot | 8 ---- 11 files changed, 95 insertions(+), 134 deletions(-) create mode 100644 browserstack.yml delete mode 100644 config/manage-local-testing.py delete mode 100644 config/mark-test-status.py diff --git a/browserstack.yml b/browserstack.yml new file mode 100644 index 0000000..aa837fd --- /dev/null +++ b/browserstack.yml @@ -0,0 +1,70 @@ +# ============================= +# Set BrowserStack Credentials +# ============================= +# Add your BrowserStack userName and acccessKey here or set BROWSERSTACK_USERNAME and +# BROWSERSTACK_ACCESS_KEY as env variables +userName: YOUR_USERNAME +accessKey: YOUR_ACCESS_KEY + +# ====================== +# Organizing your tests +# ====================== +# Use `projectName`, `buildName`, `name` capabilities to organise your tests +# `name` is the name of your test sessions and is automatically picked from your +# test name and doesn't need to be set manually when using BrowserStack SDK +# `buildName` is used to name your CI/CD job or the execution of your test suite. +# Ensure you add a dynamic identifier, like an incremental build number from your +# CI/CD or timestamp at the end of every build; otherwise tests from different +# executions will be grouped together on BrowserStack +buildName: browserstack-build-1 +# Use `projectName` to set the name of your project. Example, Marketing Website +projectName: BrowserStack Samples + +# ======================================= +# Platforms (Browsers / Devices to test) +# ======================================= +# Platforms object contains all the browser / device combinations you want to test on. +# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate) +platforms: + - os: OS X + osVersion: Big Sur + browser: Chrome + browserVersion: latest + - os: Windows + osVersion: 10 + browser: Edge + browserVersion: latest + - device: Samsung Galaxy S22 Ultra + browserName: chrome # Try 'samsung' for Samsung browser + osVersion: 12.0 + +# ======================= +# Parallels per Platform +# ======================= +# The number of parallel threads to be used for each platform set. +# BrowserStack's SDK runner will select the best strategy based on the configured value +# +# Example 1 - If you have configured 3 platforms and set `parallelsPerPlatform` as 2, a total of 6 (2 * 3) parallel threads will be used on BrowserStack +# +# Example 2 - If you have configured 1 platform and set `parallelsPerPlatform` as 5, a total of 5 (1 * 5) parallel threads will be used on BrowserStack +parallelsPerPlatform: 1 + +# ========================================== +# BrowserStack Local +# (For localhost, staging/private websites) +# ========================================== +# Set browserStackLocal to true if your website under test is not accessible publicly over the internet +# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction +browserstackLocal: true # (Default false) +# browserStackLocalOptions: +# Options to be passed to BrowserStack local in-case of advanced configurations + # localIdentifier: # (Default: null) Needed if you need to run multiple instances of local. + # forceLocal: true # (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel. + # Entire list of arguments availabe here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections + +# =================== +# Debugging features +# =================== +debug: false # # Set to true if you need screenshots for every selenium command ran +networkLogs: false # Set to true to enable HAR logs capturing +consoleLogs: errors # Remote browser's console debug levels to be printed (Available levels: `disable`, `errors`, `warnings`, `info`, `verbose`, Default: errors) diff --git a/config/Config.py b/config/Config.py index 1f243f3..f09cc12 100644 --- a/config/Config.py +++ b/config/Config.py @@ -1,37 +1,15 @@ import os -common_caps = { - "browserstack.user" : "BROWSERSTACK_USERNAME", - "browserstack.key" : "BROWSERSTACK_ACCESS_KEY", - "build" : "browserstack-build-1", - "browserstack.debug" : "true" -} - envs = [{ - "os" : "Windows", - "os_version" : "10", - "browser" : "Chrome", - "browser_version" : "latest" + "browser": "Chrome", }, -{ - "os" : "OS X", - "os_version" : "Big Sur", - "browser" : "Safari", - "browser_version" : "latest" + { + "browser": "Safari", }, -{ - "device" : "Samsung Galaxy S22", - "os_version" : "12" + { + "browser": "Firefox", }] -def combine_caps(i): - - username = os.environ.get("BROWSERSTACK_USERNAME") - accesskey = os.environ.get("BROWSERSTACK_ACCESS_KEY") - if username != None and accesskey != None: - common_caps["browserstack.user"] = username - common_caps["browserstack.key"] = accesskey - x = int(i) - envs[x].update(common_caps) - return envs[x] +def get_test_caps(i): + return envs[int(i)] diff --git a/config/KeywordsFile.robot b/config/KeywordsFile.robot index ded1323..bcd3b2a 100644 --- a/config/KeywordsFile.robot +++ b/config/KeywordsFile.robot @@ -1,9 +1,8 @@ *** Settings *** Library SeleniumLibrary -Library mark-test-status.py *** Variables *** -${remote_url}= https://hub.browserstack.com/wd/hub +${remote_url}= http://localhost:4444/wd/hub *** Keywords *** Open Session @@ -16,37 +15,11 @@ Close Session Add Implicit Wait set selenium implicit wait 5 -Mark Test Status - [Arguments] ${status} ${reason} - TEST STATUS ${status} ${reason} - Get the page title get title -Click on Sign In - click element id=signin - -Enter Credentials - [Arguments] ${username} ${password} - input text css=#username input ${username} - click element css= .css-1n7v3ny-option - input text css=#password input ${password} - click element css= .css-1n7v3ny-option - -Click on Login - click element id=login-btn - -Verify username - [Arguments] ${assert_username} - ${retrived_username}= get text css=.username - run keyword if "${retrived_username}" == "${assert_username}" mark test status passed Username validated! - run keyword if "${retrived_username}" != "${assert_username}" mark test status failed Username validation failed! - element should contain css=.username ${assert_username} - Verify site content ${site_content}= get text css=body - run keyword if "${site_content}" == "Up and running" mark test status passed Site Content validated! - run keyword if "${site_content}" != "Up and running" mark test status failed Site Content validation failed! element should contain css=body Up and running Add first product to cart @@ -54,7 +27,5 @@ Add first product to cart Verify product is added to cart ${product_name} get text xpath=//*[@id="1"]/p - ${product_incart} get text css=p.title - run keyword if "${product_name}" == "${product_incart}" mark test status passed Correct product added! - run keyword if "${product_name}" != "${product_incart}" mark test status failed Something went wrong! + ${product_incart} get text css=p.title element should contain css=p.title ${product_name} diff --git a/config/manage-local-testing.py b/config/manage-local-testing.py deleted file mode 100644 index 95f6cc6..0000000 --- a/config/manage-local-testing.py +++ /dev/null @@ -1,19 +0,0 @@ -import os -from robot.libraries.BuiltIn import BuiltIn -from robot.libraries.BuiltIn import _Misc -import robot.api.logger as logger -from robot.api.deco import keyword -from browserstack.local import Local - -access_key = os.getenv("BROWSERSTACK_ACCESS_KEY") -bs_local = Local() - -@keyword("START LOCAL") -def startLocal(): - bs_local_args = {"key": access_key} - bs_local.start(**bs_local_args) - print(bs_local.isRunning()) - -@keyword("STOP LOCAL") -def stopLocal(): - bs_local.stop() diff --git a/config/mark-test-status.py b/config/mark-test-status.py deleted file mode 100644 index 34469c6..0000000 --- a/config/mark-test-status.py +++ /dev/null @@ -1,9 +0,0 @@ -from robot.libraries.BuiltIn import BuiltIn -from robot.libraries.BuiltIn import _Misc -import robot.api.logger as logger -from robot.api.deco import keyword - -@keyword("TEST STATUS") -def testStatus(status, reason): - driver = BuiltIn().get_library_instance('SeleniumLibrary').driver - driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"'+status+'", "reason": "'+reason+'"}}') diff --git a/requirements.txt b/requirements.txt index bf195a4..789a91d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ robotframework robotframework-seleniumlibrary==5.1.3 robotframework-pabot browserstack-local -selenium==3.141.0 +selenium +browserstack-sdk diff --git a/tests/LocalTest.robot b/tests/LocalTest.robot index 1f8427b..e1c95aa 100644 --- a/tests/LocalTest.robot +++ b/tests/LocalTest.robot @@ -1,25 +1,17 @@ *** Settings *** -Library SeleniumLibrary -Library Collections -Library ../config/manage-local-testing.py +Library SeleniumLibrary Library ../config/Config.py -Resource ../config/KeywordsFile.robot -Test Setup Setup for local test -Test Teardown Teardown for local test +Resource ../config/KeywordsFile.robot +Test Setup Execute local test +Test Teardown Close Session *** Variables *** -${local_url}= http://bs-local.com:45691/check +${local_website_url}= http://bs-local.com:45691/check *** Keywords *** -Setup for local test - START LOCAL - ${final_caps}= combine caps 0 - Set to Dictionary ${final_caps} name=BStack Demo - ${TEST NAME} browserstack.local=true - Open Session ${final_caps} ${local_url} - -Teardown for local test - Close Session - STOP LOCAL +Execute local test + ${test_caps}= get test caps 0 + Open Session ${test_caps} ${local_website_url} *** Test Cases *** Local Test diff --git a/tests/parallel/Suite01.robot b/tests/parallel/Suite01.robot index 8137bef..6b5167d 100644 --- a/tests/parallel/Suite01.robot +++ b/tests/parallel/Suite01.robot @@ -1,6 +1,5 @@ *** Settings *** Library SeleniumLibrary -Library Collections Library ../../config/Config.py Resource ../../config/KeywordsFile.robot Resource ../testcases.robot @@ -12,14 +11,10 @@ ${website_url}= https://bstackdemo.com *** Keywords *** Execute test - ${final_caps}= combine caps 0 - Set to Dictionary ${final_caps} name=BStack Demo - ${TEST NAME} - Open Session ${final_caps} ${website_url} + ${test_caps}= get test caps 0 + Open Session ${test_caps} ${website_url} *** Test Cases *** -Login Test - Login - Add to Cart Test Add to Cart diff --git a/tests/parallel/Suite02.robot b/tests/parallel/Suite02.robot index ed3d211..e3d344f 100644 --- a/tests/parallel/Suite02.robot +++ b/tests/parallel/Suite02.robot @@ -1,6 +1,5 @@ *** Settings *** Library SeleniumLibrary -Library Collections Library ../../config/Config.py Resource ../../config/KeywordsFile.robot Resource ../testcases.robot @@ -12,14 +11,10 @@ ${website_url}= https://bstackdemo.com *** Keywords *** Execute test - ${final_caps}= combine caps 1 - Set to Dictionary ${final_caps} name=BStack Demo - ${TEST NAME} - Open Session ${final_caps} ${website_url} + ${test_caps}= get test caps 1 + Open Session ${test_caps} ${website_url} *** Test Cases *** -Login Test - Login - Add to Cart Test Add to Cart diff --git a/tests/parallel/Suite03.robot b/tests/parallel/Suite03.robot index c730ffb..4a4dc1f 100644 --- a/tests/parallel/Suite03.robot +++ b/tests/parallel/Suite03.robot @@ -1,6 +1,5 @@ *** Settings *** Library SeleniumLibrary -Library Collections Library ../../config/Config.py Resource ../../config/KeywordsFile.robot Resource ../testcases.robot @@ -12,14 +11,10 @@ ${website_url}= https://bstackdemo.com *** Keywords *** Execute test - ${final_caps}= combine caps 2 - Set to Dictionary ${final_caps} name=BStack Demo - ${TEST NAME} - Open Session ${final_caps} ${website_url} + ${test_caps}= get test caps 2 + Open Session ${test_caps} ${website_url} *** Test Cases *** -Login Test - Login - Add to Cart Test Add to Cart diff --git a/tests/testcases.robot b/tests/testcases.robot index 9d966ed..65c7fcc 100644 --- a/tests/testcases.robot +++ b/tests/testcases.robot @@ -3,14 +3,6 @@ Library SeleniumLibrary Resource ../config/KeywordsFile.robot *** Keywords *** -Login - Add Implicit Wait - Get the page title - Click on Sign In - Enter Credentials demouser testingisfun99 - Click on Login - Verify username demouser - Add to Cart Add Implicit Wait Get the page title From f31e2e7a6b47aa58a94bdfb4c647e62cf82468c1 Mon Sep 17 00:00:00 2001 From: Ankit Singh <2501.ankit@gmail.com> Date: Fri, 7 Oct 2022 15:12:11 +0530 Subject: [PATCH 02/22] update: README with sdk --- README.md | 65 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 32bd691..96b15a2 100644 --- a/README.md +++ b/README.md @@ -2,46 +2,51 @@ ![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780) -## Setup -* Clone the repo -* Install dependencies `pip install -r requirements.txt` - -## Set BrowserStack Credentials -* Export the BrowserStack username and access key as environment variables +## Prerequisite +``` +python3 should be installed +``` -#### For Linux/MacOS - ``` - export BROWSERSTACK_USERNAME= - export BROWSERSTACK_ACCESS_KEY= +## Setup +* Clone the repo ``` -#### For Windows + git clone -b sdk https://github.com/browserstack/robot-browserstack.git ``` - setx BROWSERSTACK_USERNAME= - setx BROWSERSTACK_ACCESS_KEY= +* Install dependencies ``` + pip install -r requirements.txt + ``` + +## Set BrowserStack Credentials +* Add your BrowserStack username and access key in the `browserstack.yml` config fle. +* You can also export them as environment variables, `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY`: + + #### For Linux/MacOS + ``` + export BROWSERSTACK_USERNAME= + export BROWSERSTACK_ACCESS_KEY= + ``` + #### For Windows + ``` + setx BROWSERSTACK_USERNAME= + setx BROWSERSTACK_ACCESS_KEY= + ``` ## Running tests -* To run local test, run `robot tests/LocalTest.robot` -* To run parallel tests we will be using the [Pabot](https://pabot.org/) library: - 1. To run test suites in parallel (Testcases within respective test suites will be sequential) - * Run - `pabot --processes tests/parallel/*.robot` - * Alternate method: `pabot --processes ` -
Eg: `pabot --processes 2 tests/parallel/Suite01.robot tests/parallel/Suite02.robot` - 2. To run all test cases within a test suite in parallel - * Run - `pabot --testlevelsplit ` -
Eg: `pabot --testlevelsplit tests/parallel/Suite01.robot` - 3. Run all testcases across all Test Suites in parallel - * Run - `pabot --testlevelsplit --processes tests/parallel/*.robot` -
**Note: If the process count exceeds the parallel threads available on BrowserStack, the sessions will automatically get queued.** +* To run sample tests: + - To run the sample tests in parallel across the platforms defined in the `browserstack.yml` file, run: + ``` + browserstack-sdk pabot ./tests/parallel/*.robot + ``` +* To run tests on locally hosted websites: + - To run the local test in parallel across the platforms defined in the `browserstack.yml` file, run: + ``` + browserstack-sdk pabot ./tests/LocalTest.robot + ``` Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) -## Notes -* This repository only works for Selenium 3 as of now. Desired Capabilities do not get honoured for Selenium 4. The open issue on SeleniumLibrary can be found [here](https://github.com/robotframework/SeleniumLibrary/issues/1774). -* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate) -* To test on a different set of browsers, check out our [platform configurator](https://www.browserstack.com/automate/capabilities) - ## Additional Resources * [Documentation for writing Automate test scripts in Python](https://www.browserstack.com/automate/python) * [Customizing your tests on BrowserStack](https://www.browserstack.com/automate/capabilities) From 61aa0ac0bbb9ae27cc406b45f9532e4854816f10 Mon Sep 17 00:00:00 2001 From: Ankit Singh <51696887+Ankit098@users.noreply.github.com> Date: Thu, 20 Oct 2022 23:15:50 +0530 Subject: [PATCH 03/22] chore: set command for adding env variables --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 96b15a2..4694335 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,9 @@ python3 should be installed ``` #### For Windows ``` + set BROWSERSTACK_USERNAME= + set BROWSERSTACK_ACCESS_KEY= + setx BROWSERSTACK_USERNAME= setx BROWSERSTACK_ACCESS_KEY= ``` From 80aefff56e4eb9bd823d59dcfcfbf9aa2bd50fb5 Mon Sep 17 00:00:00 2001 From: Ankit Singh <2501.ankit@gmail.com> Date: Fri, 7 Oct 2022 14:56:57 +0530 Subject: [PATCH 04/22] update: add SDk changes, remove extra files --- browserstack.yml | 70 ++++++++++++++++++++++++++++++++++ config/Config.py | 36 ++++------------- config/KeywordsFile.robot | 33 +--------------- config/manage-local-testing.py | 19 --------- config/mark-test-status.py | 9 ----- requirements.txt | 3 +- tests/LocalTest.robot | 24 ++++-------- tests/parallel/Suite01.robot | 9 +---- tests/parallel/Suite02.robot | 9 +---- tests/parallel/Suite03.robot | 9 +---- tests/testcases.robot | 8 ---- 11 files changed, 95 insertions(+), 134 deletions(-) create mode 100644 browserstack.yml delete mode 100644 config/manage-local-testing.py delete mode 100644 config/mark-test-status.py diff --git a/browserstack.yml b/browserstack.yml new file mode 100644 index 0000000..aa837fd --- /dev/null +++ b/browserstack.yml @@ -0,0 +1,70 @@ +# ============================= +# Set BrowserStack Credentials +# ============================= +# Add your BrowserStack userName and acccessKey here or set BROWSERSTACK_USERNAME and +# BROWSERSTACK_ACCESS_KEY as env variables +userName: YOUR_USERNAME +accessKey: YOUR_ACCESS_KEY + +# ====================== +# Organizing your tests +# ====================== +# Use `projectName`, `buildName`, `name` capabilities to organise your tests +# `name` is the name of your test sessions and is automatically picked from your +# test name and doesn't need to be set manually when using BrowserStack SDK +# `buildName` is used to name your CI/CD job or the execution of your test suite. +# Ensure you add a dynamic identifier, like an incremental build number from your +# CI/CD or timestamp at the end of every build; otherwise tests from different +# executions will be grouped together on BrowserStack +buildName: browserstack-build-1 +# Use `projectName` to set the name of your project. Example, Marketing Website +projectName: BrowserStack Samples + +# ======================================= +# Platforms (Browsers / Devices to test) +# ======================================= +# Platforms object contains all the browser / device combinations you want to test on. +# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate) +platforms: + - os: OS X + osVersion: Big Sur + browser: Chrome + browserVersion: latest + - os: Windows + osVersion: 10 + browser: Edge + browserVersion: latest + - device: Samsung Galaxy S22 Ultra + browserName: chrome # Try 'samsung' for Samsung browser + osVersion: 12.0 + +# ======================= +# Parallels per Platform +# ======================= +# The number of parallel threads to be used for each platform set. +# BrowserStack's SDK runner will select the best strategy based on the configured value +# +# Example 1 - If you have configured 3 platforms and set `parallelsPerPlatform` as 2, a total of 6 (2 * 3) parallel threads will be used on BrowserStack +# +# Example 2 - If you have configured 1 platform and set `parallelsPerPlatform` as 5, a total of 5 (1 * 5) parallel threads will be used on BrowserStack +parallelsPerPlatform: 1 + +# ========================================== +# BrowserStack Local +# (For localhost, staging/private websites) +# ========================================== +# Set browserStackLocal to true if your website under test is not accessible publicly over the internet +# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction +browserstackLocal: true # (Default false) +# browserStackLocalOptions: +# Options to be passed to BrowserStack local in-case of advanced configurations + # localIdentifier: # (Default: null) Needed if you need to run multiple instances of local. + # forceLocal: true # (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel. + # Entire list of arguments availabe here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections + +# =================== +# Debugging features +# =================== +debug: false # # Set to true if you need screenshots for every selenium command ran +networkLogs: false # Set to true to enable HAR logs capturing +consoleLogs: errors # Remote browser's console debug levels to be printed (Available levels: `disable`, `errors`, `warnings`, `info`, `verbose`, Default: errors) diff --git a/config/Config.py b/config/Config.py index 1f243f3..f09cc12 100644 --- a/config/Config.py +++ b/config/Config.py @@ -1,37 +1,15 @@ import os -common_caps = { - "browserstack.user" : "BROWSERSTACK_USERNAME", - "browserstack.key" : "BROWSERSTACK_ACCESS_KEY", - "build" : "browserstack-build-1", - "browserstack.debug" : "true" -} - envs = [{ - "os" : "Windows", - "os_version" : "10", - "browser" : "Chrome", - "browser_version" : "latest" + "browser": "Chrome", }, -{ - "os" : "OS X", - "os_version" : "Big Sur", - "browser" : "Safari", - "browser_version" : "latest" + { + "browser": "Safari", }, -{ - "device" : "Samsung Galaxy S22", - "os_version" : "12" + { + "browser": "Firefox", }] -def combine_caps(i): - - username = os.environ.get("BROWSERSTACK_USERNAME") - accesskey = os.environ.get("BROWSERSTACK_ACCESS_KEY") - if username != None and accesskey != None: - common_caps["browserstack.user"] = username - common_caps["browserstack.key"] = accesskey - x = int(i) - envs[x].update(common_caps) - return envs[x] +def get_test_caps(i): + return envs[int(i)] diff --git a/config/KeywordsFile.robot b/config/KeywordsFile.robot index ded1323..bcd3b2a 100644 --- a/config/KeywordsFile.robot +++ b/config/KeywordsFile.robot @@ -1,9 +1,8 @@ *** Settings *** Library SeleniumLibrary -Library mark-test-status.py *** Variables *** -${remote_url}= https://hub.browserstack.com/wd/hub +${remote_url}= http://localhost:4444/wd/hub *** Keywords *** Open Session @@ -16,37 +15,11 @@ Close Session Add Implicit Wait set selenium implicit wait 5 -Mark Test Status - [Arguments] ${status} ${reason} - TEST STATUS ${status} ${reason} - Get the page title get title -Click on Sign In - click element id=signin - -Enter Credentials - [Arguments] ${username} ${password} - input text css=#username input ${username} - click element css= .css-1n7v3ny-option - input text css=#password input ${password} - click element css= .css-1n7v3ny-option - -Click on Login - click element id=login-btn - -Verify username - [Arguments] ${assert_username} - ${retrived_username}= get text css=.username - run keyword if "${retrived_username}" == "${assert_username}" mark test status passed Username validated! - run keyword if "${retrived_username}" != "${assert_username}" mark test status failed Username validation failed! - element should contain css=.username ${assert_username} - Verify site content ${site_content}= get text css=body - run keyword if "${site_content}" == "Up and running" mark test status passed Site Content validated! - run keyword if "${site_content}" != "Up and running" mark test status failed Site Content validation failed! element should contain css=body Up and running Add first product to cart @@ -54,7 +27,5 @@ Add first product to cart Verify product is added to cart ${product_name} get text xpath=//*[@id="1"]/p - ${product_incart} get text css=p.title - run keyword if "${product_name}" == "${product_incart}" mark test status passed Correct product added! - run keyword if "${product_name}" != "${product_incart}" mark test status failed Something went wrong! + ${product_incart} get text css=p.title element should contain css=p.title ${product_name} diff --git a/config/manage-local-testing.py b/config/manage-local-testing.py deleted file mode 100644 index 95f6cc6..0000000 --- a/config/manage-local-testing.py +++ /dev/null @@ -1,19 +0,0 @@ -import os -from robot.libraries.BuiltIn import BuiltIn -from robot.libraries.BuiltIn import _Misc -import robot.api.logger as logger -from robot.api.deco import keyword -from browserstack.local import Local - -access_key = os.getenv("BROWSERSTACK_ACCESS_KEY") -bs_local = Local() - -@keyword("START LOCAL") -def startLocal(): - bs_local_args = {"key": access_key} - bs_local.start(**bs_local_args) - print(bs_local.isRunning()) - -@keyword("STOP LOCAL") -def stopLocal(): - bs_local.stop() diff --git a/config/mark-test-status.py b/config/mark-test-status.py deleted file mode 100644 index 34469c6..0000000 --- a/config/mark-test-status.py +++ /dev/null @@ -1,9 +0,0 @@ -from robot.libraries.BuiltIn import BuiltIn -from robot.libraries.BuiltIn import _Misc -import robot.api.logger as logger -from robot.api.deco import keyword - -@keyword("TEST STATUS") -def testStatus(status, reason): - driver = BuiltIn().get_library_instance('SeleniumLibrary').driver - driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"'+status+'", "reason": "'+reason+'"}}') diff --git a/requirements.txt b/requirements.txt index bf195a4..789a91d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,5 @@ robotframework robotframework-seleniumlibrary==5.1.3 robotframework-pabot browserstack-local -selenium==3.141.0 +selenium +browserstack-sdk diff --git a/tests/LocalTest.robot b/tests/LocalTest.robot index 1f8427b..e1c95aa 100644 --- a/tests/LocalTest.robot +++ b/tests/LocalTest.robot @@ -1,25 +1,17 @@ *** Settings *** -Library SeleniumLibrary -Library Collections -Library ../config/manage-local-testing.py +Library SeleniumLibrary Library ../config/Config.py -Resource ../config/KeywordsFile.robot -Test Setup Setup for local test -Test Teardown Teardown for local test +Resource ../config/KeywordsFile.robot +Test Setup Execute local test +Test Teardown Close Session *** Variables *** -${local_url}= http://bs-local.com:45691/check +${local_website_url}= http://bs-local.com:45691/check *** Keywords *** -Setup for local test - START LOCAL - ${final_caps}= combine caps 0 - Set to Dictionary ${final_caps} name=BStack Demo - ${TEST NAME} browserstack.local=true - Open Session ${final_caps} ${local_url} - -Teardown for local test - Close Session - STOP LOCAL +Execute local test + ${test_caps}= get test caps 0 + Open Session ${test_caps} ${local_website_url} *** Test Cases *** Local Test diff --git a/tests/parallel/Suite01.robot b/tests/parallel/Suite01.robot index 8137bef..6b5167d 100644 --- a/tests/parallel/Suite01.robot +++ b/tests/parallel/Suite01.robot @@ -1,6 +1,5 @@ *** Settings *** Library SeleniumLibrary -Library Collections Library ../../config/Config.py Resource ../../config/KeywordsFile.robot Resource ../testcases.robot @@ -12,14 +11,10 @@ ${website_url}= https://bstackdemo.com *** Keywords *** Execute test - ${final_caps}= combine caps 0 - Set to Dictionary ${final_caps} name=BStack Demo - ${TEST NAME} - Open Session ${final_caps} ${website_url} + ${test_caps}= get test caps 0 + Open Session ${test_caps} ${website_url} *** Test Cases *** -Login Test - Login - Add to Cart Test Add to Cart diff --git a/tests/parallel/Suite02.robot b/tests/parallel/Suite02.robot index ed3d211..e3d344f 100644 --- a/tests/parallel/Suite02.robot +++ b/tests/parallel/Suite02.robot @@ -1,6 +1,5 @@ *** Settings *** Library SeleniumLibrary -Library Collections Library ../../config/Config.py Resource ../../config/KeywordsFile.robot Resource ../testcases.robot @@ -12,14 +11,10 @@ ${website_url}= https://bstackdemo.com *** Keywords *** Execute test - ${final_caps}= combine caps 1 - Set to Dictionary ${final_caps} name=BStack Demo - ${TEST NAME} - Open Session ${final_caps} ${website_url} + ${test_caps}= get test caps 1 + Open Session ${test_caps} ${website_url} *** Test Cases *** -Login Test - Login - Add to Cart Test Add to Cart diff --git a/tests/parallel/Suite03.robot b/tests/parallel/Suite03.robot index c730ffb..4a4dc1f 100644 --- a/tests/parallel/Suite03.robot +++ b/tests/parallel/Suite03.robot @@ -1,6 +1,5 @@ *** Settings *** Library SeleniumLibrary -Library Collections Library ../../config/Config.py Resource ../../config/KeywordsFile.robot Resource ../testcases.robot @@ -12,14 +11,10 @@ ${website_url}= https://bstackdemo.com *** Keywords *** Execute test - ${final_caps}= combine caps 2 - Set to Dictionary ${final_caps} name=BStack Demo - ${TEST NAME} - Open Session ${final_caps} ${website_url} + ${test_caps}= get test caps 2 + Open Session ${test_caps} ${website_url} *** Test Cases *** -Login Test - Login - Add to Cart Test Add to Cart diff --git a/tests/testcases.robot b/tests/testcases.robot index 9d966ed..65c7fcc 100644 --- a/tests/testcases.robot +++ b/tests/testcases.robot @@ -3,14 +3,6 @@ Library SeleniumLibrary Resource ../config/KeywordsFile.robot *** Keywords *** -Login - Add Implicit Wait - Get the page title - Click on Sign In - Enter Credentials demouser testingisfun99 - Click on Login - Verify username demouser - Add to Cart Add Implicit Wait Get the page title From 1b1ed24216696fa6cd3ffaeeb3bbcc1616908e69 Mon Sep 17 00:00:00 2001 From: Ankit Singh <2501.ankit@gmail.com> Date: Fri, 7 Oct 2022 15:12:11 +0530 Subject: [PATCH 05/22] update: README with sdk --- README.md | 65 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 32bd691..96b15a2 100644 --- a/README.md +++ b/README.md @@ -2,46 +2,51 @@ ![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780) -## Setup -* Clone the repo -* Install dependencies `pip install -r requirements.txt` - -## Set BrowserStack Credentials -* Export the BrowserStack username and access key as environment variables +## Prerequisite +``` +python3 should be installed +``` -#### For Linux/MacOS - ``` - export BROWSERSTACK_USERNAME= - export BROWSERSTACK_ACCESS_KEY= +## Setup +* Clone the repo ``` -#### For Windows + git clone -b sdk https://github.com/browserstack/robot-browserstack.git ``` - setx BROWSERSTACK_USERNAME= - setx BROWSERSTACK_ACCESS_KEY= +* Install dependencies ``` + pip install -r requirements.txt + ``` + +## Set BrowserStack Credentials +* Add your BrowserStack username and access key in the `browserstack.yml` config fle. +* You can also export them as environment variables, `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY`: + + #### For Linux/MacOS + ``` + export BROWSERSTACK_USERNAME= + export BROWSERSTACK_ACCESS_KEY= + ``` + #### For Windows + ``` + setx BROWSERSTACK_USERNAME= + setx BROWSERSTACK_ACCESS_KEY= + ``` ## Running tests -* To run local test, run `robot tests/LocalTest.robot` -* To run parallel tests we will be using the [Pabot](https://pabot.org/) library: - 1. To run test suites in parallel (Testcases within respective test suites will be sequential) - * Run - `pabot --processes tests/parallel/*.robot` - * Alternate method: `pabot --processes ` -
Eg: `pabot --processes 2 tests/parallel/Suite01.robot tests/parallel/Suite02.robot` - 2. To run all test cases within a test suite in parallel - * Run - `pabot --testlevelsplit ` -
Eg: `pabot --testlevelsplit tests/parallel/Suite01.robot` - 3. Run all testcases across all Test Suites in parallel - * Run - `pabot --testlevelsplit --processes tests/parallel/*.robot` -
**Note: If the process count exceeds the parallel threads available on BrowserStack, the sessions will automatically get queued.** +* To run sample tests: + - To run the sample tests in parallel across the platforms defined in the `browserstack.yml` file, run: + ``` + browserstack-sdk pabot ./tests/parallel/*.robot + ``` +* To run tests on locally hosted websites: + - To run the local test in parallel across the platforms defined in the `browserstack.yml` file, run: + ``` + browserstack-sdk pabot ./tests/LocalTest.robot + ``` Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) -## Notes -* This repository only works for Selenium 3 as of now. Desired Capabilities do not get honoured for Selenium 4. The open issue on SeleniumLibrary can be found [here](https://github.com/robotframework/SeleniumLibrary/issues/1774). -* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate) -* To test on a different set of browsers, check out our [platform configurator](https://www.browserstack.com/automate/capabilities) - ## Additional Resources * [Documentation for writing Automate test scripts in Python](https://www.browserstack.com/automate/python) * [Customizing your tests on BrowserStack](https://www.browserstack.com/automate/capabilities) From 3b84685dbc822a9a1fcb9764d1b0c6d87e87d39a Mon Sep 17 00:00:00 2001 From: Ankit Singh <51696887+Ankit098@users.noreply.github.com> Date: Thu, 20 Oct 2022 23:15:50 +0530 Subject: [PATCH 06/22] chore: set command for adding env variables --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 96b15a2..4694335 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,9 @@ python3 should be installed ``` #### For Windows ``` + set BROWSERSTACK_USERNAME= + set BROWSERSTACK_ACCESS_KEY= + setx BROWSERSTACK_USERNAME= setx BROWSERSTACK_ACCESS_KEY= ``` From 041ce48e89bd6c7bcf9fbcc70c6d36200f4c2848 Mon Sep 17 00:00:00 2001 From: Ankit Singh <2501.ankit@gmail.com> Date: Wed, 16 Nov 2022 20:16:18 +0530 Subject: [PATCH 07/22] update: local tests with localIdentifier --- config/KeywordsFile.robot | 5 ++--- tests/LocalTest.robot | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/config/KeywordsFile.robot b/config/KeywordsFile.robot index bcd3b2a..bc059f6 100644 --- a/config/KeywordsFile.robot +++ b/config/KeywordsFile.robot @@ -18,9 +18,8 @@ Add Implicit Wait Get the page title get title -Verify site content - ${site_content}= get text css=body - element should contain css=body Up and running +Verify Local Page + Title Should be BrowserStack Local Add first product to cart click element xpath=//*[@id="1"]/div[4] diff --git a/tests/LocalTest.robot b/tests/LocalTest.robot index e1c95aa..dd8ecd8 100644 --- a/tests/LocalTest.robot +++ b/tests/LocalTest.robot @@ -6,7 +6,7 @@ Test Setup Execute local test Test Teardown Close Session *** Variables *** -${local_website_url}= http://bs-local.com:45691/check +${local_website_url}= http://bs-local.com:45454 *** Keywords *** Execute local test @@ -16,4 +16,4 @@ Execute local test *** Test Cases *** Local Test Add Implicit Wait - Verify site content + Verify Local Page From 248415bd15c146dd541579fbe7cd330998d588f9 Mon Sep 17 00:00:00 2001 From: Ankit Singh <2501.ankit@gmail.com> Date: Wed, 28 Dec 2022 14:27:14 +0530 Subject: [PATCH 08/22] chore: remove extra files, restructure files --- .gitignore | 2 ++ config/Config.py | 15 ------------- {config => resources}/KeywordsFile.robot | 0 .../TestCases.robot | 2 +- tests/{LocalTest.robot => local-test.robot} | 8 ++++--- tests/parallel/Suite01.robot | 20 ------------------ tests/parallel/Suite02.robot | 20 ------------------ tests/parallel/Suite03.robot | 20 ------------------ tests/test-1.robot | 21 +++++++++++++++++++ tests/test-2.robot | 21 +++++++++++++++++++ tests/test-3.robot | 21 +++++++++++++++++++ 11 files changed, 71 insertions(+), 79 deletions(-) delete mode 100644 config/Config.py rename {config => resources}/KeywordsFile.robot (100%) rename tests/testcases.robot => resources/TestCases.robot (81%) rename tests/{LocalTest.robot => local-test.robot} (75%) delete mode 100644 tests/parallel/Suite01.robot delete mode 100644 tests/parallel/Suite02.robot delete mode 100644 tests/parallel/Suite03.robot create mode 100644 tests/test-1.robot create mode 100644 tests/test-2.robot create mode 100644 tests/test-3.robot diff --git a/.gitignore b/.gitignore index b7ba3e9..77b0a7b 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ pabot_results/ .pabotsuitenames .DS_Store *.png +env +browserstack.err diff --git a/config/Config.py b/config/Config.py deleted file mode 100644 index f09cc12..0000000 --- a/config/Config.py +++ /dev/null @@ -1,15 +0,0 @@ -import os - -envs = [{ - "browser": "Chrome", -}, - { - "browser": "Safari", -}, - { - "browser": "Firefox", -}] - - -def get_test_caps(i): - return envs[int(i)] diff --git a/config/KeywordsFile.robot b/resources/KeywordsFile.robot similarity index 100% rename from config/KeywordsFile.robot rename to resources/KeywordsFile.robot diff --git a/tests/testcases.robot b/resources/TestCases.robot similarity index 81% rename from tests/testcases.robot rename to resources/TestCases.robot index 65c7fcc..0459620 100644 --- a/tests/testcases.robot +++ b/resources/TestCases.robot @@ -1,6 +1,6 @@ *** Settings *** Library SeleniumLibrary -Resource ../config/KeywordsFile.robot +Resource ./KeywordsFile.robot *** Keywords *** Add to Cart diff --git a/tests/LocalTest.robot b/tests/local-test.robot similarity index 75% rename from tests/LocalTest.robot rename to tests/local-test.robot index dd8ecd8..3b09b0b 100644 --- a/tests/LocalTest.robot +++ b/tests/local-test.robot @@ -1,18 +1,20 @@ *** Settings *** Library SeleniumLibrary -Library ../config/Config.py -Resource ../config/KeywordsFile.robot +Resource ../resources/KeywordsFile.robot Test Setup Execute local test Test Teardown Close Session + *** Variables *** ${local_website_url}= http://bs-local.com:45454 +&{test_caps} browser=chrome + *** Keywords *** Execute local test - ${test_caps}= get test caps 0 Open Session ${test_caps} ${local_website_url} + *** Test Cases *** Local Test Add Implicit Wait diff --git a/tests/parallel/Suite01.robot b/tests/parallel/Suite01.robot deleted file mode 100644 index 6b5167d..0000000 --- a/tests/parallel/Suite01.robot +++ /dev/null @@ -1,20 +0,0 @@ -*** Settings *** -Library SeleniumLibrary -Library ../../config/Config.py -Resource ../../config/KeywordsFile.robot -Resource ../testcases.robot -Test Setup Execute test -Test Teardown Close Session - -*** Variables *** -${website_url}= https://bstackdemo.com - -*** Keywords *** -Execute test - ${test_caps}= get test caps 0 - Open Session ${test_caps} ${website_url} - - -*** Test Cases *** -Add to Cart Test - Add to Cart diff --git a/tests/parallel/Suite02.robot b/tests/parallel/Suite02.robot deleted file mode 100644 index e3d344f..0000000 --- a/tests/parallel/Suite02.robot +++ /dev/null @@ -1,20 +0,0 @@ -*** Settings *** -Library SeleniumLibrary -Library ../../config/Config.py -Resource ../../config/KeywordsFile.robot -Resource ../testcases.robot -Test Setup Execute test -Test Teardown Close Session - -*** Variables *** -${website_url}= https://bstackdemo.com - -*** Keywords *** -Execute test - ${test_caps}= get test caps 1 - Open Session ${test_caps} ${website_url} - - -*** Test Cases *** -Add to Cart Test - Add to Cart diff --git a/tests/parallel/Suite03.robot b/tests/parallel/Suite03.robot deleted file mode 100644 index 4a4dc1f..0000000 --- a/tests/parallel/Suite03.robot +++ /dev/null @@ -1,20 +0,0 @@ -*** Settings *** -Library SeleniumLibrary -Library ../../config/Config.py -Resource ../../config/KeywordsFile.robot -Resource ../testcases.robot -Test Setup Execute test -Test Teardown Close Session - -*** Variables *** -${website_url}= https://bstackdemo.com - -*** Keywords *** -Execute test - ${test_caps}= get test caps 2 - Open Session ${test_caps} ${website_url} - - -*** Test Cases *** -Add to Cart Test - Add to Cart diff --git a/tests/test-1.robot b/tests/test-1.robot new file mode 100644 index 0000000..79d78c0 --- /dev/null +++ b/tests/test-1.robot @@ -0,0 +1,21 @@ +*** Settings *** +Library SeleniumLibrary +Resource ../resources/KeywordsFile.robot +Resource ../resources/TestCases.robot +Test Setup Execute test +Test Teardown Close Session + + +*** Variables *** +${website_url}= https://bstackdemo.com +&{test_caps} browser=chrome + + +*** Keywords *** +Execute test + Open Session ${test_caps} ${website_url} + + +*** Test Cases *** +Add to Cart Test 1 + Add to Cart diff --git a/tests/test-2.robot b/tests/test-2.robot new file mode 100644 index 0000000..c930fdf --- /dev/null +++ b/tests/test-2.robot @@ -0,0 +1,21 @@ +*** Settings *** +Library SeleniumLibrary +Resource ../resources/KeywordsFile.robot +Resource ../resources/TestCases.robot +Test Setup Execute test +Test Teardown Close Session + + +*** Variables *** +${website_url}= https://bstackdemo.com +&{test_caps} browser=firefox + + +*** Keywords *** +Execute test + Open Session ${test_caps} ${website_url} + + +*** Test Cases *** +Add to Cart Test 2 + Add to Cart diff --git a/tests/test-3.robot b/tests/test-3.robot new file mode 100644 index 0000000..8662d77 --- /dev/null +++ b/tests/test-3.robot @@ -0,0 +1,21 @@ +*** Settings *** +Library SeleniumLibrary +Resource ../resources/KeywordsFile.robot +Resource ../resources/TestCases.robot +Test Setup Execute test +Test Teardown Close Session + + +*** Variables *** +${website_url}= https://bstackdemo.com +&{test_caps} browser=safari + + +*** Keywords *** +Execute test + Open Session ${test_caps} ${website_url} + + +*** Test Cases *** +Add to Cart Test 3 + Add to Cart From 7fe3a32fdc1fa9c050e1ee45a8dde7875c3bac5a Mon Sep 17 00:00:00 2001 From: Ankit Singh <2501.ankit@gmail.com> Date: Wed, 28 Dec 2022 14:27:29 +0530 Subject: [PATCH 09/22] update: readme run commands --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4694335..cee6047 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,12 @@ python3 should be installed ``` git clone -b sdk https://github.com/browserstack/robot-browserstack.git ``` +* It is recommended to use a virtual environment to install dependencies. To create a virtual environment: + ``` + python3 -m venv env + source env/bin/activate # on Mac + env\Scripts\activate # on Windows + ``` * Install dependencies ``` pip install -r requirements.txt @@ -40,12 +46,12 @@ python3 should be installed * To run sample tests: - To run the sample tests in parallel across the platforms defined in the `browserstack.yml` file, run: ``` - browserstack-sdk pabot ./tests/parallel/*.robot + browserstack-sdk robot ./tests/test-*.robot ``` * To run tests on locally hosted websites: - To run the local test in parallel across the platforms defined in the `browserstack.yml` file, run: ``` - browserstack-sdk pabot ./tests/LocalTest.robot + browserstack-sdk robot ./tests/local-test.robot ``` Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) From d7c0a65e29875ef6a39234852cf9d22fee4c4166 Mon Sep 17 00:00:00 2001 From: Ankit Singh <2501.ankit@gmail.com> Date: Wed, 28 Dec 2022 14:27:46 +0530 Subject: [PATCH 10/22] update: sample yml --- browserstack.yml | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/browserstack.yml b/browserstack.yml index aa837fd..850bb7d 100644 --- a/browserstack.yml +++ b/browserstack.yml @@ -1,24 +1,25 @@ # ============================= # Set BrowserStack Credentials # ============================= -# Add your BrowserStack userName and acccessKey here or set BROWSERSTACK_USERNAME and +# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and # BROWSERSTACK_ACCESS_KEY as env variables userName: YOUR_USERNAME accessKey: YOUR_ACCESS_KEY # ====================== -# Organizing your tests +# BrowserStack Reporting # ====================== -# Use `projectName`, `buildName`, `name` capabilities to organise your tests -# `name` is the name of your test sessions and is automatically picked from your -# test name and doesn't need to be set manually when using BrowserStack SDK -# `buildName` is used to name your CI/CD job or the execution of your test suite. -# Ensure you add a dynamic identifier, like an incremental build number from your -# CI/CD or timestamp at the end of every build; otherwise tests from different -# executions will be grouped together on BrowserStack -buildName: browserstack-build-1 -# Use `projectName` to set the name of your project. Example, Marketing Website -projectName: BrowserStack Samples +# The following capabilities are used to set up reporting on BrowserStack: +# Set 'projectName' to the name of your project. Example, Marketing Website +projectName: BrowserStack Samples +# Set `buildName` as the name of the job / testsuite being run +buildName: browserstack build +# `buildIdentifier` is a unique id to differentiate every execution that gets appended to +# buildName. Choose your buildIdentifier format from the available expressions: +# ${BUILD_NUMBER} (Default): Generates an incremental counter with every execution +# ${DATE_TIME}: Generates a Timestamp with every execution. Eg. 05-Nov-19:30 +# Read more about buildIdentifiers here -> https://www.browserstack.com/docs/automate/selenium/organize-tests +buildIdentifier: '#${BUILD_NUMBER}' # Supports strings along with either/both ${expression} # ======================================= # Platforms (Browsers / Devices to test) @@ -28,13 +29,13 @@ projectName: BrowserStack Samples platforms: - os: OS X osVersion: Big Sur - browser: Chrome + browserName: Chrome browserVersion: latest - os: Windows osVersion: 10 - browser: Edge + browserName: Edge browserVersion: latest - - device: Samsung Galaxy S22 Ultra + - deviceName: Samsung Galaxy S22 Ultra browserName: chrome # Try 'samsung' for Samsung browser osVersion: 12.0 @@ -60,11 +61,14 @@ browserstackLocal: true # (Default false) # Options to be passed to BrowserStack local in-case of advanced configurations # localIdentifier: # (Default: null) Needed if you need to run multiple instances of local. # forceLocal: true # (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel. - # Entire list of arguments availabe here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections + # Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections + +source: robot-browserstack:sample-sdk:v1.0 # =================== # Debugging features # =================== debug: false # # Set to true if you need screenshots for every selenium command ran networkLogs: false # Set to true to enable HAR logs capturing -consoleLogs: errors # Remote browser's console debug levels to be printed (Available levels: `disable`, `errors`, `warnings`, `info`, `verbose`, Default: errors) +consoleLogs: errors # Remote browser's console debug levels to be printed (Default: errors) +# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors) From 43d3bd38f42edaa147dba7ad2984cbd20b3e92b2 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Mon, 10 Apr 2023 17:11:54 +0530 Subject: [PATCH 11/22] Added github action --- .github/CODEOWNERS | 1 + .github/pull_request_template.md | 6 ++ .github/workflows/reviewing_changes.yml | 88 +++++++++++++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 .github/CODEOWNERS create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/reviewing_changes.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..8f0fab7 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +.github/workflows/*.yml @browserstack/asi-devs diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..103957b --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,6 @@ +#### How to run tests? +- Before running tests please take master merge in the PR +- In Actions go to `Robot Test workflow for Python from workflow_dispatch` workflow. +- Run the workflow by using the workflow from `sdk` branch and giving the PR number in the input box. + +Note: Only BrowserStack Team can trigger the tests. diff --git a/.github/workflows/reviewing_changes.yml b/.github/workflows/reviewing_changes.yml new file mode 100644 index 0000000..f045279 --- /dev/null +++ b/.github/workflows/reviewing_changes.yml @@ -0,0 +1,88 @@ +# This job is to test different profiles in sdk branch against Pull Requests raised +# This workflow targets robot + +name: Robot Test workflow for Python from workflow_dispatch + +on: + workflow_dispatch: + inputs: + pull_request_number: + description: 'The pull request number to build' + required: true + +jobs: + comment-run: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + max-parallel: 3 + matrix: + python: ['3.7', '3.10', '3.11'] + os: [ macos-latest, windows-latest, ubuntu-latest ] + name: Robot Repo ${{ matrix.python }} - ${{ matrix.os }} Sample + env: + BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} + BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} + + steps: + - uses: actions/checkout@v3 + with: + ref: refs/pull/${{ github.event.inputs.pull_request_number }}/head + - name: Fetch Commit SHA + run: | + git log -1 --format='%H' + echo "commit_sha=$(git log -1 --format='%H')" >> $GITHUB_ENV + echo "commit_sha=$(git log -1 --format='%H')" >> $env:GITHUB_ENV + - uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 + id: status-check-in-progress + env: + job_name: Robot Repo ${{ matrix.python }} - ${{ matrix.os }} Sample + with: + github-token: ${{ github.token }} + script: | + const result = await github.rest.checks.create({ + owner: context.repo.owner, + repo: context.repo.repo, + name: process.env.job_name, + head_sha: process.env.commit_sha, + status: 'in_progress' + }).catch((err) => ({status: err.status, response: err.response})); + console.log(`The status-check response : ${result.status} Response : ${JSON.stringify(result.response)}`) + if (result.status !== 201) { + console.log('Failed to create check run') + } + - name: Setup python + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python }} + + - name: Install dependencies + run: python -m pip install -r requirements.txt + + - name: run tests in parallel + run: browserstack-sdk robot ./tests/parallel/*.robot + + - name: run local tests in parallel + run: browserstack-sdk robot ./tests/LocalTest.robot + + - if: always() + uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 + id: status-check-completed + env: + conclusion: ${{ job.status }} + job_name: Robot Repo ${{ matrix.python }} - ${{ matrix.os }} Sample + with: + github-token: ${{ github.token }} + script: | + const result = await github.rest.checks.create({ + owner: context.repo.owner, + repo: context.repo.repo, + name: process.env.job_name, + head_sha: process.env.commit_sha, + status: 'completed', + conclusion: process.env.conclusion + }).catch((err) => ({status: err.status, response: err.response})); + console.log(`The status-check response : ${result.status} Response : ${JSON.stringify(result.response)}`) + if (result.status !== 201) { + console.log('Failed to create check run') + } From cc2dff705fe1dd991171393a02772c01a8f573f9 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Mon, 10 Apr 2023 17:18:25 +0530 Subject: [PATCH 12/22] delete PR template --- .github/pull_request_template.md | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .github/pull_request_template.md diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md deleted file mode 100644 index 103957b..0000000 --- a/.github/pull_request_template.md +++ /dev/null @@ -1,6 +0,0 @@ -#### How to run tests? -- Before running tests please take master merge in the PR -- In Actions go to `Robot Test workflow for Python from workflow_dispatch` workflow. -- Run the workflow by using the workflow from `sdk` branch and giving the PR number in the input box. - -Note: Only BrowserStack Team can trigger the tests. From bf07fdd0ad2ae05e723146c45fe5f432a373739e Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Tue, 11 Apr 2023 10:59:27 +0530 Subject: [PATCH 13/22] fix codeowners --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 8f0fab7..7e1f1b4 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -.github/workflows/*.yml @browserstack/asi-devs +.github/* @browserstack/asi-devs From a1bb638a31c75475ad4c0025a23538428335be57 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Tue, 11 Apr 2023 12:58:10 +0530 Subject: [PATCH 14/22] fix name in workflow file --- .github/workflows/reviewing_changes.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reviewing_changes.yml b/.github/workflows/reviewing_changes.yml index f045279..ed4e01c 100644 --- a/.github/workflows/reviewing_changes.yml +++ b/.github/workflows/reviewing_changes.yml @@ -1,7 +1,7 @@ # This job is to test different profiles in sdk branch against Pull Requests raised # This workflow targets robot -name: Robot Test workflow for Python from workflow_dispatch +name: Python SDK Test workflow on workflow_dispatch on: workflow_dispatch: From f6d6fe675ab2f212ce3c10be53b5c166aefb23a5 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Thu, 13 Apr 2023 13:58:19 +0530 Subject: [PATCH 15/22] Fix run commands --- .github/workflows/reviewing_changes.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/reviewing_changes.yml b/.github/workflows/reviewing_changes.yml index ed4e01c..286fd33 100644 --- a/.github/workflows/reviewing_changes.yml +++ b/.github/workflows/reviewing_changes.yml @@ -60,10 +60,10 @@ jobs: run: python -m pip install -r requirements.txt - name: run tests in parallel - run: browserstack-sdk robot ./tests/parallel/*.robot + run: browserstack-sdk robot ./tests/test-*.robot - name: run local tests in parallel - run: browserstack-sdk robot ./tests/LocalTest.robot + run: browserstack-sdk robot ./tests/local-test.robot - if: always() uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 From e5e1f523cda9cb40be5cd9756e1768a1e9c85cab Mon Sep 17 00:00:00 2001 From: Ankit Singh <2501.ankit@gmail.com> Date: Tue, 18 Apr 2023 19:11:30 +0530 Subject: [PATCH 16/22] chore: remove version pin --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 789a91d..9553199 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ robotframework -robotframework-seleniumlibrary==5.1.3 +robotframework-seleniumlibrary robotframework-pabot browserstack-local selenium From 2527dea615dcbbbda4c3faf885518508b8207e79 Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Mon, 19 Jun 2023 12:47:47 +0530 Subject: [PATCH 17/22] Added BStack to test cases --- tests/local-test.robot | 2 +- tests/test-1.robot | 2 +- tests/test-2.robot | 2 +- tests/test-3.robot | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/local-test.robot b/tests/local-test.robot index 3b09b0b..c99ca14 100644 --- a/tests/local-test.robot +++ b/tests/local-test.robot @@ -16,6 +16,6 @@ Execute local test *** Test Cases *** -Local Test +BStack Local Test Add Implicit Wait Verify Local Page diff --git a/tests/test-1.robot b/tests/test-1.robot index 79d78c0..cc5ba31 100644 --- a/tests/test-1.robot +++ b/tests/test-1.robot @@ -17,5 +17,5 @@ Execute test *** Test Cases *** -Add to Cart Test 1 +BStack Sample Test 1 Add to Cart diff --git a/tests/test-2.robot b/tests/test-2.robot index c930fdf..1e44aec 100644 --- a/tests/test-2.robot +++ b/tests/test-2.robot @@ -17,5 +17,5 @@ Execute test *** Test Cases *** -Add to Cart Test 2 +BStack Sample Test 2 Add to Cart diff --git a/tests/test-3.robot b/tests/test-3.robot index 8662d77..06057e8 100644 --- a/tests/test-3.robot +++ b/tests/test-3.robot @@ -17,5 +17,5 @@ Execute test *** Test Cases *** -Add to Cart Test 3 +BStack Sample Test 3 Add to Cart From d47c6f29c2fc916624e6fa7be36ca9c988f9fd2a Mon Sep 17 00:00:00 2001 From: Neha Agarwal Date: Mon, 10 Jul 2023 13:24:44 +0530 Subject: [PATCH 18/22] delete sdk workflow --- .github/workflows/reviewing_changes.yml | 88 ------------------------- 1 file changed, 88 deletions(-) delete mode 100644 .github/workflows/reviewing_changes.yml diff --git a/.github/workflows/reviewing_changes.yml b/.github/workflows/reviewing_changes.yml deleted file mode 100644 index 286fd33..0000000 --- a/.github/workflows/reviewing_changes.yml +++ /dev/null @@ -1,88 +0,0 @@ -# This job is to test different profiles in sdk branch against Pull Requests raised -# This workflow targets robot - -name: Python SDK Test workflow on workflow_dispatch - -on: - workflow_dispatch: - inputs: - pull_request_number: - description: 'The pull request number to build' - required: true - -jobs: - comment-run: - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - max-parallel: 3 - matrix: - python: ['3.7', '3.10', '3.11'] - os: [ macos-latest, windows-latest, ubuntu-latest ] - name: Robot Repo ${{ matrix.python }} - ${{ matrix.os }} Sample - env: - BROWSERSTACK_USERNAME: ${{ secrets.BROWSERSTACK_USERNAME }} - BROWSERSTACK_ACCESS_KEY: ${{ secrets.BROWSERSTACK_ACCESS_KEY }} - - steps: - - uses: actions/checkout@v3 - with: - ref: refs/pull/${{ github.event.inputs.pull_request_number }}/head - - name: Fetch Commit SHA - run: | - git log -1 --format='%H' - echo "commit_sha=$(git log -1 --format='%H')" >> $GITHUB_ENV - echo "commit_sha=$(git log -1 --format='%H')" >> $env:GITHUB_ENV - - uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 - id: status-check-in-progress - env: - job_name: Robot Repo ${{ matrix.python }} - ${{ matrix.os }} Sample - with: - github-token: ${{ github.token }} - script: | - const result = await github.rest.checks.create({ - owner: context.repo.owner, - repo: context.repo.repo, - name: process.env.job_name, - head_sha: process.env.commit_sha, - status: 'in_progress' - }).catch((err) => ({status: err.status, response: err.response})); - console.log(`The status-check response : ${result.status} Response : ${JSON.stringify(result.response)}`) - if (result.status !== 201) { - console.log('Failed to create check run') - } - - name: Setup python - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python }} - - - name: Install dependencies - run: python -m pip install -r requirements.txt - - - name: run tests in parallel - run: browserstack-sdk robot ./tests/test-*.robot - - - name: run local tests in parallel - run: browserstack-sdk robot ./tests/local-test.robot - - - if: always() - uses: actions/github-script@98814c53be79b1d30f795b907e553d8679345975 - id: status-check-completed - env: - conclusion: ${{ job.status }} - job_name: Robot Repo ${{ matrix.python }} - ${{ matrix.os }} Sample - with: - github-token: ${{ github.token }} - script: | - const result = await github.rest.checks.create({ - owner: context.repo.owner, - repo: context.repo.repo, - name: process.env.job_name, - head_sha: process.env.commit_sha, - status: 'completed', - conclusion: process.env.conclusion - }).catch((err) => ({status: err.status, response: err.response})); - console.log(`The status-check response : ${result.status} Response : ${JSON.stringify(result.response)}`) - if (result.status !== 201) { - console.log('Failed to create check run') - } From 16866d14b48af452166b821730af1b678c8b5445 Mon Sep 17 00:00:00 2001 From: 07souravkunda Date: Fri, 22 Dec 2023 20:43:07 +0530 Subject: [PATCH 19/22] fix: safari failure --- resources/KeywordsFile.robot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/KeywordsFile.robot b/resources/KeywordsFile.robot index bc059f6..9bc77a3 100644 --- a/resources/KeywordsFile.robot +++ b/resources/KeywordsFile.robot @@ -7,7 +7,7 @@ ${remote_url}= http://localhost:4444/wd/hub *** Keywords *** Open Session [Arguments] ${capabilities} ${test_url} - open browser remote_url=${remote_url} desired_capabilities=${capabilities} url=${test_url} + open browser remote_url=${remote_url} browser=chrome desired_capabilities=${capabilities} url=${test_url} Close Session close browser From 6a8d8bae92a0d2746104fdea13adc68ae528a0c6 Mon Sep 17 00:00:00 2001 From: Sriteja Sugoor <32356934+sriteja777@users.noreply.github.com> Date: Fri, 19 Jan 2024 15:07:52 +0530 Subject: [PATCH 20/22] pin version for robotframework --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 9553199..0c6bd05 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -robotframework +robotframework==6.1.1 robotframework-seleniumlibrary robotframework-pabot browserstack-local From c2484f13bfab4b06e3045f68c3c877109d72fe8c Mon Sep 17 00:00:00 2001 From: Sriteja Sugoor <32356934+sriteja777@users.noreply.github.com> Date: Fri, 19 Jan 2024 15:44:45 +0530 Subject: [PATCH 21/22] Update requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 0c6bd05..da7f504 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ robotframework==6.1.1 -robotframework-seleniumlibrary +robotframework-seleniumlibrary==6.2.0 robotframework-pabot browserstack-local selenium From 94b4aa1c3763fa89b4ead8d58f091d68373431a3 Mon Sep 17 00:00:00 2001 From: Hrithik Katiyar Date: Mon, 1 Jul 2024 16:01:48 +0530 Subject: [PATCH 22/22] Fixed linting issue --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 77b0a7b..36f7206 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,5 @@ pabot_results/ .pabotsuitenames .DS_Store *.png -env browserstack.err +env