• Stars
    star
    130
  • Rank 277,575 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

BrowserStack Runner

Build Status

A command line interface to run browser tests over BrowserStack.

Usage

Install globally:

npm -g install browserstack-runner

Then, after setting up the configuration, run tests with:

browserstack-runner

You can also install locally and run the local binary:

npm install browserstack-runner
node_modules/.bin/browserstack-runner

If you're getting an error EACCES open ... BrowserStackLocal, configure npm to install modules using something other than the default "nobody" user:

npm -g config set user [user]

Where [user] is replaced with a local user with enough permissions.

CLI options:

--path: Can be used if a different test runner is needed other than the one present in the browserstack.json file.

--pid: Custom pid file that stores the pid's of the BrowserStackLocal instances created.

--verbose or -v: For verbose logging.

--browsers or -b: Space separated list of cli_key as defined in the browserstack.json file. This will run tests on the selected browsers only. If not present tests will run on all browsers present in the configuration file.

Sample Usage: browserstack_runner --browsers 1 2 3 --path 'path/to/test/runner' --pid 'path/to/pid/file' -v

Usage as a module

browserstack-runner can also be used as a module. To run your tests, inside your project do -

var browserstackRunner = require("browserstack-runner");

var config = require("./browserstack.json");

browserstackRunner.run(config, function(error, report) {
  if (error) {
    console.log("Error:" + error);
    return;
  }
  console.log(JSON.stringify(report, null, 2));
  console.log("Test Finished");
});

The callback to browserstackRunner.run is called with two params -

  • error: This parameter is either null or an Error object (if test execution failed) with message as the reason of why executing the tests on BrowserStack failed.
  • report: This is an array which can be used to keep track of the executed tests and suites in a run. Each object in the array has the following keys -
    • browser: The name of the browser the test executed on.
    • tests: An array of Test objects. The Test Objects are described here
    • suites: A global Suite Object as described here

The structure of the report object is as follows -

[
  {
    "browser": "Windows 7, Firefox 47.0",
    "tests": [
      {
        "name": "isOdd()",
        "suiteName": "Odd Tests",
        "fullName": ["Odd Tests", "isOdd()"],
        "status": "passed",
        "runtime": 2,
        "errors": [],
        "assertions": [
          {
            "passed": true,
            "actual": true,
            "expected": true,
            "message": "One is an odd number"
          },
          {
            "passed": true,
            "actual": true,
            "expected": true,
            "message": "Three is an odd number"
          },
          {
            "passed": true,
            "actual": true,
            "expected": true,
            "message": "Zero is not odd number"
          }
        ]
      }
    ],
    "suites": {
      "fullName": [],
      "childSuites": [
        {
          "name": "Odd Tests",
          "fullName": ["Odd Tests"],
          "childSuites": [],
          "tests": [
            {
              "name": "isOdd()",
              "suiteName": "Odd Tests",
              "fullName": ["Odd Tests", "isOdd()"],
              "status": "passed",
              "runtime": 2,
              "errors": [],
              "assertions": [
                {
                  "passed": true,
                  "actual": true,
                  "expected": true,
                  "message": "One is an odd number"
                },
                {
                  "passed": true,
                  "actual": true,
                  "expected": true,
                  "message": "Three is an odd number"
                },
                {
                  "passed": true,
                  "actual": true,
                  "expected": true,
                  "message": "Zero is not odd number"
                }
              ]
            }
          ],
          "status": "passed",
          "testCounts": {
            "passed": 1,
            "failed": 0,
            "skipped": 0,
            "total": 1
          },
          "runtime": 2
        }
      ],
      "tests": [],
      "status": "passed",
      "testCounts": {
        "passed": 1,
        "failed": 0,
        "skipped": 0,
        "total": 1
      },
      "runtime": 2
    }
  }
]

Configuration

To run browser tests on BrowserStack infrastructure, you need to create a browserstack.json file in project's root directory (the directory from which tests are run), by running this command:

