Skip to content

add/binary path env #233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 76 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
@@ -43,12 +43,12 @@ Sample Usage:
`browserstack-runner` can also be used as a module. To run your tests, inside your project do -

```node
var browserstackRunner = require('browserstack-runner');
var browserstackRunner = require("browserstack-runner");

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

browserstackRunner.run(config, function(error, report) {
if(error) {
if (error) {
console.log("Error:" + error);
return;
}
@@ -58,6 +58,7 @@ browserstackRunner.run(config, function(error, report) {
```

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.
@@ -74,10 +75,7 @@ The structure of the `report` object is as follows -
{
"name": "isOdd()",
"suiteName": "Odd Tests",
"fullName": [
"Odd Tests",
"isOdd()"
],
"fullName": ["Odd Tests", "isOdd()"],
"status": "passed",
"runtime": 2,
"errors": [],
@@ -108,18 +106,13 @@ The structure of the `report` object is as follows -
"childSuites": [
{
"name": "Odd Tests",
"fullName": [
"Odd Tests"
],
"fullName": ["Odd Tests"],
"childSuites": [],
"tests": [
{
"name": "isOdd()",
"suiteName": "Odd Tests",
"fullName": [
"Odd Tests",
"isOdd()"
],
"fullName": ["Odd Tests", "isOdd()"],
"status": "passed",
"runtime": 2,
"errors": [],
@@ -181,17 +174,17 @@ To run browser tests on BrowserStack infrastructure, you need to create a `brows

### Parameters for `browserstack.json`

* `username`: BrowserStack username (Or `BROWSERSTACK_USERNAME` environment variable)
* `key`: BrowserStack [access key](https://www.browserstack.com/accounts/local-testing) (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](https://www.browserstack.com/question/664).
* `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](https://www.browserstack.com/list-of-browsers-and-platforms?product=js_testing).
* `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.
- `username`: BrowserStack username (Or `BROWSERSTACK_USERNAME` environment variable)
- `key`: BrowserStack [access key](https://www.browserstack.com/accounts/local-testing) (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](https://www.browserstack.com/question/664).
- `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](https://www.browserstack.com/list-of-browsers-and-platforms?product=js_testing).
- `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:

@@ -232,32 +225,35 @@ A sample configuration file:
`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:

```json
{
"browser": "ie",
"browser_version": "10.0",
"os": "Windows",
"os_version": "8",
"cli_key": 1
"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:

```json
[{
"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
}
[
{
"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
}
]
```

@@ -266,48 +262,52 @@ For a full list of supported browsers, platforms and other details, [visit the B
#### 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.

- `[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:

```json
{
"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
}
"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`

```json
{
"proxy": {
"host": "localhost",
"port": 3128,
"username": "foo",
"password": "bar"
"host": "localhost",
"port": 3128,
"username": "foo",
"password": "bar"
}
}
```
@@ -316,19 +316,18 @@ Add the following in `browserstack.json`

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_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](http://about.travis-ci.org/docs/user/build-configuration/#Secure-environment-variables).


### Code Sample

Check out code sample [here](https://github.com/browserstack/browserstack-runner-sample).
@@ -348,11 +347,12 @@ To run a larger suite of tests ensuring compatibility with older versions of QUn
Tests are also run for every pull request, courtesy [Travis CI](https://travis-ci.org/).

### Timeout issue with Travis CI

You might face [build timeout issue on Travis](https://docs.travis-ci.com/user/common-build-problems/#Build-times-out-because-no-output-was-received) 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
You might face [build timeout issue on Travis](https://docs.travis-ci.com/user/common-build-problems/#Build-times-out-because-no-output-was-received) 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](https://docs.travis-ci.com/user/common-build-problems/#Build-times-out-because-no-output-was-received)
4 changes: 2 additions & 2 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -421,11 +421,11 @@ function runTests(config, callback) {
}
}

exports.run = function(user_config, callback) {
exports.run = function(userConfig, callback) {
callback = callback || function() {};

try {
config = new (require('../lib/config').config)(user_config);
config = new (require('../lib/config').config)(userConfig);

client = BrowserStack.createClient({
username: config.username,
2 changes: 2 additions & 0 deletions lib/local.js
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@ var Log = require('./logger'),
var Tunnel = function Tunnel(key, port, uniqueIdentifier, config, callback) {
var that = {};

localBinary = process.env.BROWSERSTACK_LOCAL_BINARY_PATH || localBinary;

function tunnelLauncher() {
var tunnelOptions = getTunnelOptions(key, uniqueIdentifier);