Skip to content

Commit c5dfea7

Browse files
authored
Merge pull request #16 from browserstack/merge_sdk_to_master
Merge sdk to master
2 parents 2e4493e + 0d32d29 commit c5dfea7

12 files changed

+176
-165
lines changed

README.md

Lines changed: 8 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -54,71 +54,27 @@ To install the dependencies, run the following command in project's base directo
5454
5555
Getting Started with Appium tests in Python on BrowserStack couldn't be easier!
5656

57-
### Run your first test :
57+
### **Run your first test :**
5858

59-
**1. Upload your Android or iOS App**
59+
Open `Android` or `iOS` folder :
6060

61-
Upload your Android app (.apk or .aab file) or iOS app (.ipa file) to BrowserStack servers using our REST API. Here is an example cURL request :
61+
- If you have uploaded your app then add the app id to the `browserstack.yml` config file, or you can directly specify the path to your app in the `browserstack.yml` file.
6262

63-
```
64-
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
65-
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
66-
-F "file=@/path/to/apk/file"
67-
```
68-
69-
Ensure that @ symbol is prepended to the file path in the above request. Please note the `app_url` value returned in the API response. We will use this to set the application under test while configuring the test later on.
70-
71-
**Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android app](https://www.browserstack.com/app-automate/sample-apps/android/WikipediaSample.apk) or [sample iOS app](https://www.browserstack.com/app-automate/sample-apps/ios/BStackSampleApp.ipa).
72-
73-
**2. Configure and run your first test**
74-
75-
Open `browserstack_sample.py` file in `Android` or `iOS` folder :
76-
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)
78-
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`
63+
- Run `browserstack-sdk python browserstack_sample.py`
8664

8765
- 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)
8866

8967
---
9068

9169
### **Use Local testing for apps that access resources hosted in development or testing environments :**
9270

93-
**1. Upload your Android or iOS App**
94-
95-
Upload your Android app (.apk or .aab file) or iOS app (.ipa file) that access resources hosted on your internal or test environments to BrowserStack servers using our REST API. Here is an example cURL request :
96-
97-
```
98-
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
99-
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
100-
-F "file=@/path/to/apk/file"
101-
```
102-
103-
Ensure that @ symbol is prepended to the file path in the above request. Please note the `app_url` value returned in the API response. We will use this to set the application under test while configuring the test later on.
104-
105-
**Note**: If you do not have an .apk or .ipa file and are looking to simply try App Automate, you can download and test using our [sample Android Local app](https://www.browserstack.com/app-automate/sample-apps/android/LocalSample.apk) or [sample iOS Local app](https://www.browserstack.com/app-automate/sample-apps/ios/LocalSample.ipa).
106-
107-
**2. Configure and run your local test**
108-
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
71+
Open `Android` or `iOS` folder :
11672

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.
73+
- Ensure that `browserstackLocal` capability is set to `true` in the `browserstack.yml` file
11874

119-
- If you have uploaded your own app update the test case
75+
- If you have uploaded your app then add the app id to the `browserstack.yml` config file, or you can directly specify the path to your app in the `browserstack.yml` file.
12076

121-
- Run `python browserstack_sample_local.py`
77+
- Run `browserstack-sdk python browserstack_sample_local.py`
12278

12379
- 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)
12480

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

android/browserstack_sample.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,12 @@
1212
# Specify device and os_version for testing
1313
"platformName" : "android",
1414
"platformVersion" : "9.0",
15-
"deviceName" : "Google Pixel 3",
15+
"deviceName" : "Google Pixel 3"
1616

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-
}
17+
# Add your caps here
3018
})
3119

32-
# 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)
20+
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", options=options)
3521

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

android/browserstack_sample_local.py

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,21 @@
33
from appium.webdriver.common.appiumby import AppiumBy
44
from selenium.webdriver.support.ui import WebDriverWait
55
from selenium.webdriver.support import expected_conditions as EC
6-
from browserstack.local import Local
76
import time
87

9-
# Set your BrowserStack access credentials here
10-
userName = "YOUR_USERNAME"
11-
accessKey = "YOUR_ACCESS_KEY"
12-
138
# Options are only available since client version 2.3.0
149
# If you use an older client then switch to desired_capabilities
1510
# instead: https://github.com/appium/python-client/pull/720
1611
options = UiAutomator2Options().load_capabilities({
17-
# Set URL of the application under test
18-
"app" : "bs://<app-id>",
19-
2012
# Specify device and os_version for testing
2113
"deviceName": "Google Pixel 3",
2214
"platformName": "android",
2315
"platformVersion": "9.0",
2416

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-
}
17+
# Add your caps here
3418
})
3519

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-
51-
# 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)
20+
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", options=options)
5421

5522
# Test case for the BrowserStack sample Android app.
5623
# If you have uploaded your app, update the test case here.
@@ -75,5 +42,3 @@ def stop_local():
7542

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

ios/browserstack_sample.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,15 @@
99
# If you use an older client then switch to desired_capabilities
1010
# instead: https://github.com/appium/python-client/pull/720
1111
options = XCUITestOptions().load_capabilities({
12-
# Set URL of the application under test
13-
"app" : "bs://<app-id>",
14-
1512
# Specify device and os_version for testing
1613
"deviceName": "iPhone 11 Pro",
1714
"platformName": "ios",
1815
"platformVersion": "13",
1916

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-
}
17+
# Add your caps here
2818
})
2919

30-
# 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)
20+
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", options=options)
3321

3422
# Test case for the BrowserStack sample iOS app.
3523
# If you have uploaded your app, update the test case here.
@@ -51,4 +39,4 @@
5139
assert False
5240

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

0 commit comments

Comments
 (0)