Skip to content

Commit a70b033

Browse files
agarneha1331francisf
authored andcommitted
Integrating with browserstack-sdk
1 parent ff0b2d8 commit a70b033

12 files changed

Lines changed: 165 additions & 167 deletions

README.md

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,11 @@ Ensure that @ symbol is prepended to the file path in the above request. Please
7272
7373
**2. Configure and run your first test**
7474
75-
Open `browserstack_sample.py` file in `Android` or `iOS` folder :
75+
Open `Android` or `iOS` folder :
7676
77-
- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings)
77+
- If you have uploaded your own app, update the app in the `browserstack.yml`
7878
79-
- Replace `bs://<app-id>` wkth the URL obtained from app upload step
80-
81-
- Set the device and OS version
82-
83-
- If you have uploaded your own app update the test case
84-
85-
- Run `python browserstack_sample.py`
79+
- Run `browserstack-sdk python browserstack_sample.py`
8680
8781
- You can access the test execution results, and debugging information such as video recording, network logs on [App Automate dashboard](https://app-automate.browserstack.com/dashboard)
8882
@@ -106,17 +100,11 @@ Ensure that @ symbol is prepended to the file path in the above request. Please
106100
107101
**2. Configure and run your local test**
108102
109-
Open `browserstack_sample_local` file in `Android` or `iOS` folder :
110-
111-
- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings)
112-
113-
- Replace `bs://<app-id>` wkth the URL obtained from app upload step
114-
115-
- Set the device and OS version
103+
Open `Android` or `iOS` folder :
116104
117-
- Ensure that `local` capability is set to `true`. Within the test script, there is code snippet that automatically establishes Local Testing connection to BrowserStack servers using Python binding for BrowserStack Local.
105+
- Ensure that `local` capability is set to `true` in the `browserstack.yml` file
118106
119-
- If you have uploaded your own app update the test case
107+
- If you have uploaded your own app, update the app in the `browserstack.yml`
120108
121109
- Run `python browserstack_sample_local.py`
122110

android/LocalSample.apk

3.84 MB
Binary file not shown.

android/WikipediaSample.apk

19.4 MB
Binary file not shown.

android/browserstack.yml

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

android/browserstack_sample.py

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,8 @@
55
from selenium.webdriver.support import expected_conditions as EC
66
import time
77

8-
# Options are only available since client version 2.3.0
9-
# If you use an older client then switch to desired_capabilities
10-
# instead: https://github.com/appium/python-client/pull/720
11-
options = UiAutomator2Options().load_capabilities({
12-
# Specify device and os_version for testing
13-
"platformName" : "android",
14-
"platformVersion" : "9.0",
15-
"deviceName" : "Google Pixel 3",
16-
17-
# Set URL of the application under test
18-
"app" : "bs://<app-id>",
19-
20-
# Set other BrowserStack capabilities
21-
'bstack:options' : {
22-
"projectName" : "First Python project",
23-
"buildName" : "browserstack-build-1",
24-
"sessionName" : "BStack first_test",
25-
26-
# Set your access credentials
27-
"userName" : "YOUR_USERNAME",
28-
"accessKey" : "YOUR_ACCESS_KEY"
29-
}
30-
})
31-
328
# Initialize the remote Webdriver using BrowserStack remote URL
33-
# and options defined above
34-
driver = webdriver.Remote("http://hub.browserstack.com/wd/hub", options=options)
9+
driver = webdriver.Remote("http://hub.browserstack.com/wd/hub")
3510

3611
# Test case for the BrowserStack sample Android app.
3712
# If you have uploaded your app, update the test case here.

android/browserstack_sample_local.py

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,51 +6,8 @@
66
from browserstack.local import Local
77
import time
88

9-
# Set your BrowserStack access credentials here
10-
userName = "YOUR_USERNAME"
11-
accessKey = "YOUR_ACCESS_KEY"
12-
13-
# Options are only available since client version 2.3.0
14-
# If you use an older client then switch to desired_capabilities
15-
# instead: https://github.com/appium/python-client/pull/720
16-
options = UiAutomator2Options().load_capabilities({
17-
# Set URL of the application under test
18-
"app" : "bs://<app-id>",
19-
20-
# Specify device and os_version for testing
21-
"deviceName": "Google Pixel 3",
22-
"platformName": "android",
23-
"platformVersion": "9.0",
24-
25-
# Set other BrowserStack capabilities
26-
"bstack:options": {
27-
"userName" : userName,
28-
"accessKey" : accessKey,
29-
"projectName" : "First Python Local project",
30-
"buildName" : "browserstack-build-1",
31-
"sessionName" : "BStack local_test",
32-
"local" : "true"
33-
}
34-
})
35-
36-
bs_local = None
37-
38-
def start_local():
39-
global bs_local
40-
bs_local = Local()
41-
bs_local_args = { "key": accessKey, "forcelocal": "true" }
42-
bs_local.start(**bs_local_args)
43-
44-
def stop_local():
45-
global bs_local
46-
bs_local.stop()
47-
48-
# Start BrowserStack local binary
49-
start_local()
50-
519
# Initialize the remote Webdriver using BrowserStack remote URL
52-
# and options defined above
53-
driver = webdriver.Remote("http://hub.browserstack.com/wd/hub", options=options)
10+
driver = webdriver.Remote("http://hub.browserstack.com/wd/hub")#, options=options)
5411

