Skip to content

Commit a0d1034

Browse files
authored
Merge pull request #5 from Rushabhshroff/main
Main
2 parents 60dd01f + 9e170e5 commit a0d1034

File tree

9 files changed

+45
-93
lines changed

9 files changed

+45
-93
lines changed

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,25 @@
33
PyTest Integration with BrowserStack.
44

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

79
## Setup
810

911
* Clone the repo
1012
* Install dependencies `pip install -r requirements.txt`
11-
* 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, or by setting the BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY environment variables.
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.
1214

13-
## Running your single tests
14-
* To run single tests, run `paver run single`
1515

16-
## Running your local tests
17-
* To run a local test, (if you have not set the BROWSERSTACK_ACCESS_KEY environment variable) first go to conftest.py then edit access_key on line 10
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
1818
* Run `paver run local`
1919

20-
## Running your parallel tests
21-
* To run parallel tests, run `paver run parallel`
20+
## Run sample tests
21+
* To run parallel tests, run `paver run sample`
2222

2323
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
2424

2525
## Notes
2626
* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate)
2727
* To test on a different set of browsers, check out our [platform configurator](https://www.browserstack.com/automate/python#setting-os-and-browser)
28-

config/local.json

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
{
2-
"capabilities": {
3-
"bstack:options": {
4-
"projectName": "Pytest Browserstack",
5-
"buildName": "browserstack-build-1",
6-
"sessionName": "local_test",
7-
"local": true,
8-
"debug" : "true",
9-
"networkLogs": "true"
10-
}
11-
},
12-
"environments": [
13-
{
14-
"bstack:options": {
15-
"os": "Windows",
16-
"osVersion": "11"
17-
},
18-
"browserName": "chrome",
19-
"browserVersion": "latest"
20-
}
21-
]
2+
"user": "BROWSERSTACK_USERNAME",
3+
"key": "BROWSERSTACK_ACCESS_KEY",
4+
"capabilities": {
5+
"bstack:options": {
6+
"projectName": "Pytest Browserstack",
7+
"buildName": "browserstack-build-1",
8+
"sessionName": "Bstack Local Test",
9+
"local": true,
10+
"debug": "true",
11+
"networkLogs": "true"
12+
}
13+
},
14+
"environments": [
15+
{
16+
"bstack:options": {
17+
"os": "Windows",
18+
"osVersion": "11"
19+
},
20+
"browserName": "chrome",
21+
"browserVersion": "latest"
22+
}
23+
]
2224
}

config/parallel.json renamed to config/sample.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
2+
"user": "BROWSERSTACK_USERNAME",
3+
"key": "BROWSERSTACK_ACCESS_KEY",
24
"capabilities": {
35
"bstack:options": {
46
"projectName": "Pytest Browserstack",
57
"buildName": "browserstack-build-1",
6-
"sessionName": "parallel_test",
8+
"sessionName": "BStack pytest sample",
79
"local": false,
8-
"debug" : "true",
10+
"debug": "true",
911
"networkLogs": "true"
1012
}
1113
},
@@ -20,16 +22,16 @@
2022
},
2123
{
2224
"bstack:options": {
23-
"os" : "OS X",
24-
"osVersion" : "Monterey"
25+
"os": "OS X",
26+
"osVersion": "Monterey"
2527
},
2628
"browserName": "firefox",
2729
"browserVersion": "latest"
2830
},
2931
{
3032
"bstack:options": {
31-
"osVersion" : "10.0",
32-
"deviceName" : "Samsung Galaxy S20"
33+
"osVersion": "10.0",
34+
"deviceName": "Samsung Galaxy S20"
3335
}
3436
}
3537
]

config/single.json

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

conftest.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
bs_local = None
1212

13-
BROWSERSTACK_ACCESS_KEY = os.environ['BROWSERSTACK_ACCESS_KEY'] if 'BROWSERSTACK_ACCESS_KEY' in os.environ else None
13+
BROWSERSTACK_USERNAME = os.environ['BROWSERSTACK_USERNAME'] if 'BROWSERSTACK_USERNAME' in os.environ else CONFIG["user"]
14+
BROWSERSTACK_ACCESS_KEY = os.environ['BROWSERSTACK_ACCESS_KEY'] if 'BROWSERSTACK_ACCESS_KEY' in os.environ else CONFIG["key"]
1415

1516
def start_local():
1617
"""Code to start browserstack local before start of test."""
@@ -27,10 +28,12 @@ def stop_local():
2728

2829
@pytest.fixture(scope='session')
2930
def session_capabilities():
30-
desired_capabilities = merge(CONFIG['environments'][TASK_ID],CONFIG["capabilities"])
31-
if "local" in desired_capabilities['bstack:options'] and desired_capabilities['bstack:options']['local']:
31+
capabilities = merge(CONFIG['environments'][TASK_ID],CONFIG["capabilities"])
32+
capabilities['bstack:options']['userName'] = BROWSERSTACK_USERNAME
33+
capabilities['bstack:options']['accessKey'] = BROWSERSTACK_ACCESS_KEY
34+
if "local" in capabilities['bstack:options'] and capabilities['bstack:options']['local']:
3235
start_local()
33-
return desired_capabilities
36+
return capabilities
3437

3538

3639
def pytest_sessionfinish(session, exitstatus):

pavement.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,3 @@ def run(args):
3535
p = Process(target=run_py_test, args=(args[0], i))
3636
jobs.append(p)
3737
p.start()
38-
39-
@task
40-
def test():
41-
"""Run all tests"""
42-
sh("paver run single")
43-
sh("paver run local")
44-
sh("paver run parallel")

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ browserstack-local
22
jsonmerge
33
multiprocess
44
paver
5-
selenium
5+
selenium==4.*
66
psutil
77
pytest
88
pytest-variables
File renamed without changes.

tests/test_single.py

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

0 commit comments

Comments
 (0)