-
Notifications
You must be signed in to change notification settings - Fork 31
use sdk to run tests #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
76c1df0
update: test files for sdk, remove extra files
Ankit098 b892855
add: config file and requirements
Ankit098 858d286
chore: update list of platforms
Ankit098 2a7bccd
add: readme for sdk, rename files
Ankit098 20cde6d
chore: add comments
Ankit098 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,48 +1,44 @@ | ||
| # python-selenium-browserstack | ||
| Run python tests on browserstack using the SDK. | ||
|
|
||
| ## Prerequisite | ||
| ``` | ||
| python3 and pip3 should be installed | ||
| python3 should be installed | ||
| ``` | ||
|
|
||
| ## Steps to run test session | ||
|
|
||
| - Install packages through requirements.txt | ||
| ``` | ||
| pip3 install -r requirements.txt | ||
| ## Setup | ||
| * Clone the repo | ||
| ``` | ||
| - Update your credentials in .env file | ||
| ```dotenv | ||
| BROWSERSTACK_USERNAME="BROWSERSTACK_USERNAME" | ||
| BROWSERSTACK_ACCESS_KEY="BROWSERSTACK_ACCESS_KEY" | ||
| URL="https://hub.browserstack.com/wd/hub" | ||
| git clone -b sdk https://github.com/browserstack/python-selenium-browserstack.git | ||
| ``` | ||
| * Install packages through requirements.txt | ||
| ``` | ||
| - Change the capabilities if you wish: | ||
| (For single test session, Navigate to ./scripts/single.py) | ||
| ```python | ||
| desired_cap = { | ||
| ... | ||
| 'browserName': 'iPhone', | ||
| 'device': 'iPhone 11', | ||
| 'realMobile': 'true', | ||
| 'os_version': '14.0', | ||
| 'name': 'BStack-[Python] Sample Test', # test name | ||
| 'build': 'BStack Build Number 1' # CI/CD job or build name | ||
| ... | ||
| } | ||
| pip3 install -r requirements.txt | ||
| ``` | ||
|
|
||
| - Run tests | ||
| ## Set BrowserStack Credentials | ||
| * Add your BrowserStack username and access key in the `browserstack.yml` config fle. | ||
| * You can also export them as environment variables, `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY`: | ||
|
|
||
| #### For Linux/MacOS | ||
| ``` | ||
| export BROWSERSTACK_USERNAME=<browserstack-username> | ||
| export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key> | ||
| ``` | ||
| #### For Windows | ||
| ``` | ||
| setx BROWSERSTACK_USERNAME=<browserstack-username> | ||
| setx BROWSERSTACK_ACCESS_KEY=<browserstack-access-key> | ||
| ``` | ||
|
|
||
| a. For single | ||
| ``` | ||
| python3 ./scripts/single.py | ||
| ``` | ||
| b. For local | ||
| ``` | ||
| python3 ./scripts/local.py | ||
| ``` | ||
| c. For parallel | ||
| ``` | ||
| python3 ./scripts/parallel.py | ||
| ``` | ||
| ## Running tests | ||
| * Run sample test: | ||
| - To run the sample test across platforms defined in the `browserstack.yml` file, run: | ||
| ``` | ||
| browserstack-sdk ./scripts/test.py | ||
| ``` | ||
| * Run tests on locally hosted website: | ||
| - To run the local test across platforms defined in the `browserstack.yml` file, run: | ||
| ``` | ||
| browserstack-sdk ./scripts/local-test.py | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # ============================= | ||
| # Set BrowserStack Credentials | ||
| # ============================= | ||
| # Add your BrowserStack userName and acccessKey here or set BROWSERSTACK_USERNAME and | ||
| # BROWSERSTACK_ACCESS_KEY as env variables | ||
| userName: YOUR_USERNAME | ||
| accessKey: YOUR_ACCESS_KEY | ||
|
|
||
| # ====================== | ||
| # Organizing your tests | ||
| # ====================== | ||
| # Use `projectName`, `buildName`, `name` capabilities to organise your tests | ||
| # `name` is the name of your test sessions and is automatically picked from your | ||
| # test name and doesn't need to be set manually when using BrowserStack SDK | ||
| # `buildName` is used to name your CI/CD job or the execution of your test suite. | ||
| # Ensure you add a dynamic identifier, like an incremental build number from your | ||
| # CI/CD or timestamp at the end of every build; otherwise tests from different | ||
| # executions will be grouped together on BrowserStack | ||
| buildName: browserstack-build-1 | ||
| # Use `projectName` to set the name of your project. Example, Marketing Website | ||
| projectName: BrowserStack Samples | ||
|
|
||
| # ======================================= | ||
| # Platforms (Browsers / Devices to test) | ||
| # ======================================= | ||
| # Platforms object contains all the browser / device combinations you want to test on. | ||
| # Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate) | ||
| platforms: | ||
| - os: OS X | ||
| osVersion: Big Sur | ||
| browser: Chrome | ||
| browserVersion: latest | ||
| - os: Windows | ||
| osVersion: 10 | ||
| browser: Edge | ||
| browserVersion: latest | ||
| - device: Samsung Galaxy S22 Ultra | ||
| browserName: chrome # Try 'samsung' for Samsung browser | ||
| osVersion: 12.0 | ||
|
|
||
| # ========================================== | ||
| # 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 # <boolean> (Default false) | ||
| # browserStackLocalOptions: | ||
| # Options to be passed to BrowserStack local in-case of advanced configurations | ||
| # localIdentifier: # <string> (Default: null) Needed if you need to run multiple instances of local. | ||
| # forceLocal: true # <boolean> (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel. | ||
| # Entire list of arguments availabe here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections | ||
|
|
||
| # =================== | ||
| # Debugging features | ||
| # =================== | ||
| debug: false # <boolean> # Set to true if you need screenshots for every selenium command ran | ||
| networkLogs: false # <boolean> Set to true to enable HAR logs capturing | ||
| consoleLogs: errors # <string> Remote browser's console debug levels to be printed (Available levels: `disable`, `errors`, `warnings`, `info`, `verbose`, Default: errors) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| python-dotenv | ||
| browserstack-local >= 1.2.3 | ||
| selenium == 4.1.0 | ||
| selenium | ||
| browserstack-sdk |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import json | ||
| from selenium import webdriver | ||
| from selenium.webdriver.support.ui import WebDriverWait | ||
| from selenium.webdriver.support import expected_conditions as EC | ||
| from selenium.webdriver.common.by import By | ||
| from selenium.webdriver.chrome.options import Options as ChromeOptions | ||
|
|
||
| options = ChromeOptions() | ||
|
|
||
| # The webdriver management will be handled by the browserstack-sdk | ||
| # so this will be overridden and tests will run browserstack - | ||
| # without any changes to the test files! | ||
| driver = webdriver.Remote( | ||
| command_executor='http://localhost:4444/wd/hub', | ||
| options=options) | ||
|
|
||
| try: | ||
| driver.get('http://bs-local.com:45691/check') | ||
| body_text = WebDriverWait(driver, 10).until( | ||
| EC.visibility_of_element_located((By.CSS_SELECTOR, 'body'))).text | ||
| # check if local connected successfully | ||
| if body_text == 'Up and running': | ||
| # mark test as passed if Local website is accessible | ||
| driver.execute_script( | ||
| 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed", "reason": "Local Test ran successfully"}}') | ||
| else: | ||
| # mark test as failed if Local website is not accessible | ||
| driver.execute_script( | ||
| 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed", "reason": "Local test setup failed"}}') | ||
| except Exception as err: | ||
| message = 'Exception: ' + str(err.__class__) + str(err.msg) | ||
| driver.execute_script( | ||
| 'browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed", "reason": ' + json.dumps(message) + '}}') | ||
|
|
||
| # Stop the driver | ||
| driver.quit() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.