diff --git a/README.md b/README.md index ce299d6..98180ab 100644 --- a/README.md +++ b/README.md @@ -27,18 +27,6 @@ This repository contains the following Cucumber tests: | User | Login as User with no image loaded | This test verifies that the product images load for user: "image_not_loading_user" on the e-commerce application. Since the images do not load, the test case assertion fails. | user | | User | Login as User with existing Orders | This test verifies that existing orders are shown for user: "existing_orders_user" | user | ---- -## Configuring the maximum parallel test threads for this repository - -For all the parallel run configuration profiles, you can configure the maximum parallel test threads by changing the number of workers in [pavement.py](pavement.py) - -```py -... pytest -s src/test/suites/e2e.py --driver Browserstack -n 2 -``` - -eg: Using `-n 2` will execute `2` tests in parallel per environment configuration that has been passed in the capabilities - ---- # On Premise This infrastructure points to running the tests on your own machine using a browser (e.g. Chrome) using the browser's driver executables (e.g. ChromeDriver for Chrome). Selenium enables this functionality using WebDriver for many popular browsers. @@ -58,7 +46,7 @@ Note: The ChromeDriver version must match the Chrome browser version on your mac To run the entire test suite on your own machine, use the following command: ```sh - paver run single on-prem + pytest -s src/test/suites/*.py --driver Chrome --driver-path src/driver/chromedriver ``` - Output @@ -89,29 +77,25 @@ Note: The ChromeDriver version must match the Chrome browser version on your mac set BROWSERSTACK_ACCESS_KEY= ``` - Alternatively, you can also hardcode username and access_key objects in the [single.json](src/resources/single.json) file, [parallel.json](src/resources/parallel.json) and [local.json](src/resources/local.json). - -Note: - -- The exact test capability values can be easily identified using the [Browserstack Capability Generator](https://browserstack.com/automate/capabilities) + Alternatively, you can also hardcode username and access_key objects in the browserstack.yml file, ## Running Your Tests -### Run the entire test suite in parallel on a single BrowserStack browser +### Run the entire test suite in parallel on a BrowserStack browser -In this section, we will run the tests in parallel on a single browser on Browserstack. +In this section, we will run the tests in parallel on a browser on Browserstack. - How to run the test? - To run the entire test suite in parallel on a single BrowserStack browser, use the following command: + To run the entire test suite in parallel on a BrowserStack browser, use the following command: ```sh - paver run single remote + browserstack-sdk pytest -s src/test/suites/*.py --browserstack.config ./src/conf/browserstack_single.yml ``` - Output - This run profile executes the entire test suite in parallel on a single BrowserStack browser. Please refer to your [BrowserStack dashboard](https://automate.browserstack.com/) for test results. + This run profile executes the entire test suite in parallel on a BrowserStack browser. Please refer to your [BrowserStack dashboard](https://automate.browserstack.com/) for test results. ### Run the entire test suite in parallel on multiple BrowserStack browsers @@ -122,7 +106,7 @@ In this section, we will run the tests in parallel on multiple browsers on Brows To run the entire test suite in parallel on multiple BrowserStack browsers, use the following command: ```sh - paver run parallel remote + browserstack-sdk pytest -s src/test/suites/*.py --browserstack.config ./src/conf/browserstack_parallel.yml ``` ### [Web application hosted on internal environment] Running your tests on BrowserStack using BrowserStackLocal @@ -133,7 +117,7 @@ In this section, we will run the tests in parallel on multiple browsers on Brows git clone https://github.com/browserstack/browserstack-demo-app ``` - Please follow the README.md on the BrowserStack demo application repository to install and start the dev server on localhost. -- In this section, we will run a single test case to test the BrowserStack Demo app hosted on your local machine i.e. localhost. Refer to the `browserstack.local` object in `nightwatch-browserstack.conf.js` file to change test capabilities for this configuration. +- In this section, we will run a single test case to test the BrowserStack Demo app hosted on your local machine i.e. localhost. - Note: You may need to provide additional BrowserStackLocal arguments to successfully connect your localhost environment with BrowserStack infrastructure. (e.g if you are behind firewalls, proxy or VPN). - Further details for successfully creating a BrowserStackLocal connection can be found here: @@ -143,10 +127,10 @@ In this section, we will run the tests in parallel on multiple browsers on Brows - How to run the test? - - To run the default test scenario (e.g. End to End Scenario) on a single BrowserStack browser using BrowserStackLocal, use the following command: + - To run the default test scenario (e.g. End to End Scenario) on a single BrowserStack browser using BrowserStackLocal, update the 'browserstackLocal' in the browserstack.yml file & use the following command: ```sh - paver run local remote + LOCAL=True browserstack-sdk pytest -s src/test/suites/*.py --browserstack.config ./src/conf/browserstack_local.yml ``` - Output diff --git a/browserstack.yml b/browserstack.yml new file mode 100644 index 0000000..f3f0153 --- /dev/null +++ b/browserstack.yml @@ -0,0 +1,68 @@ +# ============================= +# Set BrowserStack Credentials +# ============================= +# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and +# BROWSERSTACK_ACCESS_KEY as env variables +userName: +accessKey: + +# ====================== +# BrowserStack Reporting +# ====================== +# The following capabilities are used to set up reporting on BrowserStack: +# Set 'projectName' to the name of your project. Example, Marketing Website +projectName: POC Test +# 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} +# Set `framework` of your test suite. Example, `testng`, `cucumber`, `cucumber-testng` +# This property is needed to send test context to BrowserStack (test name, status) +framework: pytest + +# ======================================= +# 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 + browserName: Chrome + browserVersion: latest + +# ======================= +# 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: false # (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 available 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 (Default: errors) +# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors) diff --git a/conftest.py b/conftest.py deleted file mode 100644 index e6089f4..0000000 --- a/conftest.py +++ /dev/null @@ -1,62 +0,0 @@ -import pytest -from browserstack.local import Local -import os, json -from jsonmerge import merge -from dotenv import load_dotenv -import time - -load_dotenv() - -CONFIG_FILE = os.environ['CONFIG_FILE'] if 'CONFIG_FILE' in os.environ else 'resources/single.json' -TASK_ID = int(os.environ['TASK_ID']) if 'TASK_ID' in os.environ else 0 - - -with open(CONFIG_FILE) as data_file: - CONFIG = json.load(data_file) - -bs_local = None -timenow = None - -BROWSERSTACK_USERNAME = os.environ['BROWSERSTACK_USERNAME'] if 'BROWSERSTACK_USERNAME' in os.environ else CONFIG["user"] -BROWSERSTACK_ACCESS_KEY = os.environ['BROWSERSTACK_ACCESS_KEY'] if 'BROWSERSTACK_ACCESS_KEY' in os.environ else CONFIG["key"] - -def start_local(): - """Code to start browserstack local before start of test.""" - global bs_local - global timenow - timenow=str(time.time()*1000) - print(timenow) - bs_local = Local() - bs_local_args = { "key": BROWSERSTACK_ACCESS_KEY or "access_key", "localIdentifier": timenow } - bs_local.start(**bs_local_args) - -def stop_local(): - """Code to stop browserstack local after end of test.""" - global bs_local - if bs_local is not None: - bs_local.stop() - -if os.environ['REMOTE'] == "true": - @pytest.fixture(scope='session') - def session_capabilities(): - global timenow - test_name = os.environ.get('PYTEST_CURRENT_TEST').split(' ')[0].split('::')[1] - capabilities = merge(CONFIG['environments'][TASK_ID],CONFIG["capabilities"]) - capabilities['bstack:options']['userName'] = BROWSERSTACK_USERNAME - capabilities['bstack:options']['accessKey'] = BROWSERSTACK_ACCESS_KEY - capabilities['bstack:options']['source'] = 'pytest:sample-main:v1.0' - capabilities['bstack:options']['sessionName'] = test_name - print(CONFIG['base_url']) - if "local" in capabilities['bstack:options'] and capabilities['bstack:options']['local']: - start_local() - capabilities['bstack:options']['localIdentifier'] = timenow - return capabilities - -@pytest.fixture(scope='session') -def base_url(): - print(CONFIG['base_url']) - return CONFIG['base_url'] - -def pytest_sessionfinish(session, exitstatus): - stop_local() - diff --git a/pavement.py b/pavement.py deleted file mode 100644 index 587eaca..0000000 --- a/pavement.py +++ /dev/null @@ -1,52 +0,0 @@ -from paver.easy import * -from paver.setuputils import setup -from multiprocess import Process -import platform -import json - -setup( - name = "pytest-browserstack", - version = "0.1.0", - author = "BrowserStack", - author_email = "support@browserstack.com", - description = ("PyTest Integration with BrowserStack"), - license = "MIT", - keywords = "example selenium browserstack", - url = "https://github.com/browserstack/pytest-browserstack", - packages=['tests'] -) - -def run_py_test(config, run_type, task_id=0): - if config == 'local' and run_type == 'remote': - if platform.system() == "Windows": - sh('cmd /C "set CONFIG_FILE=resources/%s.json && set TASK_ID=%s && set REMOTE=true && pytest -s src/test/suites/e2e.py --driver Browserstack -n 1"' % (config, task_id)) - else: - sh('CONFIG_FILE=resources/%s.json TASK_ID=%s REMOTE=true pytest -s src/test/suites/e2e.py --driver Browserstack -n 1' % (config, task_id)) - elif run_type == 'remote': - if platform.system() == "Windows": - sh('cmd /C "set CONFIG_FILE=resources/%s.json && set TASK_ID=%s && set REMOTE=true && pytest -s src/test/suites/*.py --driver Browserstack -n 1"' % (config, task_id)) - else: - sh('CONFIG_FILE=resources/%s.json TASK_ID=%s REMOTE=true pytest -s src/test/suites/*.py --driver Browserstack -n 1' % (config, task_id)) - else: - if platform.system() == "Windows": - sh('cmd /C "set CONFIG_FILE=resources/%s.json && set TASK_ID=%s && set REMOTE=false && pytest -s src/test/suites/*.py --driver Chrome --driver-path src/driver/chromedriver -n 1"' % (config, task_id)) - else: - sh('CONFIG_FILE=resources/%s.json TASK_ID=%s REMOTE=false pytest -s src/test/suites/*.py --driver Chrome --driver-path src/driver/chromedriver -n 1' % (config, task_id)) - - -@task -@consume_nargs(2) -def run(args): - """Run single, local and parallel test using different config.""" - jobs = [] - print(*args) - config_file = 'resources/%s.json' % (args[0]) - with open(config_file) as data_file: - CONFIG = json.load(data_file) - environments = CONFIG['environments'] - for i in range(len(environments)): - p = Process(target=run_py_test, args=(args[0], args[1], i)) - jobs.append(p) - p.start() - - \ No newline at end of file diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..03f586d --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +pythonpath = . \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 289a94c..967a2e6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -browserstack-local +browserstack-sdk jsonmerge multiprocess paver diff --git a/resources/local.json b/resources/local.json deleted file mode 100644 index f105c92..0000000 --- a/resources/local.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "user": "BROWSERSTACK_USERNAME", - "key": "BROWSERSTACK_ACCESS_KEY", - "base_url":"http://localhost:3000/", - "capabilities": { - "bstack:options": { - "projectName": "Pytest Browserstack", - "buildName": "browserstack-build-local", - "local": true, - "debug": "true", - "networkLogs": "true" - } - }, - "environments": [ - { - "bstack:options": { - "os": "Windows", - "osVersion": "11" - }, - "browserName": "chrome", - "browserVersion": "latest" - } - ] -} - diff --git a/resources/parallel.json b/resources/parallel.json deleted file mode 100644 index ef73a3d..0000000 --- a/resources/parallel.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "user": "BROWSERSTACK_USERNAME", - "key": "BROWSERSTACK_ACCESS_KEY", - "base_url": "https://bstackdemo.com/", - "capabilities": { - "bstack:options": { - "projectName": "Pytest Browserstack", - "buildName": "browserstack-build-parallel", - "local": false, - "debug": "true", - "networkLogs": "true" - } - }, - "environments": [ - { - "bstack:options": { - "os": "Windows", - "osVersion": "11" - }, - "browserName": "chrome", - "browserVersion": "latest" - }, - { - "bstack:options": { - "os": "Windows", - "osVersion": "10" - }, - "browserName": "Chrome", - "browserVersion": "latest" - }, - { - "bstack:options": { - "os": "OS X", - "osVersion": "Monterey" - }, - "browserName": "Safari", - "browserVersion": "15.0" - }, - { - "bstack:options": { - "os": "Windows", - "osVersion": "10" - }, - "browserName": "Edge", - "browserVersion": "106.0" - }, - { - "bstack:options": { - "osVersion": "13.0", - "deviceName": "Google Pixel 6 Pro" - } - }, - { - "bstack:options" : { - "osVersion" : "16", - "deviceName" : "iPhone 12 Pro Max" - } - } - ] -} - diff --git a/resources/single.json b/resources/single.json deleted file mode 100644 index 330bab3..0000000 --- a/resources/single.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "user": "BROWSERSTACK_USERNAME", - "key": "BROWSERSTACK_ACCESS_KEY", - "base_url":"https://bstackdemo.com/", - "capabilities": { - "bstack:options": { - "projectName": "Pytest Browserstack", - "buildName": "browserstack-build-single", - "local": false, - "debug": "true", - "networkLogs": "true" - } - }, - "environments": [ - { - "bstack:options": { - "os": "Windows", - "osVersion": "11" - }, - "browserName": "Chrome", - "browserVersion": "108" - } - ] -} - diff --git a/src/conf/browserstack_local.yml b/src/conf/browserstack_local.yml new file mode 100644 index 0000000..4da7fb6 --- /dev/null +++ b/src/conf/browserstack_local.yml @@ -0,0 +1,68 @@ +# ============================= +# Set BrowserStack Credentials +# ============================= +# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and +# BROWSERSTACK_ACCESS_KEY as env variables +userName: +accessKey: + +# ====================== +# BrowserStack Reporting +# ====================== +# 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} +# Set `framework` of your test suite. Example, `testng`, `cucumber`, `cucumber-testng` +# This property is needed to send test context to BrowserStack (test name, status) +framework: pytest + +# ======================================= +# 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 + browserName: Chrome + browserVersion: latest + +# ======================= +# 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 available 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 (Default: errors) +# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors) diff --git a/src/conf/browserstack_parallel.yml b/src/conf/browserstack_parallel.yml new file mode 100644 index 0000000..f25b70b --- /dev/null +++ b/src/conf/browserstack_parallel.yml @@ -0,0 +1,72 @@ +# ============================= +# Set BrowserStack Credentials +# ============================= +# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and +# BROWSERSTACK_ACCESS_KEY as env variables +userName: +accessKey: + +# ====================== +# BrowserStack Reporting +# ====================== +# 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} +# Set `framework` of your test suite. Example, `testng`, `cucumber`, `cucumber-testng` +# This property is needed to send test context to BrowserStack (test name, status) +framework: pytest + +# ======================================= +# 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 + browserName: Chrome + browserVersion: latest + - os: Windows + osVersion: 10 + browserName: Edge + browserVersion: latest + +# ======================= +# 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: 2 + +# ========================================== +# 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: false # (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 available 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 (Default: errors) +# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors) diff --git a/src/conf/browserstack_single.yml b/src/conf/browserstack_single.yml new file mode 100644 index 0000000..f3f0153 --- /dev/null +++ b/src/conf/browserstack_single.yml @@ -0,0 +1,68 @@ +# ============================= +# Set BrowserStack Credentials +# ============================= +# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and +# BROWSERSTACK_ACCESS_KEY as env variables +userName: +accessKey: + +# ====================== +# BrowserStack Reporting +# ====================== +# The following capabilities are used to set up reporting on BrowserStack: +# Set 'projectName' to the name of your project. Example, Marketing Website +projectName: POC Test +# 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} +# Set `framework` of your test suite. Example, `testng`, `cucumber`, `cucumber-testng` +# This property is needed to send test context to BrowserStack (test name, status) +framework: pytest + +# ======================================= +# 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 + browserName: Chrome + browserVersion: latest + +# ======================= +# 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: false # (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 available 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 (Default: errors) +# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors) diff --git a/src/test/suites/addToCart.py b/src/test/suites/addToCart.py index b0ff8de..7678be6 100644 --- a/src/test/suites/addToCart.py +++ b/src/test/suites/addToCart.py @@ -3,9 +3,18 @@ import pytest from selenium.webdriver.common.by import By import os +from dotenv import load_dotenv + +load_dotenv() @pytest.mark.nondestructive -def test_example(driver, base_url): +def test_example(driver, base_url="https://bstackdemo.com/"): + staging = os.environ.get("LOCAL") + if (staging=="True"): + base_url="http://localhost:3000/" + else: + base_url="https://bstackdemo.com/" + driver.get(base_url) # locating product on webpage and getting name of the product @@ -20,11 +29,4 @@ def test_example(driver, base_url): # locating product in cart and getting name of the product in cart productCartText = driver.find_element(By.XPATH, '//*[@id="__next"]/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]').text - # checking whether product has been added to cart by comparing product name and marking test pass or fail - if os.environ['REMOTE'] == "true": - driver.execute_script('browserstack_executor: {"action": "setSessionName", "arguments": {"name":"addToCart_test"}}') - if productText == productCartText: - driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test Passed Successfully"}}') - else: - driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Product added to the cart not same as selected"}}') diff --git a/src/test/suites/e2e.py b/src/test/suites/e2e.py index 8b918e4..2fe06af 100644 --- a/src/test/suites/e2e.py +++ b/src/test/suites/e2e.py @@ -12,12 +12,18 @@ from dotenv import load_dotenv import os +import json load_dotenv() -@pytest.mark.nondestructive -def test_e2e(driver, base_url): +#@pytest.mark.nondestructive +def test_e2e(driver, base_url="https://bstackdemo.com/"): + staging = os.environ.get("LOCAL") + if (staging=="True"): + base_url="http://localhost:3000/" + else: + base_url="https://bstackdemo.com/" login = LoginPage(driver) login.open_base_url(base_url) login.sign_in("fav_user","testingisfun99") @@ -33,19 +39,9 @@ def test_e2e(driver, base_url): checkout.click_on_checkout() order_confirm = OrderConfirmationPage(driver) order_confirm.wait_for_confirmation_message() - if os.environ['REMOTE'] == "true": - order_confirm.click_download_pdf() - order_confirm.download_exists(driver, 'confirmation.pdf' ) order_confirm.click_continue_shopping() home.navigate_to_orders() orders = OrdersPage(driver) status = orders.verify_orders_placed() time.sleep(5) - if os.environ['REMOTE'] == "true": - driver.execute_script('browserstack_executor: {"action": "setSessionName", "arguments": {"name":"e2e_test"}}') - if status: - driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test Passed Successfully"}}') - else: - driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Order Not Placed Successfully"}}') - - \ No newline at end of file + \ No newline at end of file diff --git a/src/test/suites/login.py b/src/test/suites/login.py index 4d5adc7..3b62c04 100644 --- a/src/test/suites/login.py +++ b/src/test/suites/login.py @@ -9,32 +9,35 @@ from src.pages.loginPage import LoginPage from src.pages.homePage import HomePage import os +from dotenv import load_dotenv + +load_dotenv() @pytest.mark.nondestructive -def test_login(driver, base_url): +def test_login(driver, base_url="https://bstackdemo.com/"): + staging = os.environ.get("LOCAL") + if (staging=="True"): + base_url="http://localhost:3000/" + else: + base_url="https://bstackdemo.com/" login = LoginPage(driver) login.open_base_url(base_url) login.sign_in("fav_user","testingisfun99") home = HomePage(driver) username = home.signed_in_user() - if os.environ['REMOTE'] == "true": - driver.execute_script('browserstack_executor: {"action": "setSessionName", "arguments": {"name":"Login_Test"}}') - if username == "fav_user": - driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test Passed Successfully"}}') - else: - driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Username not found. Login Failed"}}') + @pytest.mark.nondestructive -def test_login_locked_user(driver, base_url): +def test_login_locked_user(driver, base_url="https://bstackdemo.com/"): + staging = os.environ.get("LOCAL") + if (staging=="True"): + base_url="http://localhost:3000/" + else: + base_url="https://bstackdemo.com/" login = LoginPage(driver) login.open_base_url(base_url) login.sign_in("locked_user","testingisfun99") text = login.wait_element_present((By.CLASS_NAME, 'api-error')).text - if os.environ['REMOTE'] == "true": - driver.execute_script('browserstack_executor: {"action": "setSessionName", "arguments": {"name":"Login_Test_Locked_User"}}') - if text == "Your account has been locked.": - driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test Passed Successfully"}}') - else: - driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Locked User Test Failed"}}') + diff --git a/src/test/suites/offers.py b/src/test/suites/offers.py index aae7f48..c331e2e 100644 --- a/src/test/suites/offers.py +++ b/src/test/suites/offers.py @@ -7,10 +7,17 @@ from selenium.common.exceptions import NoSuchElementException import time import os +from dotenv import load_dotenv +load_dotenv() @pytest.mark.nondestructive -def test_offers(driver, base_url): +def test_offers(driver, base_url="https://bstackdemo.com/"): + staging = os.environ.get("LOCAL") + if (staging=="True"): + base_url="http://localhost:3000/" + else: + base_url="https://bstackdemo.com/" driver.get(base_url) driver.execute_script('navigator.geolocation.getCurrentPosition = function(success){ var position = { "coords":{"latitude":"1","longitude":"103"}}; success(position);}') WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, 'signin'))) @@ -29,11 +36,5 @@ def test_offers(driver, base_url): #Click on Offers WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, 'offers'))) driver.find_element(By.ID, "offers").click() - if os.environ['REMOTE'] == "true": - driver.execute_script('browserstack_executor: {"action": "setSessionName", "arguments": {"name":"Offers_test"}}') - try: - driver.find_element(By.CLASS_NAME,'offer') - driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test Passed Successfully"}}') - except NoSuchElementException: - driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Offers Not Found Successfully"}}') + diff --git a/src/test/suites/product.py b/src/test/suites/product.py index dce4c32..852a8a4 100644 --- a/src/test/suites/product.py +++ b/src/test/suites/product.py @@ -9,9 +9,17 @@ from src.pages.loginPage import LoginPage from src.pages.homePage import HomePage import os +from dotenv import load_dotenv + +load_dotenv() @pytest.mark.nondestructive -def test_apple_filter(driver, base_url): +def test_apple_filter(driver, base_url="https://bstackdemo.com/"): + staging = os.environ.get("LOCAL") + if (staging=="True"): + base_url="http://localhost:3000/" + else: + base_url="https://bstackdemo.com/" login = LoginPage(driver) login.open_base_url(base_url) login.sign_in("fav_user","testingisfun99") @@ -19,25 +27,20 @@ def test_apple_filter(driver, base_url): home.filter_by_element() time.sleep(5) count = home.get_count_of_products() - if os.environ['REMOTE'] == "true": - driver.execute_script('browserstack_executor: {"action": "setSessionName", "arguments": {"name":"Apple_Filter_Test"}}') - if count == 9: - driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test Passed Successfully"}}') - else: - driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Filter Not Successful"}}') + @pytest.mark.nondestructive -def test_price_filter(driver, base_url): +def test_price_filter(driver, base_url="https://bstackdemo.com/"): + staging = os.environ.get("LOCAL") + if (staging=="True"): + base_url="http://localhost:3000/" + else: + base_url="https://bstackdemo.com/" login = LoginPage(driver) login.open_base_url(base_url) login.sign_in("fav_user","testingisfun99") home = HomePage(driver) home.select_lowest_price_filter() time.sleep(5) - if os.environ['REMOTE'] == "true": - driver.execute_script('browserstack_executor: {"action": "setSessionName", "arguments": {"name":"Price_Filter_Test"}}') - if home.confirm_element_name() == 'Pixel 2': - driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test Passed Successfully"}}') - else: - driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Filter Not Successful"}}') + diff --git a/src/test/suites/user.py b/src/test/suites/user.py index af8f8c3..944934b 100644 --- a/src/test/suites/user.py +++ b/src/test/suites/user.py @@ -10,9 +10,17 @@ from src.pages.orders import OrdersPage from src.pages.homePage import HomePage import os +from dotenv import load_dotenv + +load_dotenv() @pytest.mark.nondestructive -def test_existing_orders(driver, base_url): +def test_existing_orders(driver, base_url="https://bstackdemo.com/"): + staging = os.environ.get("LOCAL") + if (staging=="True"): + base_url="http://localhost:3000/" + else: + base_url="https://bstackdemo.com/" login = LoginPage(driver) login.open_base_url(base_url) login.sign_in("existing_orders_user","testingisfun99") @@ -20,24 +28,19 @@ def test_existing_orders(driver, base_url): home.navigate_to_orders() order_confirm = OrdersPage(driver) status = order_confirm.verify_orders_placed() - if os.environ['REMOTE'] == "true": - driver.execute_script('browserstack_executor: {"action": "setSessionName", "arguments": {"name":"Existing_Orders_Test"}}') - if status: - driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test Passed Successfully"}}') - else: - driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "No Existing Orders"}}') + @pytest.mark.nondestructive -def test_no_image(driver, base_url): +def test_no_image(driver, base_url="https://bstackdemo.com/"): + staging = os.environ.get("LOCAL") + if (staging=="True"): + base_url="http://localhost:3000/" + else: + base_url="https://bstackdemo.com/" login = LoginPage(driver) login.open_base_url(base_url) login.sign_in("image_not_loading_user","testingisfun99") home = HomePage(driver) - if os.environ['REMOTE'] == "true": - driver.execute_script('browserstack_executor: {"action": "setSessionName", "arguments": {"name":"No_Image_Loaded_Test"}}') - if home.verify_image_thumbnail_loading(): - driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test Passed Successfully"}}') - else: - driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Test Failed"}}') + \ No newline at end of file