Skip to content

Commit 5ea669f

Browse files
Merge pull request #28 from browserstack/merge_sdk_to_main
Merge sdk to main
2 parents 40c8d4b + 69cef2d commit 5ea669f

File tree

12 files changed

+110
-178
lines changed

12 files changed

+110
-178
lines changed

.browserstack

Lines changed: 0 additions & 3 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.vscode
22
__pycache__
33
.pytest_cache
4-
local.log
54
env
5+
local.log

README.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,34 @@
11
# PyTest with Browserstack
22

3-
PyTest Integration with BrowserStack.
3+
PyTest Integration with BrowserStack using SDK.
44

55
![BrowserStack Logo](https://d98b8t1nnulk5.cloudfront.net/production/images/layout/logo-header.png?1469004780)
66
## Prerequisite
77
* Python3
88

99
## Setup
1010

11-
* Clone the repo
11+
* Clone the repo with `git clone -b sdk https://github.com/browserstack/pytest-browserstack.git`
12+
* It is recommended to use a virtual environment to install dependencies. To create a virtual environment:
13+
```
14+
python3 -m venv env
15+
source env/bin/activate # on Mac
16+
env\Scripts\activate # on Windows
17+
```
1218
* Install dependencies `pip install -r requirements.txt`
13-
* 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.
14-
15-
16-
## Run tests on locally hosted websites
17-
* 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
18-
* Run `paver run local`
19-
20-
## Run sample tests
21-
* To run parallel tests, run `paver run sample`
22-
23-
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
19+
* To run your automated tests using BrowserStack, you must provide a valid username and access key. This can be done either by providing your username and access key in the `browserstack.yml` configuration file, or by setting the `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` environment variables.
20+
21+
## Run sample test in parallel:
22+
* To run the sample test across platforms defined in the configuration file run:
23+
```
24+
browserstack-sdk pytest -s tests/bstack-sample-test.py
25+
```
26+
27+
## Run a sample local test:
28+
* To run the sample local test across platforms defined in the configuration file, you just need to set `browserstackLocal` key as true in the `browserstack.yml` file and run:
29+
```
30+
browserstack-sdk pytest -s tests/bstack-local-test.py
31+
```
2432

2533
## Notes
2634
* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate)

browserstack.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# =============================
2+
# Set BrowserStack Credentials
3+
# =============================
4+
# Add your BrowserStack userName and accessKey here or set BROWSERSTACK_USERNAME and
5+
# BROWSERSTACK_ACCESS_KEY as env variables
6+
userName: YOUR_USERNAME
7+
accessKey: YOUR_ACCESS_KEY
8+
9+
# ======================
10+
# BrowserStack Reporting
11+
# ======================
12+
# The following capabilities are used to set up reporting on BrowserStack:
13+
# Set 'projectName' to the name of your project. Example, Marketing Website
14+
projectName: BrowserStack Samples
15+
# Set `buildName` as the name of the job / testsuite being run
16+
buildName: browserstack build
17+
# `buildIdentifier` is a unique id to differentiate every execution that gets appended to
18+
# buildName. Choose your buildIdentifier format from the available expressions:
19+
# ${BUILD_NUMBER} (Default): Generates an incremental counter with every execution
20+
# ${DATE_TIME}: Generates a Timestamp with every execution. Eg. 05-Nov-19:30
21+
# Read more about buildIdentifiers here -> https://www.browserstack.com/docs/automate/selenium/organize-tests
22+
buildIdentifier: '#${BUILD_NUMBER}' # Supports strings along with either/both ${expression}
23+
# Set `framework` of your test suite. Example, `testng`, `cucumber`, `cucumber-testng`
24+
# This property is needed to send test context to BrowserStack (test name, status)
25+
framework: pytest
26+
27+
# =======================================
28+
# Platforms (Browsers / Devices to test)
29+
# =======================================
30+
# Platforms object contains all the browser / device combinations you want to test on.
31+
# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate)
32+
platforms:
33+
- os: OS X
34+
osVersion: Big Sur
35+
browserName: Chrome
36+
browserVersion: latest
37+
- os: Windows
38+
osVersion: 10
39+
browserName: Edge
40+
browserVersion: latest
41+
- deviceName: Samsung Galaxy S22 Ultra
42+
browserName: chrome # Try 'samsung' for Samsung browser
43+
osVersion: 12.0
44+
45+
# =======================
46+
# Parallels per Platform
47+
# =======================
48+
# The number of parallel threads to be used for each platform set.
49+
# BrowserStack's SDK runner will select the best strategy based on the configured value
50+
#
51+
# Example 1 - If you have configured 3 platforms and set `parallelsPerPlatform` as 2, a total of 6 (2 * 3) parallel threads will be used on BrowserStack
52+
#
53+
# Example 2 - If you have configured 1 platform and set `parallelsPerPlatform` as 5, a total of 5 (1 * 5) parallel threads will be used on BrowserStack
54+
parallelsPerPlatform: 1
55+
56+
# ==========================================
57+
# BrowserStack Local
58+
# (For localhost, staging/private websites)
59+
# ==========================================
60+
# Set browserStackLocal to true if your website under test is not accessible publicly over the internet
61+
# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction
62+
browserstackLocal: true # <boolean> (Default false)
63+
# browserStackLocalOptions:
64+
# Options to be passed to BrowserStack local in-case of advanced configurations
65+
# localIdentifier: # <string> (Default: null) Needed if you need to run multiple instances of local.
66+
# forceLocal: true # <boolean> (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel.
67+
# Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections
68+
69+
source: pytest-browserstack:sample-sdk:v1.0
70+
71+
# ===================
72+
# Debugging features
73+
# ===================
74+
debug: false # <boolean> # Set to true if you need screenshots for every selenium command ran
75+
networkLogs: false # <boolean> Set to true to enable HAR logs capturing
76+
consoleLogs: errors # <string> Remote browser's console debug levels to be printed (Default: errors)
77+
# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors)

config/local.json

Lines changed: 0 additions & 24 deletions
This file was deleted.

config/sample.json

Lines changed: 0 additions & 38 deletions
This file was deleted.

conftest.py

Lines changed: 0 additions & 41 deletions
This file was deleted.

pavement.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

requirements.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
browserstack-local
22
jsonmerge
3-
multiprocess
4-
paver
53
selenium==4.*
64
psutil
7-
pytest
5+
pytest==7.4.4
86
pytest-variables
97
pytest-selenium
10-
pytest-xdist
8+
browserstack-sdk
9+
pytest-html==3.2.0

tests/bstack-local-test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import pytest
2+
3+
def test_local(selenium):
4+
selenium.get('http://bs-local.com:45454')
5+
local_page_title = selenium.title
6+
assert local_page_title == 'BrowserStack Local'

0 commit comments

Comments
 (0)