Skip to content

Commit 279f2a5

Browse files
authored
Merge pull request #27 from browserstack/merge_sdk_to_master
Merge sdk to master
2 parents 05a4786 + 56151a3 commit 279f2a5

File tree

13 files changed

+136
-187
lines changed

13 files changed

+136
-187
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
local.log
2+
env
23
**.pyc

.travis.yml

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

README.md

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,62 @@
44

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

7+
## Prerequisite
8+
```
9+
python3 should be installed
10+
```
11+
712
## Setup
13+
* Clone the repo
14+
```
15+
git clone -b sdk https://github.com/browserstack/behave-browserstack.git
16+
```
17+
* It is recommended to use a virtual environment to install dependencies. To create a virtual environment:
18+
```
19+
python3 -m venv env
20+
source env/bin/activate # on Mac/Linux
21+
env\Scripts\activate # on Windows
22+
```
23+
* Install dependencies
24+
```
25+
pip install -r requirements.txt
26+
```
827

9-
* Clone the repo
10-
* Install dependencies `pip install -r requirements.txt`
11-
* Update `*.json` files inside the `config/` directory with your [BrowserStack Username and Access Key](https://www.browserstack.com/accounts/settings)
28+
## Set BrowserStack Credentials
29+
* Add your BrowserStack username and access key in the `browserstack.yml` config fle.
30+
* You can also export them as environment variables, `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY`:
31+
#### For Linux/MacOS
32+
```
33+
export BROWSERSTACK_USERNAME=<browserstack-username>
34+
export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
35+
```
36+
#### For Windows
37+
```
38+
set BROWSERSTACK_USERNAME=<browserstack-username>
39+
set BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
40+
41+
setx BROWSERSTACK_USERNAME=<browserstack-username>
42+
setx BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
43+
```
1244
13-
## Running your tests
14-
* To run tests, run `paver run parallel`
15-
* To run local tests, run `paver run local`
45+
## Running tests
1646
17-
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
47+
* To run sample tests:
48+
- To run the sample tests in parallel across the platforms defined in the `browserstack.yml` file, run:
49+
```
50+
browserstack-sdk behave features/test.feature
51+
```
52+
* To run tests on locally hosted websites:
53+
- To run the local test in parallel across the platforms defined in the `browserstack.yml` file, run:
54+
```
55+
browserstack-sdk behave features/local-test.feature
56+
```
1857
1958
## Notes
2059
* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate)
21-
* To test on a different set of browsers, check out our [platform configurator](https://www.browserstack.com/automate/python#setting-os-and-browser)
22-
* You can export the environment variables for the Username and Access Key of your BrowserStack account
23-
24-
```
25-
export BROWSERSTACK_USERNAME=<browserstack-username> &&
26-
export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
27-
```
28-
60+
* To test on a different set of browsers, check out our [platform configurator](https://www.browserstack.com/docs/automate/selenium/sdk-config-generator)
61+
* Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
62+
2963
## Additional Resources
3064
* [Documentation for writing Automate test scripts in Python](https://www.browserstack.com/automate/python)
3165
* [Customizing your tests on BrowserStack](https://www.browserstack.com/automate/capabilities)

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: behave
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: behave-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 & 17 deletions
This file was deleted.

config/parallel.json

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

config/single.json

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

features/environment.py

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,13 @@
11
from selenium import webdriver
2-
from browserstack.local import Local
3-
import os, json
4-
5-
CONFIG_FILE = os.environ['CONFIG_FILE'] if 'CONFIG_FILE' in os.environ else 'config/single.json'
6-
TASK_ID = int(os.environ['TASK_ID']) if 'TASK_ID' in os.environ else 0
7-
8-
with open(CONFIG_FILE) as data_file:
9-
CONFIG = json.load(data_file)
10-
11-
bs_local = None
12-
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']
15-
16-
def start_local():
17-
"""Code to start browserstack local before start of test."""
18-
global bs_local
19-
bs_local = Local()
20-
bs_local_args = { "key": BROWSERSTACK_ACCESS_KEY, "forcelocal": "true" }
21-
bs_local.start(**bs_local_args)
22-
23-
def stop_local():
24-
"""Code to stop browserstack local after end of test."""
25-
global bs_local
26-
if bs_local is not None:
27-
bs_local.stop()
28-
292

303
def before_feature(context, feature):
31-
desired_capabilities = CONFIG['environments'][TASK_ID]
32-
for key in CONFIG["capabilities"]:
33-
if key not in desired_capabilities:
34-
desired_capabilities[key] = CONFIG["capabilities"][key]
35-
elif key == "bstack:options":
36-
desired_capabilities[key].update(CONFIG["capabilities"][key])
37-
desired_capabilities['bstack:options']['source'] = 'behave:sample-master:v1.2'
38-
39-
if "bstack:options" in desired_capabilities and "local" in desired_capabilities["bstack:options"] and desired_capabilities["bstack:options"]["local"]:
40-
start_local()
41-
4+
desired_capabilities = {
5+
'browserName': 'chrome'
6+
}
427
context.browser = webdriver.Remote(
438
desired_capabilities=desired_capabilities,
44-
command_executor="https://%s:%[email protected]/wd/hub" % (BROWSERSTACK_USERNAME, BROWSERSTACK_ACCESS_KEY)
9+
command_executor="http://localhost:4444/wd/hub"
4510
)
4611

4712
def after_feature(context, feature):
48-
if context.failed is True:
49-
context.browser.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed", "reason": "At least 1 assertion failed"}}')
50-
if context.failed is not True:
51-
context.browser.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed", "reason": "All assertions passed"}}')
5213
context.browser.quit()
53-
stop_local()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Feature: BrowserStack Local Testing
1+
Feature: BStack Local Testing
22
Scenario: can check tunnel working
33
When visit url "http://bs-local.com:45454/"
44
Then title contains "BrowserStack Local"

features/steps/steps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def step(context, selector):
2222
item = context.browser.find_element(By.XPATH, selector)
2323
item_in_cart = item.text
2424
assert item_in_cart == context.item_to_add
25-
25+
2626
@then('title contains "{title}"')
2727
def step(context, title):
2828
assert title in context.browser.title

0 commit comments

Comments
 (0)