browserstack-runner init [preset] [path]

preset: Path of a custom preset file. Default: presets/default.json

path: Path to test file. Default: path/to/test/runner

Parameters for browserstack.json

  • username: BrowserStack username (Or BROWSERSTACK_USERNAME environment variable)
  • key: BrowserStack access key (Or BROWSERSTACK_KEY environment variable)
  • test_path: Path to the test page which will run the tests when opened in a browser.
  • test_framework: Specify test framework which will run the tests. Currently supporting qunit, jasmine, jasmine1.3.1, jasmine2 and mocha.
  • test_server_port: Specify test server port that will be opened from BrowserStack. If not set the default port 8888 will be used. Find a list of all supported ports on browerstack.com.
  • timeout: Specify worker timeout with BrowserStack.
  • browsers: A list of browsers on which tests are to be run. Find a list of all supported browsers and platforms on browerstack.com.
  • build: A string to identify your test run in Browserstack. In TRAVIS setup TRAVIS_COMMIT will be the default identifier.
  • proxy: Specify a proxy to use for the local tunnel. Object with host, port, username and password properties.
  • exit_with_fail: If set to true the cli process will exit with fail if any of the tests failed. Useful for automatic build systems.
  • tunnel_pid_file: Specify a path to file to save the tunnel process id into. Can also by specified using the --pid flag while launching browserstack-runner from the command line.

A sample configuration file:

{
  "username": "<username>",
  "key": "<access key>",
  "test_framework": "qunit|jasmine|jasmine2|mocha",
  "test_path": ["relative/path/to/test/page1", "relative/path/to/test/page2"],
  "test_server_port": "8899",
  "browsers": [
    {
      "browser": "ie",
      "browser_version": "10.0",
      "device": null,
      "os": "Windows",
      "os_version": "8",
      "cli_key": 1
    },
    {
      "os": "android",
      "os_version": "4.0",
      "device": "Samsung Galaxy Nexus",
      "cli_key": 2
    },
    {
      "os": "ios",
      "os_version": "7.0",
      "device": "iPhone 5S",
      "cli_key": 3
    }
  ]
}

browsers parameter

browsers parameter is a list of objects, where each object contains the details of the browsers on which you want to run your tests. This object differs for browsers on desktop platforms and browsers on mobile platforms. Browsers on desktop platform should contain browser, browser_version, os, os_version parameters set as required and the cli_key parameter is optional and can be used in the command line when tests need to be run on a set of browsers from the browserstack.json file.

Example:

{
  "browser": "ie",
  "browser_version": "10.0",
  "os": "Windows",
  "os_version": "8",
  "cli_key": 1
}

For mobile platforms, os, os_version and device parameters are required.

Example:

[
  {
    "os": "ios",
    "os_version": "8.3",
    "device": "iPhone 6 Plus",
    "cli_key": 1
  },
  {
    "os": "android",
    "os_version": "4.0",
    "device": "Google Nexus",
    "cli_key": 2
  }
]

For a full list of supported browsers, platforms and other details, visit the BrowserStack site.

Compact browsers configuration

When os and os_version granularity is not desired, following configuration can be used:

  • [browser]_current or browser_latest: will assign the latest version of the browser.
  • [browser]_previous: will assign the previous version of the browser.
  • [browser]_[version]: will assign the version specified of the browser. Minor versions can be concatenated with underscores.

This can also be mixed with fine-grained configuration.

Example:

{
  "browsers": [
    "chrome_previous",
    "chrome_latest",
    "firefox_previous",
    "firefox_latest",
    "ie_6",
    "ie_11",
    "opera_12_1",
    "safari_5_1",
    {
      "browser": "ie",
      "browser_version": "10.0",
      "device": null,
      "os": "Windows",
      "os_version": "8",
      "cli_key": 1
    }
  ]
}

