Skip to content

Commit

Permalink
Merge pull request #16 from browserstack/merge_sdk_to_master
Browse files Browse the repository at this point in the history
Merge sdk to master
  • Loading branch information
yashdsaraf authored Jul 3, 2024
2 parents 2e4493e + 0d32d29 commit c5dfea7
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 165 deletions.
60 changes: 8 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,71 +54,27 @@ To install the dependencies, run the following command in project's base directo
Getting Started with Appium tests in Python on BrowserStack couldn't be easier!

### Run your first test :
### **Run your first test :**

**1. Upload your Android or iOS App**
Open `Android` or `iOS` folder :

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 :
- 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.

```
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
-F "file=@/path/to/apk/file"
```
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.
**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).
**2. Configure and run your first test**
Open `browserstack_sample.py` file in `Android` or `iOS` folder :
- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings)
- Replace `bs://<app-id>` wkth the URL obtained from app upload step
- Set the device and OS version
- If you have uploaded your own app update the test case
- Run `python browserstack_sample.py`
- Run `browserstack-sdk python browserstack_sample.py`

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

---

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

**1. Upload your Android or iOS App**
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 :
```
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
-F "file=@/path/to/apk/file"
```
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.
**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).
**2. Configure and run your local test**
Open `browserstack_sample_local` file in `Android` or `iOS` folder :
- Replace `YOUR_USERNAME` & `YOUR_ACCESS_KEY` with your BrowserStack access credentials. Get your BrowserStack access credentials from [here](https://www.browserstack.com/accounts/settings)
- Replace `bs://<app-id>` wkth the URL obtained from app upload step
- Set the device and OS version
Open `Android` or `iOS` folder :

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

- If you have uploaded your own app update the test case
- 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.

- Run `python browserstack_sample_local.py`
- Run `browserstack-sdk python browserstack_sample_local.py`

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

Expand Down
Binary file added android/LocalSample.apk
Binary file not shown.
Binary file added android/WikipediaSample.apk
Binary file not shown.
78 changes: 78 additions & 0 deletions android/browserstack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# =============================
# Set BrowserStack Credentials
# =============================
# Add your BrowserStack userName and acccessKey here or set BROWSERSTACK_USERNAME and
# BROWSERSTACK_ACCESS_KEY as env variables
userName: BROWSERSTACK_USERNAME
accessKey: BROWSERSTACK_ACCESS_KEY

# ======================
# BrowserStack Reporting
# ======================
# The following capabilities are used to set up reporting on BrowserStack:
# Set 'projectName' to the name of your project. Example, Marketing Website
projectName: BrowserStack Samples
# Set `buildName` as the name of the job / testsuite being run
buildName: browserstack build
# `buildIdentifier` is a unique id to differentiate every execution that gets appended to
# buildName. Choose your buildIdentifier format from the available expressions:
# ${BUILD_NUMBER} (Default): Generates an incremental counter with every execution
# ${DATE_TIME}: Generates a Timestamp with every execution. Eg. 05-Nov-19:30
# Read more about buildIdentifiers here -> https://www.browserstack.com/docs/automate/selenium/organize-tests
buildIdentifier: '#${BUILD_NUMBER}' # Supports strings along with either/both ${expression}

source: 'python:appium-sample-sdk:v1.0'

# Set `app` to define the app that is to be used for testing.
# It can either take the id of any uploaded app or the path of the app directly.
app: ./WikipediaSample.apk
# app: ./LocalSample.apk #For running local tests

# =======================================
# Platforms (Browsers / Devices to test)
# =======================================
# Platforms object contains all the browser / device combinations you want to test on.
# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate)

platforms:
- deviceName: Samsung Galaxy S22 Ultra
osVersion: 12.0
platformName: android
- deviceName: Samsung Galaxy S21
osVersion: 11.0
platformName: android
- deviceName: Google Pixel 6 Pro
osVersion: 12.0
platformName: android

# =======================
# Parallels per Platform
# =======================
# The number of parallel threads to be used for each platform set.
# BrowserStack's SDK runner will select the best strategy based on the configured value
#
# 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
#
# 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
parallelsPerPlatform: 1

# ==========================================
# BrowserStack Local
# (For localhost, staging/private websites)
# ==========================================
# Set browserStackLocal to true if your website under test is not accessible publicly over the internet
# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction
browserstackLocal: true # <boolean> (Default false)
#browserStackLocalOptions:
#Options to be passed to BrowserStack local in-case of advanced configurations
# localIdentifier: # <string> (Default: null) Needed if you need to run multiple instances of local.
# forceLocal: true # <boolean> (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel.
# Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections

# ===================
# Debugging features
# ===================
debug: false # <boolean> # Set to true if you need screenshots for every selenium command ran
networkLogs: false # <boolean> Set to true to enable HAR logs capturing
consoleLogs: errors # <string> Remote browser's console debug levels to be printed (Default: errors)
# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors)
20 changes: 3 additions & 17 deletions android/browserstack_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,12 @@
# Specify device and os_version for testing
"platformName" : "android",
"platformVersion" : "9.0",
"deviceName" : "Google Pixel 3",
"deviceName" : "Google Pixel 3"

# Set URL of the application under test
"app" : "bs://<app-id>",

# Set other BrowserStack capabilities
'bstack:options' : {
"projectName" : "First Python project",
"buildName" : "browserstack-build-1",
"sessionName" : "BStack first_test",

# Set your access credentials
"userName" : "YOUR_USERNAME",
"accessKey" : "YOUR_ACCESS_KEY"
}
# Add your caps here
})

