Skip to content

Merge sdk to main #35

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

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
76c1df0
update: test files for sdk, remove extra files
Ankit098 Oct 7, 2022
b892855
add: config file and requirements
Ankit098 Oct 7, 2022
858d286
chore: update list of platforms
Ankit098 Oct 7, 2022
2a7bccd
add: readme for sdk, rename files
Ankit098 Oct 7, 2022
20cde6d
chore: add comments
Ankit098 Oct 21, 2022
c89d4ed
Merge pull request #14 from Ankit098/sdk
Ankit098 Oct 27, 2022
4acec78
chore: fix command in readme
Ankit098 Nov 3, 2022
60415b4
update: modify local test with default localIdentifier
Ankit098 Nov 9, 2022
61b6fcf
update: title match condition
Ankit098 Nov 10, 2022
84a2f47
chore: remove unused import
Ankit098 Nov 10, 2022
3736a58
Merge pull request #19 from Ankit098/local_identifier
Ankit098 Nov 18, 2022
ac90002
update: sample yml
Ankit098 Dec 28, 2022
5c091b7
Merge pull request #22 from Ankit098/sdk_improve
karanshah-browserstack Dec 28, 2022
f37a249
Added github action
agarneha1331 Apr 10, 2023
0369bf2
fix codeowners
agarneha1331 Apr 11, 2023
c5c6652
fix name in workflow file
agarneha1331 Apr 11, 2023
52866f8
Added sessionName
agarneha1331 Jun 19, 2023
0f53e6c
small fix
agarneha1331 Jun 19, 2023
1d5910e
Revert "small fix"
karanshah-browserstack Jun 20, 2023
328942b
Revert "Added sessionName"
karanshah-browserstack Jun 20, 2023
e7d9f77
Merge pull request #30 from browserstack/revert-29-fix-session-name-sdk
karanshah-browserstack Jun 20, 2023
9af5c54
Revert "Revert "Added sessionName""
karanshah-browserstack Jun 20, 2023
92f9a52
Merge pull request #31 from browserstack/revert-30-revert-29-fix-sess…
Jul 7, 2023
240c2a9
delete sdk workflow
agarneha1331 Jul 10, 2023
2a56a02
Merged sdk branch to merge_sdk_to_main
Jun 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .env

This file was deleted.

52 changes: 33 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +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
## Setup
* Clone the repo
```
pip3 install -r requirements.txt
git clone -b sdk https://github.com/browserstack/python-selenium-browserstack.git
```
* Install packages through requirements.txt
```
- Update your credentials in .env file
```dotenv
BROWSERSTACK_USERNAME="BROWSERSTACK_USERNAME"
BROWSERSTACK_ACCESS_KEY="BROWSERSTACK_ACCESS_KEY"
URL="https://hub.browserstack.com/wd/hub"
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 parallel
```
python3 ./scripts/parallel.py
```
b. For local
```
python3 ./scripts/local.py
```
## Running tests
* Run sample test:
- To run the sample test across platforms defined in the `browserstack.yml` file, run:
```
browserstack-sdk ./tests/test.py
```
* Run tests on locally hosted website:
- To run the local test across platforms defined in the `browserstack.yml` file, run:
```
browserstack-sdk ./tests/local-test.py
```
63 changes: 63 additions & 0 deletions browserstack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# =============================
# Set BrowserStack Credentials
# =============================
# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and
# BROWSERSTACK_ACCESS_KEY as env variables
userName: YOUR_USERNAME
accessKey: YOUR_ACCESS_KEY

# ======================
# 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}

# =======================================
# 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
- deviceName: 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 available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections

source: python-browserstack:sample-sdk:v1.0

# ===================
# 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 (Default: errors)
# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors)
4 changes: 2 additions & 2 deletions requirements.txt
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
64 changes: 0 additions & 64 deletions scripts/local.py

This file was deleted.

116 changes: 0 additions & 116 deletions scripts/parallel.py

This file was deleted.

33 changes: 33 additions & 0 deletions tests/local-test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import json
from selenium import webdriver
from selenium.webdriver.chrome.options import Options as ChromeOptions

options = ChromeOptions()
options.set_capability('sessionName', 'BStack Local Test')

# 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:45454')
page_title = driver.title
# check if local connected successfully
if 'BrowserStack Local' in page_title:
# 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()
Loading