From 5493fbf4dd066d8f928a5db7bedee3bbe00f8404 Mon Sep 17 00:00:00 2001 From: princebaretto99 Date: Tue, 1 Nov 2022 20:55:55 +0530 Subject: [PATCH 01/22] Initial Push --- .DS_Store | Bin 0 -> 6148 bytes .gitignore | 5 +++ README.md | 27 ++++++++++++++ config/local.json | 22 ++++++++++++ config/parallel.json | 27 ++++++++++++++ config/single.json | 22 ++++++++++++ conftest.py | 58 ++++++++++++++++++++++++++++++ pavement.py | 36 +++++++++++++++++++ requirements.txt | 11 ++++++ tests/local_tests/local_sample.py | 37 +++++++++++++++++++ tests/test_sample_1.py | 34 ++++++++++++++++++ 11 files changed, 279 insertions(+) create mode 100644 .DS_Store create mode 100644 .gitignore create mode 100644 README.md create mode 100644 config/local.json create mode 100644 config/parallel.json create mode 100644 config/single.json create mode 100644 conftest.py create mode 100644 pavement.py create mode 100644 requirements.txt create mode 100644 tests/local_tests/local_sample.py create mode 100644 tests/test_sample_1.py diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ba345a2aa5f5fcc5141981b96bf30c5244385b45 GIT binary patch literal 6148 zcmeHKy-veG47N)_K`b2^Z(}Y4bEv`-^aW6VD3uygsW7qJ$cwP?7=0}yKA)}9kV8zM z3fYqVU3~WC@?8|iM8u<~*^p>JLg#bVvE~Yt7e9RZUjS1bM~V_TuXDWqbW~jk=lr7_+|byeG%>NORi2ZZdDt z-t7J!-k)FRwue^4=MM4_nfo8&`S_lk0cXG&_zeb7vqg$CMYqm?GvEyD7?AHnfC`p| zQ89fwU{VVJ?8BV|W9cO%Cm5E7Q4uo`)>NRTvb7kj>F@`OD-ENfrW0H9!FFf14u#X* zv3^M5#HFHJXTTX~GjODr1F8Qv-}nFRB)@V7oPmGE0QakLHNqoVZS6dq)Y<^Og^EaA lRNSRtkV-LPr4*k-lfWNj04xooB0LcP5lA$+aR&aBfe-fGNihHb literal 0 HcmV?d00001 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6c8ee20 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.vscode +__pycache__ +.pytest_cache +local.log +testSele \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..5de8f6c --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +# PyTest with Browserstack + +PyTest Integration with BrowserStack. + +![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780) +## Prerequisite +* Python3 + +## Setup + +* Clone the repo +* Install dependencies `pip install -r requirements.txt` +* To run your automated tests using BrowserStack, you must provide a valid username and access key. This can be done either by using a .browserstack configuration file in the working directory or your home directory, by setting the BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY environment variables, or by adding user & key to config file. + + +## Run tests on locally hosted websites +* To run a local test, (if you have not set the BROWSERSTACK_ACCESS_KEY environment variable) first go to config/local.json then edit key on line 3 +* Run `paver run local` + +## Run sample tests +* To run parallel tests, run `paver run single` + + Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) + +## Notes +* 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/python#setting-os-and-browser) diff --git a/config/local.json b/config/local.json new file mode 100644 index 0000000..4c6585d --- /dev/null +++ b/config/local.json @@ -0,0 +1,22 @@ +{ + "user": "BROWSERSTACK_USERNAME", + "key": "BROWSERSTACK_ACCESS_KEY", + "capabilities": { + "app" : "", + "bstack:options": { + "projectName": "Pytest Browserstack", + "buildName": "browserstack-build-1", + "sessionName": "BStack sample pytest", + "local": "true", + "debug": "true", + "networkLogs": "true" + } + }, + "environments": [ + { + "platformName": "android", + "platformVersion": "9.0", + "deviceName": "Google Pixel 3" + } + ] +} \ No newline at end of file diff --git a/config/parallel.json b/config/parallel.json new file mode 100644 index 0000000..e4acb7f --- /dev/null +++ b/config/parallel.json @@ -0,0 +1,27 @@ +{ + "user": "BROWSERSTACK_USERNAME", + "key": "BROWSERSTACK_ACCESS_KEY", + "capabilities": { + "app" : "", + "bstack:options": { + "projectName": "Pytest Browserstack", + "buildName": "browserstack-build-1", + "sessionName": "BStack sample pytest", + "local": false, + "debug": "true", + "networkLogs": "true" + } + }, + "environments": [ + { + "platformName": "android", + "platformVersion": "9.0", + "deviceName": "Google Pixel 3" + }, + { + "platformName": "android", + "platformVersion": "11.0", + "deviceName": "Samsung Galaxy A52" + } + ] +} \ No newline at end of file diff --git a/config/single.json b/config/single.json new file mode 100644 index 0000000..23090f3 --- /dev/null +++ b/config/single.json @@ -0,0 +1,22 @@ +{ + "user": "BROWSERSTACK_USERNAME", + "key": "BROWSERSTACK_ACCESS_KEY", + "capabilities": { + "app" : "", + "bstack:options": { + "projectName": "Pytest Browserstack", + "buildName": "browserstack-build-1", + "sessionName": "BStack sample pytest", + "local": false, + "debug": "true", + "networkLogs": "true" + } + }, + "environments": [ + { + "platformName": "android", + "platformVersion": "9.0", + "deviceName": "Google Pixel 3" + } + ] +} \ No newline at end of file diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..7102bbe --- /dev/null +++ b/conftest.py @@ -0,0 +1,58 @@ +import pytest +from browserstack.local import Local +import os +from appium import webdriver +import json +from jsonmerge import merge +CONFIG_FILE = os.environ['CONFIG_FILE'] if 'CONFIG_FILE' in os.environ else 'config/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 + +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 + bs_local = Local() + bs_local_args = { + "key": BROWSERSTACK_ACCESS_KEY or "access_key", "forcelocal": "true"} + 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() + + +@pytest.fixture(scope='session') +def session_capabilities(): + capabilities = merge(CONFIG['environments'] + [TASK_ID], CONFIG["capabilities"]) + capabilities['bstack:options']['userName'] = BROWSERSTACK_USERNAME + capabilities['bstack:options']['accessKey'] = BROWSERSTACK_ACCESS_KEY + if "local" in capabilities['bstack:options'] and capabilities['bstack:options']['local']: + start_local() + return capabilities + + +@pytest.fixture(scope='function') +def setWebdriver(request, session_capabilities): + remoteURL = "https://hub-cloud.browserstack.com/wd/hub" + driver = webdriver.Remote(remoteURL, session_capabilities) + request.cls.driver = driver + + yield driver + + driver.quit() + + +def pytest_sessionfinish(session, exitstatus): + stop_local() diff --git a/pavement.py b/pavement.py new file mode 100644 index 0000000..1b29c04 --- /dev/null +++ b/pavement.py @@ -0,0 +1,36 @@ +from paver.easy import * +from paver.setuputils import setup +from multiprocess import Process +import platform +import json + +def run_py_test(config, task_id=0): + if platform.system() == "Windows": + if(config=="local"): + sh('cmd /C "set CONFIG_FILE=config/%s.json && set TASK_ID=%s && pytest -s tests/local_tests/*.py"' % (config, task_id)) + elif(config == "parallel"): + sh('cmd /C "set CONFIG_FILE=config/%s.json && set TASK_ID=%s && pytest -s tests/*.py -n 2"' % (config, task_id)) + else: + sh('cmd /C "set CONFIG_FILE=config/%s.json && set TASK_ID=%s && pytest -s tests/*.py"' % (config, task_id)) + + else: + if(config=="local"): + sh('CONFIG_FILE=config/%s.json TASK_ID=%s pytest -s tests/local_tests/*.py' % (config, task_id)) + elif(config == "parallel"): + sh('CONFIG_FILE=config/%s.json TASK_ID=%s pytest -s tests/*.py -n 2' % (config, task_id)) + else: + sh('CONFIG_FILE=config/%s.json TASK_ID=%s pytest -s tests/*.py' % (config, task_id)) + +@task +@consume_nargs(1) +def run(args): + """Run single, local and parallel test using different config.""" + jobs = [] + config_file = 'config/%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], i)) + jobs.append(p) + p.start() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e177fe3 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,11 @@ +browserstack-local +jsonmerge +multiprocess +paver +selenium==4.0.0 +psutil +pytest +pytest-variables +pytest-selenium +pytest-xdist +Appium-Python-Client \ No newline at end of file diff --git a/tests/local_tests/local_sample.py b/tests/local_tests/local_sample.py new file mode 100644 index 0000000..41f6cc6 --- /dev/null +++ b/tests/local_tests/local_sample.py @@ -0,0 +1,37 @@ +from browserstack.local import Local +from appium import webdriver +from appium.webdriver.common.appiumby import AppiumBy +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +import time +import pytest +from selenium.webdriver.common.by import By + + +@pytest.mark.usefixtures('getWebdriver') +class TestSample: + + def test_example(self): + test_button = WebDriverWait(self.driver, 30).until( + EC.element_to_be_clickable( + (AppiumBy.ID, "com.example.android.basicnetworking:id/test_action")) + ) + + test_button.click() + + time.sleep(5) + + test_element = None + search_results = self.driver.find_elements(AppiumBy.CLASS_NAME, "android.widget.TextView") + print(len(search_results)) + for result in search_results: + if "Up and running" in result.text: + test_element = result + + if test_element is None: + self.driver.execute_script( + 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Cannot find the needed TextView element from app"}}') + else: + self.driver.execute_script( + 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test Passed Successfully"}}') + \ No newline at end of file diff --git a/tests/test_sample_1.py b/tests/test_sample_1.py new file mode 100644 index 0000000..d263e29 --- /dev/null +++ b/tests/test_sample_1.py @@ -0,0 +1,34 @@ +from browserstack.local import Local +from appium import webdriver +from appium.webdriver.common.appiumby import AppiumBy +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +import time +import pytest +from selenium.webdriver.common.by import By + +@pytest.mark.usefixtures('setWebdriver') +class TestSample: + + def test_example(self): + search_element = WebDriverWait(self.driver, 30).until( + EC.element_to_be_clickable( + (AppiumBy.ACCESSIBILITY_ID, "Search Wikipedia")) + ) + + search_element.click() + search_input = WebDriverWait(self.driver, 30).until( + EC.element_to_be_clickable( + (AppiumBy.ID, "org.wikipedia.alpha:id/search_src_text")) + ) + search_input.send_keys("BrowserStack") + time.sleep(5) + search_results = self.driver.find_elements( + AppiumBy.CLASS_NAME, "android.widget.TextView") + # checking whether product has been added to cart by comparing product name and marking test pass or fail + if(len(search_results) > 0): + self.driver.execute_script( + 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test Passed Successfully"}}') + else: + self.driver.execute_script( + 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Product added to the cart not same as selected"}}') From 96eca35bd449e57d1f0255c87ad214475824512c Mon Sep 17 00:00:00 2001 From: Princeton Baretto <43331485+princebaretto99@users.noreply.github.com> Date: Tue, 1 Nov 2022 20:57:21 +0530 Subject: [PATCH 02/22] Delete .DS_Store --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index ba345a2aa5f5fcc5141981b96bf30c5244385b45..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKy-veG47N)_K`b2^Z(}Y4bEv`-^aW6VD3uygsW7qJ$cwP?7=0}yKA)}9kV8zM z3fYqVU3~WC@?8|iM8u<~*^p>JLg#bVvE~Yt7e9RZUjS1bM~V_TuXDWqbW~jk=lr7_+|byeG%>NORi2ZZdDt z-t7J!-k)FRwue^4=MM4_nfo8&`S_lk0cXG&_zeb7vqg$CMYqm?GvEyD7?AHnfC`p| zQ89fwU{VVJ?8BV|W9cO%Cm5E7Q4uo`)>NRTvb7kj>F@`OD-ENfrW0H9!FFf14u#X* zv3^M5#HFHJXTTX~GjODr1F8Qv-}nFRB)@V7oPmGE0QakLHNqoVZS6dq)Y<^Og^EaA lRNSRtkV-LPr4*k-lfWNj04xooB0LcP5lA$+aR&aBfe-fGNihHb From 165e94a0bb00d80fae0231d987eb3c6118699169 Mon Sep 17 00:00:00 2001 From: princebaretto99 Date: Tue, 1 Nov 2022 22:25:59 +0530 Subject: [PATCH 03/22] Updated README --- README.md | 133 +++++++++++++++++++++++++++++++++++++------ config/local.json | 2 +- config/parallel.json | 2 +- config/single.json | 2 +- 4 files changed, 120 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 5de8f6c..f28670e 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,128 @@ -# PyTest with Browserstack +# PyTest with Browserstack AppAutomate PyTest Integration with BrowserStack. ![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780) -## Prerequisite -* Python3 +### Requirements -## Setup +1. Python 3.6+ or Python 2.7+ + + - For Windows, download latest python version from [here](https://www.python.org/downloads/windows/) and run the installer executable + - For Mac and Linux, run `python --version` to see what python version is pre-installed. If you want a different version download from [here](https://www.python.org/downloads/) -* Clone the repo -* Install dependencies `pip install -r requirements.txt` -* To run your automated tests using BrowserStack, you must provide a valid username and access key. This can be done either by using a .browserstack configuration file in the working directory or your home directory, by setting the BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY environment variables, or by adding user & key to config file. +2. Package Manager pip + Note : `pip` comes installed with Python 2.7.9+ and python 3.4+ -## Run tests on locally hosted websites -* To run a local test, (if you have not set the BROWSERSTACK_ACCESS_KEY environment variable) first go to config/local.json then edit key on line 3 -* Run `paver run local` + - If `pip` is not installed, follow these instructions: + - Securely download get-pip.py by following this link: [get-pip.py](https://bootstrap.pypa.io/get-pip.py) or use following cURL command to download it: -## Run sample tests -* To run parallel tests, run `paver run single` + ```sh + curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py + ``` - Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github) + - After dowloading, run the file : -## Notes -* 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/python#setting-os-and-browser) + - For Python 3 + + ```sh + python3 get-pip.py + ``` + + - For Python 2 + + ```sh + python2 get-pip.py + ``` + +### Install the dependencies + +To install the dependencies, run the following command in project's base directory: + +- For Python 3 + + ```sh + pip3 install -r requirements.txt + ``` + +- For Python 2 + + ```sh + pip2 install -r requirements.txt + ``` + +## Getting Started + +Getting Started with Pytest-Appium tests in Python on BrowserStack couldn't be easier! + +### Run your first test : + +**1. Upload your Android or iOS App** + +Upload your Android app (.apk or .aab file) or iOS app (.ipa file) to BrowserStack servers using our REST API. Here is an example cURL request : + +``` +curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \ +-X POST "https://api-cloud.browserstack.com/app-automate/upload" \ +-F "file=@/path/to/apk/file" +``` + +Ensure that @ symbol is prepended to the file path in the above request. Please note the `app_url` value returned in the API response. We will use this to set the application under test while configuring the test later on. + +**Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android app](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) or [sample iOS app](https://www.browserstack.com/app-automate/sample-apps/ios/BStackSampleApp.ipa). + + +**2. Configure and run your first test** + +Open `single.json`/`parallel.json` file in `config` folder : + +- Replace `BROWSERSTACK_USERNAME` & `BROWSERSTACK_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings) + +- Replace `bs://` wkth the URL obtained from app upload step + +- Set the deviceName and platformVersion + +- If you have uploaded your own app update the test case + +- Run `paver run single` + +- In orde to run tests in parallel across different configurations mentioned in the `parallel.json` file, run `paver run parallel` + +- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) + +--- + +### **Use Local testing for apps that access resources hosted in development or testing environments :** + +**1. Upload your Android or iOS App** + +Upload your Android app (.apk or .aab file) or iOS app (.ipa file) that access resources hosted on your internal or test environments to BrowserStack servers using our REST API. Here is an example cURL request : + +``` +curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \ +-X POST "https://api-cloud.browserstack.com/app-automate/upload" \ +-F "file=@/path/to/apk/file" +``` + +Ensure that @ symbol is prepended to the file path in the above request. Please note the `app_url` value returned in the API response. We will use this to set the application under test while configuring the test later on. + +**Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android Local app](https://www.browserstack.com/app-automate/sample-apps/android/LocalSample.apk) or [sample iOS Local app](https://www.browserstack.com/app-automate/sample-apps/ios/LocalSample.ipa). + + +**2. Configure and run your local test** + +Open `browserstack_sample_local` file in `Android` or `iOS` folder : + +- Replace `BROWSERSTACK_USERNAME` & `BROWSERSTACK_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings) + +- Replace `bs://` wkth the URL obtained from app upload step + +- Set the device and OS version + +- Ensure that `local` capability is set to `true`. The `conftest.py` contains the code snippet that automatically establishes Local Testing connection to BrowserStack servers using Python binding for BrowserStack Local. + +- If you have uploaded your own app update the test case. The test cases for Local Tests are present [here](tests/local_tests/local_sample.py) + +- Run `paver run local` + +- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) diff --git a/config/local.json b/config/local.json index 4c6585d..73fb23d 100644 --- a/config/local.json +++ b/config/local.json @@ -2,7 +2,7 @@ "user": "BROWSERSTACK_USERNAME", "key": "BROWSERSTACK_ACCESS_KEY", "capabilities": { - "app" : "", + "app" : "bs://", "bstack:options": { "projectName": "Pytest Browserstack", "buildName": "browserstack-build-1", diff --git a/config/parallel.json b/config/parallel.json index e4acb7f..1dc3c1f 100644 --- a/config/parallel.json +++ b/config/parallel.json @@ -2,7 +2,7 @@ "user": "BROWSERSTACK_USERNAME", "key": "BROWSERSTACK_ACCESS_KEY", "capabilities": { - "app" : "", + "app" : "bs://", "bstack:options": { "projectName": "Pytest Browserstack", "buildName": "browserstack-build-1", diff --git a/config/single.json b/config/single.json index 23090f3..0be18b2 100644 --- a/config/single.json +++ b/config/single.json @@ -2,7 +2,7 @@ "user": "BROWSERSTACK_USERNAME", "key": "BROWSERSTACK_ACCESS_KEY", "capabilities": { - "app" : "", + "app" : "bs://", "bstack:options": { "projectName": "Pytest Browserstack", "buildName": "browserstack-build-1", From 5bed28eb9d40f1d062e9259e58ab66ad78fdb85b Mon Sep 17 00:00:00 2001 From: princebaretto99 Date: Tue, 1 Nov 2022 22:33:26 +0530 Subject: [PATCH 04/22] Updated README --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f28670e..a3d79b8 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,10 @@ Open `single.json`/`parallel.json` file in `config` folder : - Run `paver run single` -- In orde to run tests in parallel across different configurations mentioned in the `parallel.json` file, run `paver run parallel` +- In order to run tests in parallel across different configurations mentioned in the [`parallel.json`](config/parallel.json) file, run the below command + ``` + paver run parallel + ``` - You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) @@ -111,13 +114,13 @@ Ensure that @ symbol is prepended to the file path in the above request. Please **2. Configure and run your local test** -Open `browserstack_sample_local` file in `Android` or `iOS` folder : +Open `local.json` file in `conifg` folder : - Replace `BROWSERSTACK_USERNAME` & `BROWSERSTACK_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings) - Replace `bs://` wkth the URL obtained from app upload step -- Set the device and OS version +- Set the deviceName and platformVersion - Ensure that `local` capability is set to `true`. The `conftest.py` contains the code snippet that automatically establishes Local Testing connection to BrowserStack servers using Python binding for BrowserStack Local. From f9fc98025d2507b3f67393a8e69f8843e8aff5b7 Mon Sep 17 00:00:00 2001 From: princebaretto99 Date: Tue, 1 Nov 2022 22:38:10 +0530 Subject: [PATCH 05/22] Updated README --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a3d79b8..421eb80 100644 --- a/README.md +++ b/README.md @@ -84,7 +84,10 @@ Open `single.json`/`parallel.json` file in `config` folder : - If you have uploaded your own app update the test case -- Run `paver run single` +- Run the below command to execute a single test on BrowserStack AppAutomate: + ``` + paver run single + ``` - In order to run tests in parallel across different configurations mentioned in the [`parallel.json`](config/parallel.json) file, run the below command ``` @@ -126,6 +129,9 @@ Open `local.json` file in `conifg` folder : - If you have uploaded your own app update the test case. The test cases for Local Tests are present [here](tests/local_tests/local_sample.py) -- Run `paver run local` +- Run the below command: + ``` + paver run local + ``` - You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) From 59de53900ba187238aa33ddc345b6c1e3912c1a4 Mon Sep 17 00:00:00 2001 From: princebaretto99 Date: Tue, 1 Nov 2022 22:54:16 +0530 Subject: [PATCH 06/22] Updated README --- README.md | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/README.md b/README.md index 421eb80..3c82550 100644 --- a/README.md +++ b/README.md @@ -10,31 +10,6 @@ PyTest Integration with BrowserStack. - For Windows, download latest python version from [here](https://www.python.org/downloads/windows/) and run the installer executable - For Mac and Linux, run `python --version` to see what python version is pre-installed. If you want a different version download from [here](https://www.python.org/downloads/) -2. Package Manager pip - - Note : `pip` comes installed with Python 2.7.9+ and python 3.4+ - - - If `pip` is not installed, follow these instructions: - - Securely download get-pip.py by following this link: [get-pip.py](https://bootstrap.pypa.io/get-pip.py) or use following cURL command to download it: - - ```sh - curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py - ``` - - - After dowloading, run the file : - - - For Python 3 - - ```sh - python3 get-pip.py - ``` - - - For Python 2 - - ```sh - python2 get-pip.py - ``` - ### Install the dependencies To install the dependencies, run the following command in project's base directory: From 311d29a2d0b9d0c9a158e7d1885f759f079107af Mon Sep 17 00:00:00 2001 From: princebaretto99 Date: Tue, 1 Nov 2022 23:25:57 +0530 Subject: [PATCH 07/22] Updated README --- README.md | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3c82550..86c3186 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ To install the dependencies, run the following command in project's base directo - For Python 2 ```sh - pip2 install -r requirements.txt + pip install -r requirements.txt ``` ## Getting Started @@ -55,9 +55,7 @@ Open `single.json`/`parallel.json` file in `config` folder : - Replace `bs://` wkth the URL obtained from app upload step -- Set the deviceName and platformVersion - -- If you have uploaded your own app update the test case +- Set the deviceName and platformVersion. You can refer our [Capability Generator](https://www.browserstack.com/app-automate/capabilities) - Run the below command to execute a single test on BrowserStack AppAutomate: ``` @@ -98,12 +96,10 @@ Open `local.json` file in `conifg` folder : - Replace `bs://` wkth the URL obtained from app upload step -- Set the deviceName and platformVersion +- Set the deviceName and platformVersion. You can refer our [Capability Generator](https://www.browserstack.com/app-automate/capabilities) - Ensure that `local` capability is set to `true`. The `conftest.py` contains the code snippet that automatically establishes Local Testing connection to BrowserStack servers using Python binding for BrowserStack Local. -- If you have uploaded your own app update the test case. The test cases for Local Tests are present [here](tests/local_tests/local_sample.py) - - Run the below command: ``` paver run local From 21d94fc1b3d8fb9dc9007de8b0c4618413eb9496 Mon Sep 17 00:00:00 2001 From: princebaretto99 Date: Wed, 2 Nov 2022 16:10:02 +0530 Subject: [PATCH 08/22] Added Tests --- .DS_Store | Bin 0 -> 6148 bytes tests/test_sample_1.py | 4 ++-- tests/test_sample_2.py | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 .DS_Store create mode 100644 tests/test_sample_2.py diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ba345a2aa5f5fcc5141981b96bf30c5244385b45 GIT binary patch literal 6148 zcmeHKy-veG47N)_K`b2^Z(}Y4bEv`-^aW6VD3uygsW7qJ$cwP?7=0}yKA)}9kV8zM z3fYqVU3~WC@?8|iM8u<~*^p>JLg#bVvE~Yt7e9RZUjS1bM~V_TuXDWqbW~jk=lr7_+|byeG%>NORi2ZZdDt z-t7J!-k)FRwue^4=MM4_nfo8&`S_lk0cXG&_zeb7vqg$CMYqm?GvEyD7?AHnfC`p| zQ89fwU{VVJ?8BV|W9cO%Cm5E7Q4uo`)>NRTvb7kj>F@`OD-ENfrW0H9!FFf14u#X* zv3^M5#HFHJXTTX~GjODr1F8Qv-}nFRB)@V7oPmGE0QakLHNqoVZS6dq)Y<^Og^EaA lRNSRtkV-LPr4*k-lfWNj04xooB0LcP5lA$+aR&aBfe-fGNihHb literal 0 HcmV?d00001 diff --git a/tests/test_sample_1.py b/tests/test_sample_1.py index d263e29..a6bc74c 100644 --- a/tests/test_sample_1.py +++ b/tests/test_sample_1.py @@ -25,10 +25,10 @@ def test_example(self): time.sleep(5) search_results = self.driver.find_elements( AppiumBy.CLASS_NAME, "android.widget.TextView") - # checking whether product has been added to cart by comparing product name and marking test pass or fail + if(len(search_results) > 0): self.driver.execute_script( 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test Passed Successfully"}}') else: self.driver.execute_script( - 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Product added to the cart not same as selected"}}') + 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Test Failed"}}') diff --git a/tests/test_sample_2.py b/tests/test_sample_2.py new file mode 100644 index 0000000..6001956 --- /dev/null +++ b/tests/test_sample_2.py @@ -0,0 +1,34 @@ +from browserstack.local import Local +from appium import webdriver +from appium.webdriver.common.appiumby import AppiumBy +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +import time +import pytest +from selenium.webdriver.common.by import By + +@pytest.mark.usefixtures('setWebdriver') +class TestSample: + + def test_example(self): + search_element = WebDriverWait(self.driver, 30).until( + EC.element_to_be_clickable( + (AppiumBy.ACCESSIBILITY_ID, "Search Wikipedia")) + ) + + search_element.click() + search_input = WebDriverWait(self.driver, 30).until( + EC.element_to_be_clickable( + (AppiumBy.ID, "org.wikipedia.alpha:id/search_src_text")) + ) + search_input.send_keys("Browser Testing") + time.sleep(5) + search_results = self.driver.find_elements( + AppiumBy.CLASS_NAME, "android.widget.TextView") + + if(len(search_results) > 0): + self.driver.execute_script( + 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test Passed Successfully"}}') + else: + self.driver.execute_script( + 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Test Failed"}}') From d2b6879a62d0b058ab55297e24e61014de5dbe59 Mon Sep 17 00:00:00 2001 From: princebaretto99 Date: Thu, 17 Nov 2022 02:18:54 +0530 Subject: [PATCH 09/22] Updated format --- README.md | 46 ++++++++++++--- conftest.py => android/conftest.py | 0 android/pavement.py | 36 ++++++++++++ {config => android/run-local-test}/local.json | 2 +- .../run-local-test/tests}/local_sample.py | 0 .../run-parallel-test}/parallel.json | 4 +- .../run-parallel-test/tests}/test_sample_1.py | 0 .../run-parallel-test/tests}/test_sample_2.py | 0 .../run-single-test}/single.json | 4 +- .../run-single-test/tests/test_sample_1.py | 34 +++++++++++ ios/conftest.py | 58 +++++++++++++++++++ pavement.py => ios/pavement.py | 8 +-- ios/run-local-test/local.json | 22 +++++++ ios/run-local-test/tests/local_sample.py | 35 +++++++++++ ios/run-parallel-test/parallel.json | 27 +++++++++ ios/run-parallel-test/tests/test_sample_1.py | 32 ++++++++++ ios/run-parallel-test/tests/test_sample_2.py | 32 ++++++++++ ios/run-single-test/single.json | 22 +++++++ ios/run-single-test/tests/test_sample_1.py | 32 ++++++++++ 19 files changed, 378 insertions(+), 16 deletions(-) rename conftest.py => android/conftest.py (100%) create mode 100644 android/pavement.py rename {config => android/run-local-test}/local.json (90%) rename {tests/local_tests => android/run-local-test/tests}/local_sample.py (100%) rename {config => android/run-parallel-test}/parallel.json (84%) rename {tests => android/run-parallel-test/tests}/test_sample_1.py (100%) rename {tests => android/run-parallel-test/tests}/test_sample_2.py (100%) rename {config => android/run-single-test}/single.json (80%) create mode 100644 android/run-single-test/tests/test_sample_1.py create mode 100644 ios/conftest.py rename pavement.py => ios/pavement.py (84%) create mode 100644 ios/run-local-test/local.json create mode 100644 ios/run-local-test/tests/local_sample.py create mode 100644 ios/run-parallel-test/parallel.json create mode 100644 ios/run-parallel-test/tests/test_sample_1.py create mode 100644 ios/run-parallel-test/tests/test_sample_2.py create mode 100644 ios/run-single-test/single.json create mode 100644 ios/run-single-test/tests/test_sample_1.py diff --git a/README.md b/README.md index 86c3186..efd4edd 100644 --- a/README.md +++ b/README.md @@ -47,9 +47,9 @@ Ensure that @ symbol is prepended to the file path in the above request. Please **Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android app](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) or [sample iOS app](https://www.browserstack.com/app-automate/sample-apps/ios/BStackSampleApp.ipa). -**2. Configure and run your first test** +**2. Configure and run your first single test** -Open `single.json`/`parallel.json` file in `config` folder : +Open `single.json` file in `android/run-single-test` folder for Android and `ios/run-single-test` folder for iOS: - Replace `BROWSERSTACK_USERNAME` & `BROWSERSTACK_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings) @@ -57,16 +57,40 @@ Open `single.json`/`parallel.json` file in `config` folder : - Set the deviceName and platformVersion. You can refer our [Capability Generator](https://www.browserstack.com/app-automate/capabilities) -- Run the below command to execute a single test on BrowserStack AppAutomate: +- Run the below command to execute a single Android test on BrowserStack AppAutomate: ``` + cd android paver run single ``` -- In order to run tests in parallel across different configurations mentioned in the [`parallel.json`](config/parallel.json) file, run the below command +- Run the below command to execute a single iOS test on BrowserStack AppAutomate: ``` - paver run parallel + cd ios + paver run single ``` +**3. Configure and run your parallel test** + +- In order to run tests in parallel across different configurations, Open `parallel.json` file in `android/run-parallel-test` folder for Android and `ios/run-parallel-test` folder for iOS + +- Replace `BROWSERSTACK_USERNAME` & `BROWSERSTACK_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings) + +- Replace `bs://` wkth the URL obtained from app upload step + +- Set the deviceName and platformVersion. You can refer our [Capability Generator](https://www.browserstack.com/app-automate/capabilities) + +- Run the below command to execute a single Android test on BrowserStack AppAutomate: +``` +cd android +paver run parallel +``` + +- Run the below command to execute a single iOS test on BrowserStack AppAutomate: +``` +cd ios +paver run parallel +``` + - You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard) --- @@ -90,7 +114,8 @@ Ensure that @ symbol is prepended to the file path in the above request. Please **2. Configure and run your local test** -Open `local.json` file in `conifg` folder : +Open `local.json` file in `android/run-local-test` folder for Android and `ios/run-local-test` folder for iOS: + - Replace `BROWSERSTACK_USERNAME` & `BROWSERSTACK_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings) @@ -100,8 +125,15 @@ Open `local.json` file in `conifg` folder : - Ensure that `local` capability is set to `true`. The `conftest.py` contains the code snippet that automatically establishes Local Testing connection to BrowserStack servers using Python binding for BrowserStack Local. -- Run the below command: +- Run the below command for Android: + ``` + cd android + paver run local + ``` + +- Run the below command for iOS: ``` + cd ios paver run local ``` diff --git a/conftest.py b/android/conftest.py similarity index 100% rename from conftest.py rename to android/conftest.py diff --git a/android/pavement.py b/android/pavement.py new file mode 100644 index 0000000..14794fa --- /dev/null +++ b/android/pavement.py @@ -0,0 +1,36 @@ +from paver.easy import * +from paver.setuputils import setup +from multiprocess import Process +import platform +import json + +def run_py_test(config, task_id=0): + if platform.system() == "Windows": + if(config=="local"): + sh('cmd /C "set CONFIG_FILE=run-local-test/%s.json && set TASK_ID=%s && pytest -s run-local-test/tests/*.py"' % (config, task_id)) + elif(config == "parallel"): + sh('cmd /C "set CONFIG_FILE=run-parallel-test/%s.json && set TASK_ID=%s && pytest -s run-parallel-test/tests/*.py -n 2"' % (config, task_id)) + else: + sh('cmd /C "set CONFIG_FILE=run-single-test/%s.json && set TASK_ID=%s && pytest -s run-single-test/tests/*.py"' % (config, task_id)) + + else: + if(config=="local"): + sh('CONFIG_FILE=run-local-test/%s.json TASK_ID=%s pytest -s run-local-test/tests/*.py' % (config, task_id)) + elif(config == "parallel"): + sh('CONFIG_FILE=run-parallel-test/%s.json TASK_ID=%s pytest -s run-parallel-test/tests/*.py -n 2' % (config, task_id)) + else: + sh('CONFIG_FILE=run-single-test/%s.json TASK_ID=%s pytest -s run-single-test/tests/*.py' % (config, task_id)) + +@task +@consume_nargs(1) +def run(args): + """Run single, local and parallel test using different config.""" + jobs = [] + config_file = 'run-%s-test/%s.json' % (args[0], 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], i)) + jobs.append(p) + p.start() diff --git a/config/local.json b/android/run-local-test/local.json similarity index 90% rename from config/local.json rename to android/run-local-test/local.json index 73fb23d..5f26f97 100644 --- a/config/local.json +++ b/android/run-local-test/local.json @@ -5,7 +5,7 @@ "app" : "bs://", "bstack:options": { "projectName": "Pytest Browserstack", - "buildName": "browserstack-build-1", + "buildName": "browserstack-build-android", "sessionName": "BStack sample pytest", "local": "true", "debug": "true", diff --git a/tests/local_tests/local_sample.py b/android/run-local-test/tests/local_sample.py similarity index 100% rename from tests/local_tests/local_sample.py rename to android/run-local-test/tests/local_sample.py diff --git a/config/parallel.json b/android/run-parallel-test/parallel.json similarity index 84% rename from config/parallel.json rename to android/run-parallel-test/parallel.json index 1dc3c1f..722d64c 100644 --- a/config/parallel.json +++ b/android/run-parallel-test/parallel.json @@ -2,10 +2,10 @@ "user": "BROWSERSTACK_USERNAME", "key": "BROWSERSTACK_ACCESS_KEY", "capabilities": { - "app" : "bs://", + "app" : "bs://d83aa0e9b284055bf70c906239301a579b6143c4", "bstack:options": { "projectName": "Pytest Browserstack", - "buildName": "browserstack-build-1", + "buildName": "browserstack-build-android", "sessionName": "BStack sample pytest", "local": false, "debug": "true", diff --git a/tests/test_sample_1.py b/android/run-parallel-test/tests/test_sample_1.py similarity index 100% rename from tests/test_sample_1.py rename to android/run-parallel-test/tests/test_sample_1.py diff --git a/tests/test_sample_2.py b/android/run-parallel-test/tests/test_sample_2.py similarity index 100% rename from tests/test_sample_2.py rename to android/run-parallel-test/tests/test_sample_2.py diff --git a/config/single.json b/android/run-single-test/single.json similarity index 80% rename from config/single.json rename to android/run-single-test/single.json index 0be18b2..198d98b 100644 --- a/config/single.json +++ b/android/run-single-test/single.json @@ -2,10 +2,10 @@ "user": "BROWSERSTACK_USERNAME", "key": "BROWSERSTACK_ACCESS_KEY", "capabilities": { - "app" : "bs://", + "app" : "bs://d83aa0e9b284055bf70c906239301a579b6143c4", "bstack:options": { "projectName": "Pytest Browserstack", - "buildName": "browserstack-build-1", + "buildName": "browserstack-build-android", "sessionName": "BStack sample pytest", "local": false, "debug": "true", diff --git a/android/run-single-test/tests/test_sample_1.py b/android/run-single-test/tests/test_sample_1.py new file mode 100644 index 0000000..a6bc74c --- /dev/null +++ b/android/run-single-test/tests/test_sample_1.py @@ -0,0 +1,34 @@ +from browserstack.local import Local +from appium import webdriver +from appium.webdriver.common.appiumby import AppiumBy +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +import time +import pytest +from selenium.webdriver.common.by import By + +@pytest.mark.usefixtures('setWebdriver') +class TestSample: + + def test_example(self): + search_element = WebDriverWait(self.driver, 30).until( + EC.element_to_be_clickable( + (AppiumBy.ACCESSIBILITY_ID, "Search Wikipedia")) + ) + + search_element.click() + search_input = WebDriverWait(self.driver, 30).until( + EC.element_to_be_clickable( + (AppiumBy.ID, "org.wikipedia.alpha:id/search_src_text")) + ) + search_input.send_keys("BrowserStack") + time.sleep(5) + search_results = self.driver.find_elements( + AppiumBy.CLASS_NAME, "android.widget.TextView") + + if(len(search_results) > 0): + self.driver.execute_script( + 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test Passed Successfully"}}') + else: + self.driver.execute_script( + 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Test Failed"}}') diff --git a/ios/conftest.py b/ios/conftest.py new file mode 100644 index 0000000..7102bbe --- /dev/null +++ b/ios/conftest.py @@ -0,0 +1,58 @@ +import pytest +from browserstack.local import Local +import os +from appium import webdriver +import json +from jsonmerge import merge +CONFIG_FILE = os.environ['CONFIG_FILE'] if 'CONFIG_FILE' in os.environ else 'config/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 + +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 + bs_local = Local() + bs_local_args = { + "key": BROWSERSTACK_ACCESS_KEY or "access_key", "forcelocal": "true"} + 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() + + +@pytest.fixture(scope='session') +def session_capabilities(): + capabilities = merge(CONFIG['environments'] + [TASK_ID], CONFIG["capabilities"]) + capabilities['bstack:options']['userName'] = BROWSERSTACK_USERNAME + capabilities['bstack:options']['accessKey'] = BROWSERSTACK_ACCESS_KEY + if "local" in capabilities['bstack:options'] and capabilities['bstack:options']['local']: + start_local() + return capabilities + + +@pytest.fixture(scope='function') +def setWebdriver(request, session_capabilities): + remoteURL = "https://hub-cloud.browserstack.com/wd/hub" + driver = webdriver.Remote(remoteURL, session_capabilities) + request.cls.driver = driver + + yield driver + + driver.quit() + + +def pytest_sessionfinish(session, exitstatus): + stop_local() diff --git a/pavement.py b/ios/pavement.py similarity index 84% rename from pavement.py rename to ios/pavement.py index 1b29c04..b85bbd7 100644 --- a/pavement.py +++ b/ios/pavement.py @@ -9,17 +9,17 @@ def run_py_test(config, task_id=0): if(config=="local"): sh('cmd /C "set CONFIG_FILE=config/%s.json && set TASK_ID=%s && pytest -s tests/local_tests/*.py"' % (config, task_id)) elif(config == "parallel"): - sh('cmd /C "set CONFIG_FILE=config/%s.json && set TASK_ID=%s && pytest -s tests/*.py -n 2"' % (config, task_id)) + sh('cmd /C "set CONFIG_FILE=config/%s.json && set TASK_ID=%s && pytest -s tests/parallel_tests/*.py -n 2"' % (config, task_id)) else: - sh('cmd /C "set CONFIG_FILE=config/%s.json && set TASK_ID=%s && pytest -s tests/*.py"' % (config, task_id)) + sh('cmd /C "set CONFIG_FILE=config/%s.json && set TASK_ID=%s && pytest -s tests/single_tests/*.py"' % (config, task_id)) else: if(config=="local"): sh('CONFIG_FILE=config/%s.json TASK_ID=%s pytest -s tests/local_tests/*.py' % (config, task_id)) elif(config == "parallel"): - sh('CONFIG_FILE=config/%s.json TASK_ID=%s pytest -s tests/*.py -n 2' % (config, task_id)) + sh('CONFIG_FILE=config/%s.json TASK_ID=%s pytest -s tests/parallel_tests/*.py -n 2' % (config, task_id)) else: - sh('CONFIG_FILE=config/%s.json TASK_ID=%s pytest -s tests/*.py' % (config, task_id)) + sh('CONFIG_FILE=config/%s.json TASK_ID=%s pytest -s tests/single_tests/*.py' % (config, task_id)) @task @consume_nargs(1) diff --git a/ios/run-local-test/local.json b/ios/run-local-test/local.json new file mode 100644 index 0000000..9ffaa12 --- /dev/null +++ b/ios/run-local-test/local.json @@ -0,0 +1,22 @@ +{ + "user": "BROWSERSTACK_USERNAME", + "key": "BROWSERSTACK_ACCESS_KEY", + "capabilities": { + "app" : "bs://", + "bstack:options": { + "projectName": "Pytest Browserstack", + "buildName": "browserstack-build-ios", + "sessionName": "BStack sample pytest", + "local": "true", + "debug": "true", + "networkLogs": "true" + } + }, + "environments": [ + { + "platformName": "ios", + "platformVersion": "16", + "deviceName": "iPhone 14" + } + ] +} \ No newline at end of file diff --git a/ios/run-local-test/tests/local_sample.py b/ios/run-local-test/tests/local_sample.py new file mode 100644 index 0000000..058d332 --- /dev/null +++ b/ios/run-local-test/tests/local_sample.py @@ -0,0 +1,35 @@ +from browserstack.local import Local +from appium import webdriver +from appium.webdriver.common.appiumby import AppiumBy +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +import time +import pytest +from selenium.webdriver.common.by import By + + +@pytest.mark.usefixtures('getWebdriver') +class TestSample: + + def test_example(self): + + def existence_lambda(s): + result = s.find_element(AppiumBy.ACCESSIBILITY_ID, "ResultBrowserStackLocal").get_attribute("value") + return result and len(result) > 0 + + test_button = WebDriverWait(self.driver, 30).until( + EC.element_to_be_clickable((AppiumBy.ACCESSIBILITY_ID, "TestBrowserStackLocal")) + ) + test_button.click() + WebDriverWait(self.driver, 30).until(existence_lambda) + + time.sleep(5) + result_element = self.driver.find_element(AppiumBy.ACCESSIBILITY_ID, "ResultBrowserStackLocal") + result_string = result_element.text.lower() + if result_string.__contains__("up and running"): + self.driver.execute_script( + 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Test failed"}}') + else: + self.driver.execute_script( + 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test Passed"}}') + \ No newline at end of file diff --git a/ios/run-parallel-test/parallel.json b/ios/run-parallel-test/parallel.json new file mode 100644 index 0000000..cf1838f --- /dev/null +++ b/ios/run-parallel-test/parallel.json @@ -0,0 +1,27 @@ +{ + "user": "BROWSERSTACK_USERNAME", + "key": "BROWSERSTACK_ACCESS_KEY", + "capabilities": { + "app" : "IOSSampleApp", + "bstack:options": { + "projectName": "Pytest Browserstack", + "buildName": "browserstack-build-ios", + "sessionName": "BStack sample pytest", + "local": false, + "debug": "true", + "networkLogs": "true" + } + }, + "environments": [ + { + "platformName": "ios", + "platformVersion": "16", + "deviceName": "iPhone 14" + }, + { + "platformName": "ios", + "platformVersion": "15", + "deviceName": "iPhone 11" + } + ] +} \ No newline at end of file diff --git a/ios/run-parallel-test/tests/test_sample_1.py b/ios/run-parallel-test/tests/test_sample_1.py new file mode 100644 index 0000000..b08e5b2 --- /dev/null +++ b/ios/run-parallel-test/tests/test_sample_1.py @@ -0,0 +1,32 @@ +from browserstack.local import Local +from appium import webdriver +from appium.webdriver.common.appiumby import AppiumBy +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +import time +import pytest +from selenium.webdriver.common.by import By + +@pytest.mark.usefixtures('setWebdriver') +class TestSample: + + def test_example(self): + text_button = WebDriverWait(self.driver, 30).until( + EC.element_to_be_clickable((AppiumBy.ACCESSIBILITY_ID, "Text Button")) + ) + text_button.click() + text_input = WebDriverWait(self.driver, 30).until( + EC.element_to_be_clickable((AppiumBy.ACCESSIBILITY_ID, "Text Input")) + ) + text_input.send_keys("hello@browserstack.com"+"\n") + time.sleep(5) + text_output = WebDriverWait(self.driver, 30).until( + EC.element_to_be_clickable((AppiumBy.ACCESSIBILITY_ID, "Text Output")) + ) + + if(text_output!=None and text_output.text=="hello@browserstack.com"): + self.driver.execute_script( + 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test Passed Successfully"}}') + else: + self.driver.execute_script( + 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Test Failed"}}') diff --git a/ios/run-parallel-test/tests/test_sample_2.py b/ios/run-parallel-test/tests/test_sample_2.py new file mode 100644 index 0000000..825385d --- /dev/null +++ b/ios/run-parallel-test/tests/test_sample_2.py @@ -0,0 +1,32 @@ +from browserstack.local import Local +from appium import webdriver +from appium.webdriver.common.appiumby import AppiumBy +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +import time +import pytest +from selenium.webdriver.common.by import By + +@pytest.mark.usefixtures('setWebdriver') +class TestSample: + + def test_example(self): + text_button = WebDriverWait(self.driver, 30).until( + EC.element_to_be_clickable((AppiumBy.ACCESSIBILITY_ID, "Text Button")) + ) + text_button.click() + text_input = WebDriverWait(self.driver, 30).until( + EC.element_to_be_clickable((AppiumBy.ACCESSIBILITY_ID, "Text Input")) + ) + text_input.send_keys("helloworld@browserstack.com"+"\n") + time.sleep(5) + text_output = WebDriverWait(self.driver, 30).until( + EC.element_to_be_clickable((AppiumBy.ACCESSIBILITY_ID, "Text Output")) + ) + + if(text_output!=None and text_output.text=="helloworld@browserstack.com"): + self.driver.execute_script( + 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test Passed Successfully"}}') + else: + self.driver.execute_script( + 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Test Failed"}}') diff --git a/ios/run-single-test/single.json b/ios/run-single-test/single.json new file mode 100644 index 0000000..331f774 --- /dev/null +++ b/ios/run-single-test/single.json @@ -0,0 +1,22 @@ +{ + "user": "BROWSERSTACK_USERNAME", + "key": "BROWSERSTACK_ACCESS_KEY", + "capabilities": { + "app" : "IOSSampleApp", + "bstack:options": { + "projectName": "Pytest Browserstack", + "buildName": "browserstack-build-ios", + "sessionName": "BStack sample pytest", + "local": false, + "debug": "true", + "networkLogs": "true" + } + }, + "environments": [ + { + "platformName": "ios", + "platformVersion": "16", + "deviceName": "iPhone 14" + } + ] +} \ No newline at end of file diff --git a/ios/run-single-test/tests/test_sample_1.py b/ios/run-single-test/tests/test_sample_1.py new file mode 100644 index 0000000..b08e5b2 --- /dev/null +++ b/ios/run-single-test/tests/test_sample_1.py @@ -0,0 +1,32 @@ +from browserstack.local import Local +from appium import webdriver +from appium.webdriver.common.appiumby import AppiumBy +from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC +import time +import pytest +from selenium.webdriver.common.by import By + +@pytest.mark.usefixtures('setWebdriver') +class TestSample: + + def test_example(self): + text_button = WebDriverWait(self.driver, 30).until( + EC.element_to_be_clickable((AppiumBy.ACCESSIBILITY_ID, "Text Button")) + ) + text_button.click() + text_input = WebDriverWait(self.driver, 30).until( + EC.element_to_be_clickable((AppiumBy.ACCESSIBILITY_ID, "Text Input")) + ) + text_input.send_keys("hello@browserstack.com"+"\n") + time.sleep(5) + text_output = WebDriverWait(self.driver, 30).until( + EC.element_to_be_clickable((AppiumBy.ACCESSIBILITY_ID, "Text Output")) + ) + + if(text_output!=None and text_output.text=="hello@browserstack.com"): + self.driver.execute_script( + 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test Passed Successfully"}}') + else: + self.driver.execute_script( + 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Test Failed"}}') From 614eef392e78b8c288099d811760d6eb6b389944 Mon Sep 17 00:00:00 2001 From: Princeton Baretto <43331485+princebaretto99@users.noreply.github.com> Date: Thu, 17 Nov 2022 02:19:52 +0530 Subject: [PATCH 10/22] Delete .DS_Store --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index ba345a2aa5f5fcc5141981b96bf30c5244385b45..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKy-veG47N)_K`b2^Z(}Y4bEv`-^aW6VD3uygsW7qJ$cwP?7=0}yKA)}9kV8zM z3fYqVU3~WC@?8|iM8u<~*^p>JLg#bVvE~Yt7e9RZUjS1bM~V_TuXDWqbW~jk=lr7_+|byeG%>NORi2ZZdDt z-t7J!-k)FRwue^4=MM4_nfo8&`S_lk0cXG&_zeb7vqg$CMYqm?GvEyD7?AHnfC`p| zQ89fwU{VVJ?8BV|W9cO%Cm5E7Q4uo`)>NRTvb7kj>F@`OD-ENfrW0H9!FFf14u#X* zv3^M5#HFHJXTTX~GjODr1F8Qv-}nFRB)@V7oPmGE0QakLHNqoVZS6dq)Y<^Og^EaA lRNSRtkV-LPr4*k-lfWNj04xooB0LcP5lA$+aR&aBfe-fGNihHb From c6cea227730b8f474372c51cf41c233c4d95bef0 Mon Sep 17 00:00:00 2001 From: princebaretto99 Date: Thu, 17 Nov 2022 18:10:43 +0530 Subject: [PATCH 11/22] Fixed local ios bug --- android/run-local-test/tests/local_sample.py | 2 +- ios/pavement.py | 14 +++++++------- ios/run-local-test/tests/local_sample.py | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/android/run-local-test/tests/local_sample.py b/android/run-local-test/tests/local_sample.py index 41f6cc6..db0dbbe 100644 --- a/android/run-local-test/tests/local_sample.py +++ b/android/run-local-test/tests/local_sample.py @@ -8,7 +8,7 @@ from selenium.webdriver.common.by import By -@pytest.mark.usefixtures('getWebdriver') +@pytest.mark.usefixtures('setWebdriver') class TestSample: def test_example(self): diff --git a/ios/pavement.py b/ios/pavement.py index b85bbd7..14794fa 100644 --- a/ios/pavement.py +++ b/ios/pavement.py @@ -7,26 +7,26 @@ def run_py_test(config, task_id=0): if platform.system() == "Windows": if(config=="local"): - sh('cmd /C "set CONFIG_FILE=config/%s.json && set TASK_ID=%s && pytest -s tests/local_tests/*.py"' % (config, task_id)) + sh('cmd /C "set CONFIG_FILE=run-local-test/%s.json && set TASK_ID=%s && pytest -s run-local-test/tests/*.py"' % (config, task_id)) elif(config == "parallel"): - sh('cmd /C "set CONFIG_FILE=config/%s.json && set TASK_ID=%s && pytest -s tests/parallel_tests/*.py -n 2"' % (config, task_id)) + sh('cmd /C "set CONFIG_FILE=run-parallel-test/%s.json && set TASK_ID=%s && pytest -s run-parallel-test/tests/*.py -n 2"' % (config, task_id)) else: - sh('cmd /C "set CONFIG_FILE=config/%s.json && set TASK_ID=%s && pytest -s tests/single_tests/*.py"' % (config, task_id)) + sh('cmd /C "set CONFIG_FILE=run-single-test/%s.json && set TASK_ID=%s && pytest -s run-single-test/tests/*.py"' % (config, task_id)) else: if(config=="local"): - sh('CONFIG_FILE=config/%s.json TASK_ID=%s pytest -s tests/local_tests/*.py' % (config, task_id)) + sh('CONFIG_FILE=run-local-test/%s.json TASK_ID=%s pytest -s run-local-test/tests/*.py' % (config, task_id)) elif(config == "parallel"): - sh('CONFIG_FILE=config/%s.json TASK_ID=%s pytest -s tests/parallel_tests/*.py -n 2' % (config, task_id)) + sh('CONFIG_FILE=run-parallel-test/%s.json TASK_ID=%s pytest -s run-parallel-test/tests/*.py -n 2' % (config, task_id)) else: - sh('CONFIG_FILE=config/%s.json TASK_ID=%s pytest -s tests/single_tests/*.py' % (config, task_id)) + sh('CONFIG_FILE=run-single-test/%s.json TASK_ID=%s pytest -s run-single-test/tests/*.py' % (config, task_id)) @task @consume_nargs(1) def run(args): """Run single, local and parallel test using different config.""" jobs = [] - config_file = 'config/%s.json' % (args[0]) + config_file = 'run-%s-test/%s.json' % (args[0], args[0]) with open(config_file) as data_file: CONFIG = json.load(data_file) environments = CONFIG['environments'] diff --git a/ios/run-local-test/tests/local_sample.py b/ios/run-local-test/tests/local_sample.py index 058d332..f489154 100644 --- a/ios/run-local-test/tests/local_sample.py +++ b/ios/run-local-test/tests/local_sample.py @@ -8,7 +8,7 @@ from selenium.webdriver.common.by import By -@pytest.mark.usefixtures('getWebdriver') +@pytest.mark.usefixtures('setWebdriver') class TestSample: def test_example(self): @@ -28,8 +28,8 @@ def existence_lambda(s): result_string = result_element.text.lower() if result_string.__contains__("up and running"): self.driver.execute_script( - 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Test failed"}}') + 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test passed"}}') else: self.driver.execute_script( - 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test Passed"}}') + 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Test failed"}}') \ No newline at end of file From d9cea5b5affd2567fb7434acfd61f997698a094f Mon Sep 17 00:00:00 2001 From: princebaretto99 Date: Thu, 17 Nov 2022 18:12:55 +0530 Subject: [PATCH 12/22] Fixed changes --- .gitignore | 2 +- android/run-local-test/local.json | 2 +- android/run-parallel-test/parallel.json | 2 +- android/run-single-test/single.json | 2 +- ios/run-local-test/local.json | 2 +- ios/run-parallel-test/parallel.json | 2 +- ios/run-single-test/single.json | 2 +- requirements.txt | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 6c8ee20..4642597 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ __pycache__ .pytest_cache local.log -testSele \ No newline at end of file +testSele diff --git a/android/run-local-test/local.json b/android/run-local-test/local.json index 5f26f97..57e1bf6 100644 --- a/android/run-local-test/local.json +++ b/android/run-local-test/local.json @@ -19,4 +19,4 @@ "deviceName": "Google Pixel 3" } ] -} \ No newline at end of file +} diff --git a/android/run-parallel-test/parallel.json b/android/run-parallel-test/parallel.json index 722d64c..adfa297 100644 --- a/android/run-parallel-test/parallel.json +++ b/android/run-parallel-test/parallel.json @@ -24,4 +24,4 @@ "deviceName": "Samsung Galaxy A52" } ] -} \ No newline at end of file +} diff --git a/android/run-single-test/single.json b/android/run-single-test/single.json index 198d98b..98eb87c 100644 --- a/android/run-single-test/single.json +++ b/android/run-single-test/single.json @@ -19,4 +19,4 @@ "deviceName": "Google Pixel 3" } ] -} \ No newline at end of file +} diff --git a/ios/run-local-test/local.json b/ios/run-local-test/local.json index 9ffaa12..5ba9b5e 100644 --- a/ios/run-local-test/local.json +++ b/ios/run-local-test/local.json @@ -19,4 +19,4 @@ "deviceName": "iPhone 14" } ] -} \ No newline at end of file +} diff --git a/ios/run-parallel-test/parallel.json b/ios/run-parallel-test/parallel.json index cf1838f..08db95e 100644 --- a/ios/run-parallel-test/parallel.json +++ b/ios/run-parallel-test/parallel.json @@ -24,4 +24,4 @@ "deviceName": "iPhone 11" } ] -} \ No newline at end of file +} diff --git a/ios/run-single-test/single.json b/ios/run-single-test/single.json index 331f774..072d22e 100644 --- a/ios/run-single-test/single.json +++ b/ios/run-single-test/single.json @@ -19,4 +19,4 @@ "deviceName": "iPhone 14" } ] -} \ No newline at end of file +} diff --git a/requirements.txt b/requirements.txt index e177fe3..43d2d01 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,4 @@ pytest pytest-variables pytest-selenium pytest-xdist -Appium-Python-Client \ No newline at end of file +Appium-Python-Client From d88bd9d405dbef17d2b4ead918e615d6875266ce Mon Sep 17 00:00:00 2001 From: Princeton Baretto <43331485+princebaretto99@users.noreply.github.com> Date: Thu, 17 Nov 2022 18:28:32 +0530 Subject: [PATCH 13/22] Update README.md Co-authored-by: Avinash Bharti <90600575+avinash-bharti@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index efd4edd..8724f81 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Open `single.json` file in `android/run-single-test` folder for Android and `ios - Replace `BROWSERSTACK_USERNAME` & `BROWSERSTACK_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings) -- Replace `bs://` wkth the URL obtained from app upload step +- Replace `bs://` with the URL obtained from app upload step - Set the deviceName and platformVersion. You can refer our [Capability Generator](https://www.browserstack.com/app-automate/capabilities) From 15999d57fe9afcb92654304442b9c109840ce1bf Mon Sep 17 00:00:00 2001 From: Princeton Baretto <43331485+princebaretto99@users.noreply.github.com> Date: Thu, 17 Nov 2022 20:28:13 +0530 Subject: [PATCH 14/22] Update README.md Co-authored-by: Avinash Bharti <90600575+avinash-bharti@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8724f81..7d4a715 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ cd android paver run parallel ``` -- Run the below command to execute a single iOS test on BrowserStack AppAutomate: +- Run the below command to execute a parallel iOS test on BrowserStack AppAutomate: ``` cd ios paver run parallel From e22e764cf3c0052825667c1d526e43ec55d2ee95 Mon Sep 17 00:00:00 2001 From: Princeton Baretto <43331485+princebaretto99@users.noreply.github.com> Date: Thu, 17 Nov 2022 20:28:23 +0530 Subject: [PATCH 15/22] Update README.md Co-authored-by: Avinash Bharti <90600575+avinash-bharti@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7d4a715..7d9da37 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ Open `single.json` file in `android/run-single-test` folder for Android and `ios - Set the deviceName and platformVersion. You can refer our [Capability Generator](https://www.browserstack.com/app-automate/capabilities) -- Run the below command to execute a single Android test on BrowserStack AppAutomate: +- Run the below command to execute parallel Android test on BrowserStack AppAutomate: ``` cd android paver run parallel From 6d621e75807116558417d4f4629510c8f3f8464c Mon Sep 17 00:00:00 2001 From: princebaretto99 Date: Thu, 17 Nov 2022 20:29:15 +0530 Subject: [PATCH 16/22] Fixed conftest files --- android/conftest.py | 2 +- ios/conftest.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/android/conftest.py b/android/conftest.py index 7102bbe..ffa596b 100644 --- a/android/conftest.py +++ b/android/conftest.py @@ -4,7 +4,7 @@ from appium import webdriver import json from jsonmerge import merge -CONFIG_FILE = os.environ['CONFIG_FILE'] if 'CONFIG_FILE' in os.environ else 'config/single.json' +CONFIG_FILE = os.environ['CONFIG_FILE'] if 'CONFIG_FILE' in os.environ else 'run-single-test/single.json' TASK_ID = int(os.environ['TASK_ID']) if 'TASK_ID' in os.environ else 0 with open(CONFIG_FILE) as data_file: diff --git a/ios/conftest.py b/ios/conftest.py index 7102bbe..ffa596b 100644 --- a/ios/conftest.py +++ b/ios/conftest.py @@ -4,7 +4,7 @@ from appium import webdriver import json from jsonmerge import merge -CONFIG_FILE = os.environ['CONFIG_FILE'] if 'CONFIG_FILE' in os.environ else 'config/single.json' +CONFIG_FILE = os.environ['CONFIG_FILE'] if 'CONFIG_FILE' in os.environ else 'run-single-test/single.json' TASK_ID = int(os.environ['TASK_ID']) if 'TASK_ID' in os.environ else 0 with open(CONFIG_FILE) as data_file: From a67795c7eb31f11b36fb190a38984223acf859c7 Mon Sep 17 00:00:00 2001 From: Princeton Baretto <43331485+princebaretto99@users.noreply.github.com> Date: Thu, 17 Nov 2022 23:55:10 +0530 Subject: [PATCH 17/22] Update android/conftest.py Co-authored-by: Avinash Bharti <90600575+avinash-bharti@users.noreply.github.com> --- android/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/conftest.py b/android/conftest.py index ffa596b..7e0b62f 100644 --- a/android/conftest.py +++ b/android/conftest.py @@ -45,7 +45,7 @@ def session_capabilities(): @pytest.fixture(scope='function') def setWebdriver(request, session_capabilities): - remoteURL = "https://hub-cloud.browserstack.com/wd/hub" + remoteURL = "https://hub.browserstack.com/wd/hub" driver = webdriver.Remote(remoteURL, session_capabilities) request.cls.driver = driver From e10247e40e03e7bf2a4561d847214659e4272cc5 Mon Sep 17 00:00:00 2001 From: Princeton Baretto <43331485+princebaretto99@users.noreply.github.com> Date: Thu, 17 Nov 2022 23:57:09 +0530 Subject: [PATCH 18/22] Update android/run-local-test/local.json Co-authored-by: Avinash Bharti <90600575+avinash-bharti@users.noreply.github.com> --- android/run-local-test/local.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/run-local-test/local.json b/android/run-local-test/local.json index 57e1bf6..60b3aee 100644 --- a/android/run-local-test/local.json +++ b/android/run-local-test/local.json @@ -5,7 +5,7 @@ "app" : "bs://", "bstack:options": { "projectName": "Pytest Browserstack", - "buildName": "browserstack-build-android", + "buildName": "browserstack-build-1", "sessionName": "BStack sample pytest", "local": "true", "debug": "true", From b63c5531db14d27b8b0cfa94de54eb681b72efb2 Mon Sep 17 00:00:00 2001 From: Princeton Baretto <43331485+princebaretto99@users.noreply.github.com> Date: Thu, 17 Nov 2022 23:57:21 +0530 Subject: [PATCH 19/22] Update android/run-local-test/local.json Co-authored-by: Avinash Bharti <90600575+avinash-bharti@users.noreply.github.com> --- android/run-local-test/local.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/run-local-test/local.json b/android/run-local-test/local.json index 60b3aee..26038ab 100644 --- a/android/run-local-test/local.json +++ b/android/run-local-test/local.json @@ -4,7 +4,7 @@ "capabilities": { "app" : "bs://", "bstack:options": { - "projectName": "Pytest Browserstack", + "projectName": "Pytest Local Project", "buildName": "browserstack-build-1", "sessionName": "BStack sample pytest", "local": "true", From 268aaf8a971d804d53fd61bf0c09a9d53ba820a1 Mon Sep 17 00:00:00 2001 From: Princeton Baretto <43331485+princebaretto99@users.noreply.github.com> Date: Thu, 17 Nov 2022 23:57:37 +0530 Subject: [PATCH 20/22] Update android/run-local-test/local.json Co-authored-by: Avinash Bharti <90600575+avinash-bharti@users.noreply.github.com> --- android/run-local-test/local.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/run-local-test/local.json b/android/run-local-test/local.json index 26038ab..600faf5 100644 --- a/android/run-local-test/local.json +++ b/android/run-local-test/local.json @@ -6,7 +6,7 @@ "bstack:options": { "projectName": "Pytest Local Project", "buildName": "browserstack-build-1", - "sessionName": "BStack sample pytest", + "sessionName": "BStack local_test", "local": "true", "debug": "true", "networkLogs": "true" From f78ac53a84a9c64dfb7e085fb90f95375705ef99 Mon Sep 17 00:00:00 2001 From: princebaretto99 Date: Fri, 18 Nov 2022 00:08:37 +0530 Subject: [PATCH 21/22] Fixed caps --- android/run-local-test/local.json | 2 +- android/run-local-test/tests/local_sample.py | 1 + android/run-parallel-test/parallel.json | 8 ++++---- android/run-single-test/single.json | 8 ++++---- ios/conftest.py | 2 +- ios/run-local-test/local.json | 6 +++--- ios/run-local-test/tests/local_sample.py | 1 + ios/run-parallel-test/parallel.json | 8 ++++---- ios/run-single-test/single.json | 8 ++++---- 9 files changed, 23 insertions(+), 21 deletions(-) diff --git a/android/run-local-test/local.json b/android/run-local-test/local.json index 600faf5..c229967 100644 --- a/android/run-local-test/local.json +++ b/android/run-local-test/local.json @@ -4,7 +4,7 @@ "capabilities": { "app" : "bs://", "bstack:options": { - "projectName": "Pytest Local Project", + "projectName": "Pytest Android Project", "buildName": "browserstack-build-1", "sessionName": "BStack local_test", "local": "true", diff --git a/android/run-local-test/tests/local_sample.py b/android/run-local-test/tests/local_sample.py index db0dbbe..da5bda6 100644 --- a/android/run-local-test/tests/local_sample.py +++ b/android/run-local-test/tests/local_sample.py @@ -34,4 +34,5 @@ def test_example(self): else: self.driver.execute_script( 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed","reason": "Test Passed Successfully"}}') + \ No newline at end of file diff --git a/android/run-parallel-test/parallel.json b/android/run-parallel-test/parallel.json index adfa297..6810f0d 100644 --- a/android/run-parallel-test/parallel.json +++ b/android/run-parallel-test/parallel.json @@ -2,11 +2,11 @@ "user": "BROWSERSTACK_USERNAME", "key": "BROWSERSTACK_ACCESS_KEY", "capabilities": { - "app" : "bs://d83aa0e9b284055bf70c906239301a579b6143c4", + "app" : "bs://", "bstack:options": { - "projectName": "Pytest Browserstack", - "buildName": "browserstack-build-android", - "sessionName": "BStack sample pytest", + "projectName": "Pytest Android Project", + "buildName": "browserstack-build-1", + "sessionName": "BStack parallel_test", "local": false, "debug": "true", "networkLogs": "true" diff --git a/android/run-single-test/single.json b/android/run-single-test/single.json index 98eb87c..89d2ae0 100644 --- a/android/run-single-test/single.json +++ b/android/run-single-test/single.json @@ -2,11 +2,11 @@ "user": "BROWSERSTACK_USERNAME", "key": "BROWSERSTACK_ACCESS_KEY", "capabilities": { - "app" : "bs://d83aa0e9b284055bf70c906239301a579b6143c4", + "app" : "bs://", "bstack:options": { - "projectName": "Pytest Browserstack", - "buildName": "browserstack-build-android", - "sessionName": "BStack sample pytest", + "projectName": "Pytest Android Project", + "buildName": "browserstack-build-1", + "sessionName": "BStack single_test", "local": false, "debug": "true", "networkLogs": "true" diff --git a/ios/conftest.py b/ios/conftest.py index ffa596b..7e0b62f 100644 --- a/ios/conftest.py +++ b/ios/conftest.py @@ -45,7 +45,7 @@ def session_capabilities(): @pytest.fixture(scope='function') def setWebdriver(request, session_capabilities): - remoteURL = "https://hub-cloud.browserstack.com/wd/hub" + remoteURL = "https://hub.browserstack.com/wd/hub" driver = webdriver.Remote(remoteURL, session_capabilities) request.cls.driver = driver diff --git a/ios/run-local-test/local.json b/ios/run-local-test/local.json index 5ba9b5e..32d4bc7 100644 --- a/ios/run-local-test/local.json +++ b/ios/run-local-test/local.json @@ -4,9 +4,9 @@ "capabilities": { "app" : "bs://", "bstack:options": { - "projectName": "Pytest Browserstack", - "buildName": "browserstack-build-ios", - "sessionName": "BStack sample pytest", + "projectName": "Pytest iOS Project", + "buildName": "browserstack-build-1", + "sessionName": "BStack local_test", "local": "true", "debug": "true", "networkLogs": "true" diff --git a/ios/run-local-test/tests/local_sample.py b/ios/run-local-test/tests/local_sample.py index f489154..3b196f4 100644 --- a/ios/run-local-test/tests/local_sample.py +++ b/ios/run-local-test/tests/local_sample.py @@ -32,4 +32,5 @@ def existence_lambda(s): else: self.driver.execute_script( 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed","reason": "Test failed"}}') + \ No newline at end of file diff --git a/ios/run-parallel-test/parallel.json b/ios/run-parallel-test/parallel.json index 08db95e..6a78c87 100644 --- a/ios/run-parallel-test/parallel.json +++ b/ios/run-parallel-test/parallel.json @@ -2,11 +2,11 @@ "user": "BROWSERSTACK_USERNAME", "key": "BROWSERSTACK_ACCESS_KEY", "capabilities": { - "app" : "IOSSampleApp", + "app" : "bs://", "bstack:options": { - "projectName": "Pytest Browserstack", - "buildName": "browserstack-build-ios", - "sessionName": "BStack sample pytest", + "projectName": "Pytest iOS Project", + "buildName": "browserstack-build-1", + "sessionName": "BStack parallel_test", "local": false, "debug": "true", "networkLogs": "true" diff --git a/ios/run-single-test/single.json b/ios/run-single-test/single.json index 072d22e..e56d881 100644 --- a/ios/run-single-test/single.json +++ b/ios/run-single-test/single.json @@ -2,11 +2,11 @@ "user": "BROWSERSTACK_USERNAME", "key": "BROWSERSTACK_ACCESS_KEY", "capabilities": { - "app" : "IOSSampleApp", + "app" : "bs://", "bstack:options": { - "projectName": "Pytest Browserstack", - "buildName": "browserstack-build-ios", - "sessionName": "BStack sample pytest", + "projectName": "Pytest iOS Project", + "buildName": "browserstack-build-1", + "sessionName": "BStack single_test", "local": false, "debug": "true", "networkLogs": "true" From 36a604baa0f418b2c75501fb83ec8fcad4b4b7be Mon Sep 17 00:00:00 2001 From: princebaretto99 Date: Fri, 18 Nov 2022 10:59:37 +0530 Subject: [PATCH 22/22] Updated requirements.txt --- requirements.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 43d2d01..5e57920 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,10 +2,9 @@ browserstack-local jsonmerge multiprocess paver -selenium==4.0.0 +selenium==4.6.0 psutil -pytest +pytest==7.1 pytest-variables -pytest-selenium pytest-xdist Appium-Python-Client