5512
# Test case for the BrowserStack sample Android app.
5613
# If you have uploaded your app, update the test case here.
@@ -75,5 +32,3 @@ def stop_local():
7532

7633
# Invoke driver.quit() after the test is done to indicate that the test is completed.
7734
driver.quit()
78-
79-
stop_local()

ios/BStackSampleApp.ipa

5.04 MB
Binary file not shown.

ios/LocalSample.ipa

9.08 MB
Binary file not shown.

ios/browserstack.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# =============================
2+
# Set BrowserStack Credentials
3+
# =============================
4+
# Add your BrowserStack userName and acccessKey here or set BROWSERSTACK_USERNAME and
5+
# BROWSERSTACK_ACCESS_KEY as env variables
6+
userName: BROWSERSTACK_USERNAME
7+
accessKey: BROWSERSTACK_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+
source: 'python:appium-sample-sdk:v1.0'
25+
26+
# app: ./BStackSampleApp.ipa
27+
app: ./LocalSample.ipa #For running local tests
28+
29+
# =======================================
30+
# Platforms (Browsers / Devices to test)
31+
# =======================================
32+
# Platforms object contains all the browser / device combinations you want to test on.
33+
# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate)
34+
35+
platforms:
36+
- deviceName: iPhone 14 Pro
37+
osVersion: 16
38+
platformName: ios
39+
- deviceName: iPhone 13 Pro
40+
osVersion: 15
41+
platformName: ios
42+
- deviceName: iPhone XS
43+
osVersion: 14
44+
platformName: ios
45+
46+
# =======================
47+
# Parallels per Platform
48+
# =======================
49+
# The number of parallel threads to be used for each platform set.
50+
# BrowserStack's SDK runner will select the best strategy based on the configured value
51+
#
52+
# 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
53+
#
54+
# 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
55+
parallelsPerPlatform: 1
56+
57+
# ==========================================
58+
# BrowserStack Local
59+
# (For localhost, staging/private websites)
60+
# ==========================================
61+
# Set browserStackLocal to true if your website under test is not accessible publicly over the internet
62+
# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction
63+
browserstackLocal: true # <boolean> (Default false)
64+
#browserStackLocalOptions:
65+
#Options to be passed to BrowserStack local in-case of advanced configurations
66+
# localIdentifier: # <string> (Default: null) Needed if you need to run multiple instances of local.
67+
# forceLocal: true # <boolean> (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel.
68+
# Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections
69+
70+
# ===================
71+
# Debugging features
72+
# ===================
73+
debug: false # <boolean> # Set to true if you need screenshots for every selenium command ran
74+
networkLogs: false # <boolean> Set to true to enable HAR logs capturing
75+
consoleLogs: errors # <string> Remote browser's console debug levels to be printed (Default: errors)
76+
# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors)

ios/browserstack_sample.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,8 @@
55
from selenium.webdriver.support import expected_conditions as EC
66
import time
77

8-
# Options are only available since client version 2.3.0
9-
# If you use an older client then switch to desired_capabilities
10-
# instead: https://github.com/appium/python-client/pull/720
11-
options = XCUITestOptions().load_capabilities({
12-
# Set URL of the application under test
13-
"app" : "bs://<app-id>",
14-
15-
# Specify device and os_version for testing
16-
"deviceName": "iPhone 11 Pro",
17-
"platformName": "ios",
18-
"platformVersion": "13",
19-
20-
# Set other BrowserStack capabilities
21-
"bstack:options": {
22-
"userName" : "YOUR_USERNAME",
23-
"accessKey" : "YOUR_ACCESS_KEY",
24-
"projectName" : "First Python project",
25-
"buildName" : "browserstack-build-1",
26-
"sessionName" : "BStack first_test"
27-
}
28-
})
29-
308
# Initialize the remote Webdriver using BrowserStack remote URL
31-
# and options defined above
32-
driver = webdriver.Remote("http://hub.browserstack.com/wd/hub", options=options)
9+
driver = webdriver.Remote("http://hub.browserstack.com/wd/hub")
3310

3411
# Test case for the BrowserStack sample iOS app.
3512
# If you have uploaded your app, update the test case here.
@@ -51,4 +28,4 @@
5128
assert False
5229

5330
# Invoke driver.quit() after the test is done to indicate that the test is completed.
54-
driver.quit()
31+
driver.quit()

0 commit comments

Comments
 (0)