Note: These shortcuts work only for browsers on desktop platforms supported by BrowserStack.

Proxy support for BrowserStack local

Add the following in browserstack.json

{
  "proxy": {
    "host": "localhost",
    "port": 3128,
    "username": "foo",
    "password": "bar"
  }
}

Supported environment variables

To avoid duplication of system or user specific information across several configuration files, use these environment variables:

  • BROWSERSTACK_USERNAME: BrowserStack user name.
  • BROWSERSTACK_KEY: BrowserStack key.
  • TUNNEL_ID: Identifier for the current instance of the tunnel process. In TRAVIS setup TRAVIS_JOB_ID will be the default identifier.
  • BROWSERSTACK_JSON: Path to the browserstack.json file. If null, browserstack.json in the root directory will be used.
  • BROWSERSTACK_LOCAL_BINARY_PATH: Path to the browserstack local binary present on the system. If null, BrowserStackLocal in the lib/ directory will be used.

Secure Information

To avoid checking in the BrowserStack username and key in your source control system, the corresponding environment variables can be used.

These can also be provided by a build server, for example using secure environment variables on Travis CI.

Code Sample

Check out code sample here.

Running Tests

BrowserStack Runner is currently tested by running test cases defined in QUnit, Mocha, and Spine repositories.

To run tests:

npm test

To run a larger suite of tests ensuring compatibility with older versions of QUnit, etc.:

npm run test-ci

Tests are also run for every pull request, courtesy Travis CI.

Timeout issue with Travis CI

You might face build timeout issue on Travis if runner takes more than 10 minutes to run tests.

There are 2 possible ways to solve this problem:

  1. Run a script which does console.log every 1-2 minutes. This will output to console and hence avoid Travis build timeout
  2. Use travis_wait function provided by Travis-CI. You can prefix browserstack-runner command by travis-wait in your travis.yml file

We would recommend using travis_wait function. It also allows you to configure wait time (ex: travis_wait 20 browserstack-runner, this will extend wait time to 20 minutes). Read more about travis_wait here

More Repositories

1

api

Spec of latest BrowserStack JavaScript testing api
119
star
2

nightwatch-browserstack

Selenium examples for Nightwatch and BrowserStack Automate
JavaScript
77
star
3

testng-browserstack

Selenium examples for TestNG and BrowserStack Automate
Java
75
star
4

browserstack-local-nodejs

NodeJS bindings for BrowserStack Local
JavaScript
71
star
5

webdriverio-browserstack

Selenium examples for WebDriverIO and BrowserStack Automate
JavaScript
68
star
6

enigma

Access management tool
Python
54
star
7

github-actions

A collection of GitHub Actions for BrowserStack. For internal reference: https://browserstack.atlassian.net/wiki/spaces/ENG/pages/1750928573/GitHub+Integration+via+GitHub+Actions
JavaScript
54
star
8

playwright-browserstack

Sample repo for Playwright samples with BrowserStack.
JavaScript
51
star
9

browserstack-cypress-cli

NPM package for the customers to run Cypress on Browserstack Infra
JavaScript
51
star
10

automate-node-samples

Sample mocha, protractor, nightwatchjs, wd parallel testing code for running selenium with BrowserStack Automate
JavaScript
45
star
11

webdriverio-appium-app-browserstack

JavaScript
42
star
12

protractor-browserstack

Selenium examples for Protractor and BrowserStack Automate
JavaScript
42
star
13

automate-python-samples

Sample behave, lettuce, nose, unit, py.test code for running selenium with BrowserStack Automate
Python
37
star
14

ruby-screenshots

Ruby Wrapper for BrowserStack Screenshots API
Ruby
34
star
15

testng-appium-app-browserstack

Java
30
star
16

cucumber-js-browserstack

Selenium examples for Cucumber-JS and BrowserStack Automate
JavaScript
28
star
17

automate-ruby-samples