# Initialize the remote Webdriver using BrowserStack remote URL
# and options defined above
driver = webdriver.Remote("http://hub.browserstack.com/wd/hub", options=options)
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", options=options)

# Test case for the BrowserStack sample Android app.
# If you have uploaded your app, update the test case here.
Expand Down
39 changes: 2 additions & 37 deletions android/browserstack_sample_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,21 @@
from appium.webdriver.common.appiumby import AppiumBy
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from browserstack.local import Local
import time

# Set your BrowserStack access credentials here
userName = "YOUR_USERNAME"
accessKey = "YOUR_ACCESS_KEY"

# Options are only available since client version 2.3.0
# If you use an older client then switch to desired_capabilities
# instead: https://github.com/appium/python-client/pull/720
options = UiAutomator2Options().load_capabilities({
# Set URL of the application under test
"app" : "bs://<app-id>",

# Specify device and os_version for testing
"deviceName": "Google Pixel 3",
"platformName": "android",
"platformVersion": "9.0",

# Set other BrowserStack capabilities
"bstack:options": {
"userName" : userName,
"accessKey" : accessKey,
"projectName" : "First Python Local project",
"buildName" : "browserstack-build-1",
"sessionName" : "BStack local_test",
"local" : "true"
}
# Add your caps here
})

bs_local = None

def start_local():
global bs_local
bs_local = Local()
bs_local_args = { "key": accessKey, "forcelocal": "true" }
bs_local.start(**bs_local_args)

def stop_local():
global bs_local
bs_local.stop()

# Start BrowserStack local binary
start_local()

# Initialize the remote Webdriver using BrowserStack remote URL
# and options defined above
driver = webdriver.Remote("http://hub.browserstack.com/wd/hub", options=options)
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", options=options)

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

# Invoke driver.quit() after the test is done to indicate that the test is completed.
driver.quit()

stop_local()
Binary file added ios/BStackSampleApp.ipa
Binary file not shown.
Binary file added ios/LocalSample.ipa
Binary file not shown.
78 changes: 78 additions & 0 deletions ios/browserstack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# =============================
# Set BrowserStack Credentials
# =============================
# Add your BrowserStack userName and acccessKey here or set BROWSERSTACK_USERNAME and
# BROWSERSTACK_ACCESS_KEY as env variables
userName: BROWSERSTACK_USERNAME
accessKey: BROWSERSTACK_ACCESS_KEY

