Skip to content

Commit 0ddb50a

Browse files
Merge pull request #24 from browserstack/merge_sdk_to_main
Merge sdk to main
2 parents e96d062 + 94b4aa1 commit 0ddb50a

19 files changed

+247
-277
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ pabot_results/
77
.pabotsuitenames
88
.DS_Store
99
*.png
10+
browserstack.err
11+
env

README.md

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,60 @@
22

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

5-
## Setup
6-
* Clone the repo
7-
* Install dependencies `pip install -r requirements.txt`
8-
9-
## Set BrowserStack Credentials
10-
* Export the BrowserStack username and access key as environment variables
5+
## Prerequisite
6+
```
7+
python3 should be installed
8+
```
119

12-
#### For Linux/MacOS
10+
## Setup
11+
* Clone the repo
1312
```
14-
export BROWSERSTACK_USERNAME=<browserstack-username>
15-
export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
13+
git clone -b sdk https://github.com/browserstack/robot-browserstack.git
1614
```
17-
#### For Windows
15+
* It is recommended to use a virtual environment to install dependencies. To create a virtual environment:
1816
```
19-
setx BROWSERSTACK_USERNAME=<browserstack-username>
20-
setx BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
17+
python3 -m venv env
18+
source env/bin/activate # on Mac
19+
env\Scripts\activate # on Windows
2120
```
21+
* Install dependencies
22+
```
23+
pip install -r requirements.txt
24+
```
25+
26+
## Set BrowserStack Credentials
27+
* Add your BrowserStack username and access key in the `browserstack.yml` config fle.
28+
* You can also export them as environment variables, `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY`:
29+
30+
#### For Linux/MacOS
31+
```
32+
export BROWSERSTACK_USERNAME=<browserstack-username>
33+
export BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
34+
```
35+
#### For Windows
36+
```
37+
set BROWSERSTACK_USERNAME=<browserstack-username>
38+
set BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
39+
40+
setx BROWSERSTACK_USERNAME=<browserstack-username>
41+
setx BROWSERSTACK_ACCESS_KEY=<browserstack-access-key>
42+
```
2243
2344
## Running tests
2445
25-
* To run local test, run `robot tests/LocalTest.robot`
26-
* To run parallel tests we will be using the [Pabot](https://pabot.org/) library:
27-
1. To run test suites in parallel (Testcases within respective test suites will be sequential)
28-
* Run - `pabot --processes <count_of_parallels> tests/parallel/*.robot`
29-
* Alternate method: `pabot --processes <count_of_parallels> <name_of_suites_to_run>`
30-
<br/>Eg: `pabot --processes 2 tests/parallel/Suite01.robot tests/parallel/Suite02.robot`
31-
2. To run all test cases within a test suite in parallel
32-
* Run - `pabot --testlevelsplit <test_suite_file_name>`
33-
<br/>Eg: `pabot --testlevelsplit tests/parallel/Suite01.robot`
34-
3. Run all testcases across all Test Suites in parallel
35-
* Run - `pabot --testlevelsplit --processes <count_of_parallels> tests/parallel/*.robot`
36-
<br/>**Note: If the process count exceeds the parallel threads available on BrowserStack, the sessions will automatically get queued.**
46+
* To run sample tests:
47+
- To run the sample tests in parallel across the platforms defined in the `browserstack.yml` file, run:
48+
```
49+
browserstack-sdk robot ./tests/test-*.robot
50+
```
51+
* To run tests on locally hosted websites:
52+
- To run the local test in parallel across the platforms defined in the `browserstack.yml` file, run:
53+
```
54+
browserstack-sdk robot ./tests/local-test.robot
55+
```
3756
3857
Understand how many parallel sessions you need by using our [Parallel Test Calculator](https://www.browserstack.com/automate/parallel-calculator?ref=github)
3958
40-
## Notes
41-
* This repository only works for Selenium 3 as of now. Desired Capabilities do not get honoured for Selenium 4. The open issue on SeleniumLibrary can be found [here](https://github.com/robotframework/SeleniumLibrary/issues/1774).
42-
* You can view your test results on the [BrowserStack Automate dashboard](https://www.browserstack.com/automate)
43-
* To test on a different set of browsers, check out our [platform configurator](https://www.browserstack.com/automate/capabilities)
44-
4559
## Additional Resources
4660
* [Documentation for writing Automate test scripts in Python](https://www.browserstack.com/automate/python)
4761
* [Customizing your tests on BrowserStack](https://www.browserstack.com/automate/capabilities)

browserstack.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
24+
# =======================================
25+
# Platforms (Browsers / Devices to test)
26+
# =======================================
27+
# Platforms object contains all the browser / device combinations you want to test on.
28+
# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate)
29+
platforms:
30+
- os: OS X
31+
osVersion: Big Sur
32+
browserName: Chrome
33+
browserVersion: latest
34+
- os: Windows
35+
osVersion: 10
36+
browserName: Edge
37+
browserVersion: latest
38+
- deviceName: Samsung Galaxy S22 Ultra
39+
browserName: chrome # Try 'samsung' for Samsung browser
40+
osVersion: 12.0
41+
42+
# =======================
43+
# Parallels per Platform
44+
# =======================
45+
# The number of parallel threads to be used for each platform set.
46+
# BrowserStack's SDK runner will select the best strategy based on the configured value
47+
#
48+
# 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
49+
#
50+
# 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
51+
parallelsPerPlatform: 1
52+
53+
# ==========================================
54+
# BrowserStack Local
55+
# (For localhost, staging/private websites)
56+
# ==========================================
57+
# Set browserStackLocal to true if your website under test is not accessible publicly over the internet
58+
# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction
59+
browserstackLocal: true # <boolean> (Default false)
60+
# browserStackLocalOptions:
61+
# Options to be passed to BrowserStack local in-case of advanced configurations
62+
# localIdentifier: # <string> (Default: null) Needed if you need to run multiple instances of local.
63+
# forceLocal: true # <boolean> (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel.
64+
# Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections
65+
66+
source: robot-browserstack:sample-sdk:v1.0
67+
68+
# ===================
69+
# Debugging features
70+
# ===================
71+
debug: false # <boolean> # Set to true if you need screenshots for every selenium command ran
72+
networkLogs: false # <boolean> Set to true to enable HAR logs capturing
73+
consoleLogs: errors # <string> Remote browser's console debug levels to be printed (Default: errors)
74+
# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors)

config/Config.py

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

config/KeywordsFile.robot

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

config/manage-local-testing.py

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

config/mark-test-status.py

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

requirements.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
robotframework
2-
robotframework-seleniumlibrary==5.1.3
1+
robotframework==6.1.1
2+
robotframework-seleniumlibrary==6.2.0
33
robotframework-pabot
44
browserstack-local
5-
selenium==3.141.0
5+
selenium
6+
browserstack-sdk

resources/KeywordsFile.robot

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
*** Settings ***
2+
Library SeleniumLibrary
3+
4+
*** Variables ***
5+
${remote_url}= http://localhost:4444/wd/hub
6+
7+
*** Keywords ***
8+
Open Session
9+
[Arguments] ${capabilities} ${test_url}
10+
open browser remote_url=${remote_url} browser=chrome desired_capabilities=${capabilities} url=${test_url}
11+
12+
Close Session
13+
close browser
14+
15+
Add Implicit Wait
16+
set selenium implicit wait 5
17+
18+
Get the page title
19+
get title
20+
21+
Verify Local Page
22+
Title Should be BrowserStack Local
23+
24+
Add first product to cart
25+
click element xpath=//*[@id="1"]/div[4]
26+
27+
Verify product is added to cart
28+
${product_name} get text xpath=//*[@id="1"]/p
29+
${product_incart} get text css=p.title
30+
element should contain css=p.title ${product_name}

resources/TestCases.robot

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*** Settings ***
2+
Library SeleniumLibrary
3+
Resource ./KeywordsFile.robot
4+
5+
*** Keywords ***
6+
Add to Cart
7+
Add Implicit Wait
8+
Get the page title
9+
Add first product to cart
10+
Verify product is added to cart

0 commit comments

Comments
 (0)