Sample cucumber, capybara, unit, minitest code for running selenium with BrowserStack Automate
Ruby
22
star
18

selenium-webdriver-nodejs

Selenium Webdriver Nodejs
JavaScript
20
star
19

browserstack-fastlane-plugin

Ruby
20
star
20

browserstack-local-java

Java bindings for BrowserStack Local
Java
18
star
21

java-appium-app-browserstack

Java
17
star
22

enigma-access-modules

Plug-able access modules for enigma
Python
17
star
23

flashblock-detector

Flash blocking plugin detector
JavaScript
17
star
24

python-appium-app-browserstack

Python
16
star
25

browserstack-gradle-plugin

Gradle plugin for uploading app and running tests on BrowserStack
Java
16
star
26

capybara-browserstack

Selenium examples for Capybara and BrowserStack Automate
Ruby
14
star
27

specflow-browserstack

Selenium examples for SpecFlow and BrowserStack Automate
C#
14
star
28

behave-browserstack

Selenium examples for Behave and BrowserStack Automate
Python
14
star
29

browserstack-local-php

PHP bindings for BrowserStack Local
PHP
13
star
30

behat-browserstack

Selenium examples for Behat and BrowserStack Automate
PHP
13
star
31

docker-browserstack-local

Docker official Image packaging for Browserstack Local Binary
Dockerfile
12
star
32

serenity-browserstack

Selenium examples for Serenity and BrowserStack Automate
Java
12
star
33

browserstack-local-ruby

Ruby bindings for BrowserStack Local
Ruby
11
star
34

rspec-browserstack

Selenium examples for RSpec and BrowserStack Automate
Ruby
10
star
35

node-js-playwright-browserstack

Creating a sample repo for different Playwright languages and runners
JavaScript
10
star
36

automate-csharp-samples

Sample nunit, Galio code for running selenium with BrowserStack Automate
C#
9
star
37

lettuce-browserstack

Selenium examples for Lettuce and BrowserStack Automate
Python
8
star
38

python-selenium-browserstack

Python
8
star
39

junit-browserstack

Selenium examples for JUnit and BrowserStack Automate
Java
8
star
40

cucumber-java-browserstack

Java
8
star
41

browserstack-local-python

Python bindings for BrowserStack Local
Python
7
star
42

cucumber-ruby-appium-app-browserstack

Ruby
7
star
43

mocha-browserstack

Selenium examples for Mocha and BrowserStack Automate
JavaScript
7
star
44

browserstack-runner-sample

Code example to show how to run QUnit javascript tests with browserstack-runner
HTML
7
star
45

node-appium-app-browserstack

JavaScript
7
star
46

automate-php-samples

Sample behat, phpunit code for running selenium with BrowserStack Automate
PHP
7
star
47

android-native-app-certificate-pinning

Demo Android App for self-signed SSL certificate validation using Certificate Bundling and pinning process (Use case 1: App data sync with HTTPs servers, Use case 2: App using UIWidgets like WebView)
Java
7
star
48

automate-selenium-ide-samples

Run Selenium IDE scripts (json format) on BrowserStack Automate
JavaScript
6
star
49

xcuitest-sample-browserstack

Swift
6
star
50

junit-appium-app-browserstack

Java
6
star
51

phpunit-browserstack

Selenium examples for PHPUnit and BrowserStack Automate
PHP
6
star
52

browserstack-docker-example

This repo hosts the docker file running a basic selenium test on BrowserStack
JavaScript
5
star
53

selenium-webdriver-ruby

Faster Webdriver for Ruby
Ruby
5
star
54

automate-java-samples

Sample junit, testng code for running selenium with BrowserStack Automate
Java
5
star
55

test-university

This repository is a reference guide for all Test University resources and codes samples.
5
star
56

OSXVNC

abcd
C
4
star
57

ruby-appium-app-browserstack

Ruby
4
star
58

jest-js-browserstack

JavaScript
4
star
59