# ======================
# BrowserStack Reporting
# ======================
# The following capabilities are used to set up reporting on BrowserStack:
# Set 'projectName' to the name of your project. Example, Marketing Website
projectName: BrowserStack Samples
# Set `buildName` as the name of the job / testsuite being run
buildName: browserstack build
# `buildIdentifier` is a unique id to differentiate every execution that gets appended to
# buildName. Choose your buildIdentifier format from the available expressions:
# ${BUILD_NUMBER} (Default): Generates an incremental counter with every execution
# ${DATE_TIME}: Generates a Timestamp with every execution. Eg. 05-Nov-19:30
# Read more about buildIdentifiers here -> https://www.browserstack.com/docs/automate/selenium/organize-tests
buildIdentifier: '#${BUILD_NUMBER}' # Supports strings along with either/both ${expression}

source: 'python:appium-sample-sdk:v1.0'

# Set `app` to define the app that is to be used for testing.
# It can either take the id of any uploaded app or the path of the app directly.
app: ./BStackSampleApp.ipa
# app: ./LocalSample.ipa #For running local tests

# =======================================
# Platforms (Browsers / Devices to test)
# =======================================
# Platforms object contains all the browser / device combinations you want to test on.
# Entire list available here -> (https://www.browserstack.com/list-of-browsers-and-platforms/automate)

platforms:
- deviceName: iPhone 14 Pro
osVersion: 16
platformName: ios
- deviceName: iPhone 13 Pro
osVersion: 15
platformName: ios
- deviceName: iPhone XS
osVersion: 14
platformName: ios

# =======================
# Parallels per Platform
# =======================
# The number of parallel threads to be used for each platform set.
# BrowserStack's SDK runner will select the best strategy based on the configured value
#
# 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
#
# 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
parallelsPerPlatform: 1

# ==========================================
# BrowserStack Local
# (For localhost, staging/private websites)
# ==========================================
# Set browserStackLocal to true if your website under test is not accessible publicly over the internet
# Learn more about how BrowserStack Local works here -> https://www.browserstack.com/docs/automate/selenium/local-testing-introduction
browserstackLocal: true # <boolean> (Default false)
#browserStackLocalOptions:
#Options to be passed to BrowserStack local in-case of advanced configurations
# localIdentifier: # <string> (Default: null) Needed if you need to run multiple instances of local.
# forceLocal: true # <boolean> (Default: false) Set to true if you need to resolve all your traffic via BrowserStack Local tunnel.
# Entire list of arguments available here -> https://www.browserstack.com/docs/automate/selenium/manage-incoming-connections

# ===================
# Debugging features
# ===================
debug: false # <boolean> # Set to true if you need screenshots for every selenium command ran
networkLogs: false # <boolean> Set to true to enable HAR logs capturing
consoleLogs: errors # <string> Remote browser's console debug levels to be printed (Default: errors)
# Available options are `disable`, `errors`, `warnings`, `info`, `verbose` (Default: errors)
18 changes: 3 additions & 15 deletions ios/browserstack_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,15 @@
# If you use an older client then switch to desired_capabilities
# instead: https://github.com/appium/python-client/pull/720
options = XCUITestOptions().load_capabilities({
# Set URL of the application under test
"app" : "bs://<app-id>",

# Specify device and os_version for testing
"deviceName": "iPhone 11 Pro",
"platformName": "ios",
"platformVersion": "13",

# Set other BrowserStack capabilities
"bstack:options": {
"userName" : "YOUR_USERNAME",
"accessKey" : "YOUR_ACCESS_KEY",
"projectName" : "First Python project",
"buildName" : "browserstack-build-1",
"sessionName" : "BStack first_test"
}
# Add your caps here
})

# Initialize the remote Webdriver using BrowserStack remote URL
# and options defined above
driver = webdriver.Remote("http://hub.browserstack.com/wd/hub", options=options)
driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", options=options)

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

# Invoke driver.quit() after the test is done to indicate that the test is completed.
driver.quit()
driver.quit()
Loading

0 comments on commit c5dfea7

Please sign in to comment.