### Install BrowserStack SDK and Setup Source: https://www.browserstack.com/docs/app-percy/integrate-bstack-sdk/jest Install the BrowserStack Node.js SDK as a development dependency and run the setup command with your credentials. ```shell npm i -D browserstack-node-sdk@latest npx setup --username "YOUR_USERNAME" --key "YOUR_ACCESS_KEY" ``` -------------------------------- ### Install and Start App with Appium (Ruby) Source: https://www.browserstack.com/docs/app-automate/appium/advanced-features/test-app-upgrades Use `execute_script` to install an app and start its activity. The `appPath` parameter should contain the hashed ID of the uploaded app. The upgrade app's URL must be set in the `browserstack.midSessionInstallApps` capability. ```Ruby # Use app_url value passed in the 'browserstack.midSessionInstallApps' capability execute_script("mobile: installApp", { "appPath" => "bs://"}) execute_script("mobile: startActivity",{"intent" => "com.browserstack.sample.MainActivity", "package" => "com.browserstack.sample"}) ``` -------------------------------- ### Install and Start App with Appium (Java) Source: https://www.browserstack.com/docs/app-automate/appium/advanced-features/test-app-upgrades Use `driver.executeScript` to install an app using its hashed ID and then start a specific activity. Ensure the `app_url` for the upgrade is set in the `browserstack.midSessionInstallApps` capability. ```Java driver.executeScript("mobile: installApp",ImmutableMap.of("appPath", "bs://")); HashMap startActivityArgs = new HashMap<>(); startActivityArgs.put("intent", "com.browserstack.sample.MainActivity"); startActivityArgs.put("package", "com.browserstack.sample"); driver.executeScript("mobile:startActivity", startActivityArgs); ``` -------------------------------- ### Install BrowserStack SDK and Setup Source: https://www.browserstack.com/docs/app-accessibility/automated-tests/get-started/nunit/integrate-with-app-automate Install the BrowserStack SDK package and run the setup command to configure your project for BrowserStack testing. Ensure your project uses .NET 8 or below. ```bash dotnet add package BrowserStack.TestAdapter dotnet build dotnet browserstack-sdk setup --userName "YOUR_USERNAME" --accessKey "YOUR_ACCESS_KEY" ``` -------------------------------- ### Install BrowserStack Node SDK and Setup Source: https://www.browserstack.com/docs/automate/selenium/getting-started/nodejs/codecept-js/integrate-your-tests Install the BrowserStack SDK and run the setup command to configure your project with access credentials and update package.json. Ensure Node v12+ is installed. ```bash npm i -D browserstack-node-sdk@latest npx setup --username YOUR_USERNAME --key YOUR_ACCESS_KEY ``` -------------------------------- ### Clone and Install Sample Application Source: https://www.browserstack.com/docs/percy/sample-build/storybook Clone the example Percy Storybook repository and install its dependencies. ```bash git clone https://github.com/percy/example-percy-storybook.git cd example-percy-storybook npm install ``` -------------------------------- ### Clone and Install Sample Application Source: https://www.browserstack.com/docs/percy/sample-build/capybara Clone the example Capybara application and install its dependencies. ```bash git clone https://github.com/percy/example-percy-capybara.git cd example-percy-capybara make install ``` -------------------------------- ### Install and Start App with Appium (Node.js) Source: https://www.browserstack.com/docs/app-automate/appium/advanced-features/test-app-upgrades Execute Appium commands to install an app and start its activity. The `appPath` capability should reference the uploaded app's hashed ID. The upgrade app's URL must be configured in `browserstack.midSessionInstallApps`. ```JavaScript driver.execute("mobile: installApp", {appPath: "bs://"}); driver.execute("mobile: startActivity", {intent: "com.browserstack.sample.MainActivity", package:"com.browserstack.sample"}); ``` -------------------------------- ### Clone Sample App and Install Dependencies Source: https://www.browserstack.com/docs/app-percy/sample-build/espresso Clone the sample application repository and navigate into the project directory. This sets up the necessary files for your build. ```bash git clone https://github.com/percy/example-percy-espresso-java.git cd example-percy-espresso-java ``` -------------------------------- ### Clone Sample Repository Source: https://www.browserstack.com/docs/automate/selenium/getting-started/python/lettuce/run-tests-in-parallel Clone the lettuce-browserstack sample repository to get started with parallel testing setup. This is the initial step before installing dependencies and configuring your tests. ```bash git clone https://github.com/browserstack/lettuce-browserstack.git cd lettuce-browserstack ``` -------------------------------- ### Install and Start App with Appium (PHP) Source: https://www.browserstack.com/docs/app-automate/appium/advanced-features/test-app-upgrades Use the `installApp` and `startActivity` methods to manage app installations and launches within a test session. The `app_url` for the upgrade must be set in the `browserstack.midSessionInstallApps` capability. ```PHP $driver->installApp('bs://'); $driver->startActivity(array('appPackage' => 'com.browserstack.sample', 'appActivity' => 'com.browserstack.sample.MainActivity')); ``` -------------------------------- ### Clone Sample Repository and Install Dependencies Source: https://www.browserstack.com/docs/automate/selenium/getting-started/nodejs/codecept-js Clone the BrowserStack CodeceptJS sample repository and install its dependencies to get started. ```bash git clone https://github.com/browserstack/codecept-js-browserstack.git cd codecept-js-browserstack npm install ``` -------------------------------- ### Set up JS Unit Test Environment Source: https://www.browserstack.com/docs/automate/javascript-testing/run-first-js-unit-test Create a new directory, initialize npm, and install QUnit globally or locally. ```bash # Create a new directory for the tutorial mkdir browserstack_js_unit_test cd browserstack_js_unit_test # Install Qunit. Remove -g if you don't want to install it globally. npm init npm install -g qunit ``` -------------------------------- ### Clone Sample Repository and Install Dependencies Source: https://www.browserstack.com/docs/automate/selenium/getting-started/nodejs/jest-js Clone the BrowserStack JestJS sample repository and install the necessary npm packages to get started. ```bash git clone -b tra https://github.com/browserstack/jest-js-browserstack.git cd jest-js-browserstack npm install ``` -------------------------------- ### Navigate to the sample project directory Source: https://www.browserstack.com/docs/app-accessibility/automated-tests/get-started/cucumber-testng/run-checks-on-sample-repo Navigate to the appropriate platform directory (Android or iOS) within the cloned repository. ```bash cd testng-appium-app-browserstack/android/testng-examples ``` ```bash cd testng-appium-app-browserstack/ios/testng-examples ``` -------------------------------- ### Clone repository and install dependencies Source: https://www.browserstack.com/docs/automate/puppeteer/jest Clone the sample repository and install npm dependencies to get started with Jest Puppeteer tests on BrowserStack. ```bash git clone https://github.com/browserstack/puppeteer-browserstack.git cd puppeteer-browserstack/puppeteer-jest npm install ``` -------------------------------- ### Clone repository and install dependencies Source: https://www.browserstack.com/docs/automate/playwright/cucumber-typescript Clone the sample repository and install necessary npm dependencies to get started with TypeScript Playwright tests. ```bash git clone https://github.com/browserstack/typescript-playwright-browserstack.git cd typescript-playwright-browserstack npm i ``` -------------------------------- ### Clone Sample App and Install Dependencies Source: https://www.browserstack.com/docs/app-percy/sample-build/xcuitest Clone the sample application repository and navigate into its directory. This sets up the project for visual testing. ```bash git clone https://github.com/percy/example-percy-xcui-swift.git cd example-percy-xcui-swift ``` -------------------------------- ### Initial browserstack.yml Setup Source: https://www.browserstack.com/docs/automate-turboscale/integrate-with-cloud-hosted-solution/selenium/java/junit This is an initial example of the `browserstack.yml` file. Replace placeholders with your actual BrowserStack credentials and desired configuration. ```yml userName: YOUR_USERNAME accessKey: YOUR_ACCESS_KEY framework: junit4 platforms: - os: Linux browserName: Firefox browserVersion: latest parallelsPerPlatform: 1 YOUR_LOCAL_CAPS_TYPE: YOUR_LOCAL_CAPS YOUR_BUILD_NAME_TYPE: YOUR_BUILD_NAME YOUR_BUILD_IDENTIFIER_KEY: YOUR_BUILD_IDENTIFIER_TYPE YOUR_PROJECT_NAME_TYPE: YOUR_PROJECT_NAME YOUR_DEBUG_CAPS_TYPE: YOUR_DEBUG_CAPS YOUR_NETWORK_CAPS_TYPE: YOUR_NETWORK_CAPS YOUR_CONSOLE_CAPS_TYPE: YOUR_CONSOLE_CAPS turboScale: YOUR_TURBOSCALE_CAPS turboScaleOptions: gridName: YOUR_GRID_NAME ``` -------------------------------- ### Clone Sample Repository and Install Dependencies Source: https://www.browserstack.com/docs/automate/playwright/codeceptjs Clone the provided GitHub repository and install the necessary npm dependencies to get started with CodeceptJS Playwright tests. ```bash git clone https://github.com/browserstack/playwright-browserstack.git cd playwright-browserstack/codeceptjs-example npm install ``` -------------------------------- ### Clone Sample Python Repository Source: https://www.browserstack.com/docs/automate/selenium/getting-started/python Clone the sample Python project from GitHub to get started. Ensure you have Git installed. ```bash # clone sample Python repository git clone -b main https://github.com/browserstack/python-selenium-browserstack cd python-selenium-browserstack ``` -------------------------------- ### Clone and Install Sample Application Source: https://www.browserstack.com/docs/percy/sample-build/selenium/python Clone the sample application repository and install its dependencies. ```bash git clone https://github.com/percy/example-percy-python-selenium.git cd example-percy-python-selenium make install ``` -------------------------------- ### Clone and Install Sample Application Source: https://www.browserstack.com/docs/percy/sample-build/selenium/javascript Clone the sample application repository and install its dependencies. ```bash git clone https://github.com/percy/example-percy-selenium-javascript.git cd example-percy-selenium-javascript npm install ``` -------------------------------- ### Clone Capybara-BrowserStack Repository Source: https://www.browserstack.com/docs/automate/selenium/getting-started/ruby/capybara Clone the sample repository to get started with Capybara tests on BrowserStack. Ensure Git is installed on your machine. ```bash git clone https://github.com/browserstack/capybara-browserstack.git ``` -------------------------------- ### Clone Sample Repository Source: https://www.browserstack.com/docs/automate/selenium/getting-started/ruby/capybara/run-tests-in-parallel Clone the provided sample repository to get started with parallel Capybara tests. Navigate into the cloned directory to proceed with setup. ```bash git clone https://github.com/browserstack/capybara-browserstack.git cd capybara-browserstack ``` -------------------------------- ### Python Example for Testing App Upgrades Source: https://www.browserstack.com/docs/app-automate/appium/advanced-features/test-app-upgrades This Python script shows how to test app upgrades. It sets up desired capabilities, terminates the app, installs the updated version, and then starts the activity. Ensure you have the Appium Python client installed. ```python from appium import webdriver def test_app_upgrade(): desired_caps = { 'platformName': 'Android', 'platformVersion': '9.0', 'deviceName': 'Google Pixel 3', 'app': 'bs://', 'bstack:options': {'midSessionInstallApps': ['bs://']} } driver = webdriver.Remote( command_executor='https://hub.browserstack.com/wd/hub', desired_capabilities=desired_caps, username= 'YOUR_BROWSERSTACK_USERNAME', access_key= 'YOUR_BROWSERSTACK_ACCESS_KEY' ) try: # Your test with v1.0 goes here # Close the app under test driver.terminate_app('com.browserstack.sample') driver.execute_script('mobile:terminateApp', {'appId': 'com.browserstack.sample'}) # Install the upgrade version of the app driver.execute_script('mobile:installApp', {'appPath': 'bs://'}) # Launch the app using the package and launcher activity of the app driver.execute_script('mobile:startActivity', {'intent': 'com.browserstack.sample.MainActivity', 'package': 'com.browserstack.sample'}) # Your test with upgrade version v1.1 goes here finally: driver.quit() test_app_upgrade() ``` -------------------------------- ### Clone and Install Sample Application Source: https://www.browserstack.com/docs/percy/sample-build/selenium/dotnet Clone the sample application repository and install its dependencies. Ensure Node.js and .NET Core are installed. ```bash git clone https://github.com/percy/example-percy-dotnet-selenium.git cd example-percy-dotnet-selenium make install ``` -------------------------------- ### Clone Sample Application and Build Source: https://www.browserstack.com/docs/percy/selenium/getting-started/c-sharp Clone the sample repository and install dependencies using these commands. ```bash git clone https://github.com/percy/example-percy-automate-selenium-dotnet.git cd example-percy-automate-selenium-dotnet donet build ``` -------------------------------- ### Clone Sample Repository Source: https://www.browserstack.com/docs/app-automate/appium/getting-started/java/selenide/local-testing Clone the provided sample repository to get started with local testing. This repository contains the necessary setup for Selenide and Appium with BrowserStack. ```bash git clone https://github.com/browserstack/selenide-appium-app-browserstack cd selenide-appium-app-browserstack ``` -------------------------------- ### Clone Sample JUnit Project Source: https://www.browserstack.com/docs/automate/selenium/getting-started/java/junit Clone the sample JUnit project from the BrowserStack GitHub repository to get started quickly. This provides a pre-configured setup for running tests. ```bash git clone https://github.com/browserstack/junit-browserstack.git cd junit-browserstack/junit-4 ``` -------------------------------- ### Setup Sample Project using Maven Archetype Source: https://www.browserstack.com/docs/app-automate/appium/getting-started/java/cucumber Set up a new sample project with pre-configured BrowserStack credentials using the Maven archetype. ```bash mvn archetype:generate -B -DarchetypeGroupId=com.browserstack \ -DarchetypeArtifactId=browserstack-sdk-archetype-setup -DarchetypeVersion=1.1 \ -DgroupId=com.browserstack -DartifactId=cucumber-browserstack -Dversion=1.0 \ -DBROWSERSTACK_USERNAME=YOUR_USERNAME -DBROWSERSTACK_ACCESS_KEY=YOUR_ACCESS_KEY -DBROWSERSTACK_PROJECT_REPO=cucumber-browserstack cd cucumber-browserstack ``` ```bash mvn archetype:generate -B -DarchetypeGroupId="com.browserstack" -DarchetypeArtifactId="browserstack-sdk-archetype-setup" -DarchetypeVersion="1.1" -DgroupId="com.browserstack" -DartifactId="cucumber-browserstack" -Dversion="1.0" -DBROWSERSTACK_USERNAME="YOUR_USERNAME" -DBROWSERSTACK_ACCESS_KEY="YOUR_ACCESS_KEY" -DBROWSERSTACK_PROJECT_REPO="cucumber-browserstack"; cd cucumber-browserstack ``` ```bash mvn archetype:generate -B -DarchetypeGroupId="com.browserstack" -DarchetypeArtifactId="browserstack-sdk-archetype-setup" -DarchetypeVersion="1.1" -DgroupId="com.browserstack" -DartifactId="cucumber-browserstack" -Dversion="1.0" -DBROWSERSTACK_USERNAME="YOUR_USERNAME" -DBROWSERSTACK_ACCESS_KEY="YOUR_ACCESS_KEY" -DBROWSERSTACK_PROJECT_REPO="cucumber-browserstack" && cd cucumber-browserstack ``` -------------------------------- ### Set Up Python Virtual Environment and Install Dependencies Source: https://www.browserstack.com/docs/app-automate/appium/getting-started/python/behave Create a Python virtual environment and activate it. Then, install the required dependencies using pip. ```bash python3 -m venv env source env/bin/activate pip3 install -r requirements.txt ``` ```bash python3 -m venv env .\env\Scripts\Activate.ps1 pip3 install -r requirements.txt ``` -------------------------------- ### Configure GitLab CI for BrowserStack Local (Python) Source: https://www.browserstack.com/docs/app-automate/appium/integrations/gitlab This `before_script` setup for Python in `.gitlab-ci.yml` includes creating a virtual environment, installing Selenium, and then downloading and starting the BrowserStack Local binary. ```yaml before_script: - python -V # Print out python version for debugging - pip install virtualenv - virtualenv venv - source venv/bin/activate - pip install selenium # Download the browserstack binary file - wget "https://local-downloads.browserstack.com/BrowserStackLocal-linux-x64.zip" #For OS X systems, use the following command # install zip unzip bash file - apt-get install zip unzip # Unzip the BrowserStack Local binary file - unzip BrowserStackLocal-linux-x64.zip # Run the file with your access key - ./BrowserStackLocal --key $BROWSERSTACK_ACCESS_KEY --daemon start ``` -------------------------------- ### Fetch All Configurations Response Source: https://www.browserstack.com/docs/test-management/api-reference/configurations Example response when fetching all configurations, showing system and custom configurations with their details. ```json { "success": true, "configurations": [ { "id": 5122204, "name": "testing_config", "os": null, "os_version": null, "device": null, "browser": null, "browser_version": null, "is_system": false }, { "id": 4490607, "name": "iOS - iPhone 13 latest", "os": "iOS", "os_version": "", "device": "iPhone 13", "browser": "", "browser_version": "latest", "is_system": false } ], "info": { "page": 1, "page_size": 30, "count": 20, "prev": null, "next": null } } ``` -------------------------------- ### Clone BrowserStack Sample Project Source: https://www.browserstack.com/docs/automate/selenium/getting-started/integrate-your-tests-legacy Clone the BrowserStack sample project from GitHub using Git to get a pre-configured setup for running tests. This is a quick way to start integrating your tests with BrowserStack. ```bash git clone https://github.com/browserstack/testng-browserstack.git cd testng-browserstack ``` -------------------------------- ### Get Current Platform Details in Node.js Source: https://www.browserstack.com/docs/app-automate/appium/sdk-faqs/generic/custom-variables This Node.js example demonstrates retrieving current platform details using `BrowserStackSdk.getCurrentPlatform()`. It's part of a Selenium WebDriver test setup and logs the platform information. ```javascript var assert = require('assert'); const { Builder, Capabilities } = require("selenium-webdriver"); const { BrowserStackSdk } = require("browserstack-node-sdk"); var buildDriver = function() { return new Builder(). usingServer('http://localhost:4444/wd/hub'). withCapabilities(Capabilities.chrome()). build(); }; describe('BStack Local Testing', async function() { this.timeout(0); var driver; before(function() { driver = buildDriver(); }); it('check tunnel is working', async function() { console.log(BrowserStackSdk.getCurrentPlatform()); await driver.get('http://bs-local.com:45454/'); let title = await driver.getTitle(); assert(title.match(/BrowserStack Local/i) != null); }); after(async function() { await driver.quit(); }); }); ``` -------------------------------- ### Execute Sample Test on iOS Source: https://www.browserstack.com/docs/app-automate/appium/getting-started/nodejs/cucumber-js/local-testing Navigate to the `ios` directory, install dependencies, and run the sample local test for iOS. ```bash cd ios npm install npm run sample-local-test ``` -------------------------------- ### Set up dependencies Source: https://www.browserstack.com/docs/automate/playwright/getting-started/nodejs/local-testing Install the required Node.js dependencies for the project. ```bash npm i ``` -------------------------------- ### Install BrowserStack SDK and Setup (Windows) Source: https://www.browserstack.com/docs/test-observability/quick-start/nunit Install the BrowserStack.TestAdapter package, enable test observability, and set up the BrowserStack SDK using the command line on Windows. ```bash dotnet add package BrowserStack.TestAdapter setx BROWSERSTACK_TEST_OBSERVABILITY "true" set BROWSERSTACK_TEST_OBSERVABILITY "true" dotnet build dotnet browserstack-sdk setup --userName "YOUR_USERNAME" --accessKey "YOUR_ACCESS_KEY" ``` -------------------------------- ### Install BrowserStack SDK and Setup Source: https://www.browserstack.com/docs/test-observability/quick-start/cucumberjs Install the latest version of the browserstack-node-sdk npm package and run the setup command to configure your access credentials and package.json. ```bash npm install browserstack-node-sdk@latest npx setup --username 'YOUR_USERNAME' --key 'YOUR_ACCESS_KEY' ``` -------------------------------- ### Start Application Server Source: https://www.browserstack.com/docs/automate/cypress/run-your-first-test-old Start the application server using the npm start script. ```bash npm start ``` -------------------------------- ### Install and Start App with Appium (Python) Source: https://www.browserstack.com/docs/app-automate/appium/advanced-features/test-app-upgrades Employ `driver.execute_script` to install an app and initiate its activity. The `appPath` should be the hashed ID of the uploaded app. Ensure the upgrade app's URL is configured in `browserstack.midSessionInstallApps`. ```Python # Use app_url value passed in the 'browserstack.midSessionInstallApps' capability driver.execute_script("mobile: installApp", {"appPath": "bs://"}); driver.execute_script("mobile: startActivity", {"intent": "com.browserstack.sample.MainActivity", "package":"com.browserstack.sample"}); ``` -------------------------------- ### Install Dependencies for JUnit Examples Source: https://www.browserstack.com/docs/app-automate/appium/getting-started/java/junit-5/local-testing-legacy Execute these Maven commands to install required dependencies for testing Android or iOS apps using JUnit 5 examples. ```bash # Test an android app cd android/junit5-examples mvn clean # Test an iOS app cd ios/junit5-examples mvn clean ``` -------------------------------- ### Clone and Set Up Sample Application Source: https://www.browserstack.com/docs/percy/playwright/getting-started/python Clone the sample application repository, set up a virtual environment, and install dependencies. This prepares your local environment for running Percy tests. ```bash git clone https://github.com/percy/example-percy-playwright-python.git cd example-percy-playwright-python # create virtual environment python3 -m venv env source env/bin/activate # update the pip if not updated already using [python3 -m pip install --upgrade pip] # install the required packages pip3 install -r requirements.txt npm install ```