karma-browserstack-example

JavaScript
4
star
60

nunit-browserstack

Selenium examples for NUnit and BrowserStack Automate
C#
4
star
61

puppeteer-browserstack

Sample repo for Puppeteer samples with BrowserStack.
JavaScript
4
star
62

geb-browserstack

Selenium examples for Geb and BrowserStack Automate
Groovy
4
star
63

nunit-appium-app-browserstack

C#
4
star
64

browserstack-demo-app

A shopping application to demonstrate real-world usage of BrowserStack testing methods, patterns, and workflows.
JavaScript
4
star
65

espresso-browserstack

Java
4
star
66

cucumber-watir-browserstack

Selenium examples for Cucumber-Watir and BrowserStack Automate
Ruby
4
star
67

selenide-browserstack

Selenium examples for TestNG and BrowserStack Automate
Java
3
star
68

ws-reconnect-proxy

Proxy Server that is between a ws server and a ws client. In case of either server / client disconnects graceful or otherwise - initiates/ supports reconnection .
JavaScript
3
star
69

fast-selenium-scripts

Python
3
star
70

browserstack-local-csharp

CSharp bindings for BrowserStack Local
C#
3
star
71

cucumber-ruby-browserstack

Selenium examples for Cucumber-Ruby and BrowserStack Automate
Ruby
3
star
72

browserstack-integration-nodejs

Integration to run your tests on BrowserStack
JavaScript
3
star
73

behave-appium-app-browserstack

Python
3
star
74

teamcity-plugin

Java
3
star
75

browserstack-integration-ruby

Integration to run your tests on BrowserStack
Ruby
3
star
76

pytest-browserstack

Python
3
star
77

speedlab-code-samples

Demonstrates the workflow of SpeedLab APIs
JavaScript
3
star
78

selenium-parallel-webinar-demo

Demo of the tests used by David Burns during his Webinar on 22 April 2020
Python
2
star
79

csharp-appium-app-browserstack

C#
2
star
80

wd-browserstack

Selenium examples for WD and BrowserStack Automate
JavaScript
2
star
81

pytest-playwright-browserstack

Creating a sample repo for different Playwright languages and runners
Python
2
star
82

automate-client-java

Java
2
star
83

unittest-browserstack

Selenium examples for Unit Test and BrowserStack Automate
Python
2
star
84

chitragupta-node

Node SDK for structured JSON logging
JavaScript
2
star
85

automate-groovy-samples

how to run selenium scripts on BrowserStack Automate in groovy
Groovy
2
star
86

cucumber-js-cypress-browserstack

Creating a sample repo for Cypress - Cucumber
JavaScript
2
star
87

webdriver-framework

Repository that contains the logic for creating the WebDriver instances based on a configuration file. These WebDriver instances can be either be used for controlling cloud browsers or in-house browsers. This library will also be responsible for managing the BrowserStackLocal tunnel.
Java
2
star
88

typescript-playwright-browserstack

Creating a sample repo for different Playwright languages and runners
TypeScript
2
star
89

codecept-js-browserstack

JavaScript
1
star
90

jbehave-browserstack

Selenium examples for JBehave and BrowserStack Automate
Java
1
star
91

chitragupta-rails

Rails SDK for structured JSON logging
Ruby
1
star
92

node-js-selenium-browserstack

JavaScript
1
star
93

ruby-selenium-browserstack

Ruby
1
star
94

gauge-java-browserstack

Selenium Java examples for Gauge and BrowserStack Automate
Java
1
star
95

phpunit-appium-app-browserstack

PHP
1
star
96

protractor-browserstack-reporter

JavaScript
1
star
97

browserstack-android-sample-app

Java
1
star
98

emberjs-qunit-browserstack

JavaScript
1
star
99

pytest-appium-app-browserstack

Pytest integration with BrowserStack
Python
1
star
100

java-selenium-browserstack

Java
1
star