Skip to content

Commit

Permalink
Better handling of environment variables (closes #11, closes #13) (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreyBelym authored and AlexanderMoskovkin committed Apr 11, 2017
1 parent 7983a96 commit 33d1dec
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,13 @@ testCafe
.run();
```

## Configuration

Use the following environment variables to set additional configuration options:

- `SAUCE_JOB` - the text that will be displayed as Job Name on SauceLabs,

- `SAUCE_BUILD` - the text that will be displayed as Build Name on SauceLabs.

## Author
Developer Express Inc. (https://devexpress.com)
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "testcafe-browser-provider-saucelabs",
"version": "1.1.0",
"version": "1.2.0",
"description": "saucelabs TestCafe browser provider plugin.",
"repository": "https://github.com/DevExpress/testcafe-browser-provider-saucelabs",
"homepage": "https://github.com/DevExpress/testcafe-browser-provider-saucelabs",
Expand Down
12 changes: 11 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Promise from 'pinkie';
import pify from 'pify';
import { flatten, find, assign } from 'lodash';

const AUTH_FAILED_ERROR = 'Authentication failed. Please assign the correct username and access key ' +
'to the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables.';

const SAUCE_LABS_REQUESTED_MACHINES_COUNT = 1;
const WAIT_FOR_FREE_MACHINES_REQUEST_INTERVAL = 60000;
Expand Down Expand Up @@ -180,6 +182,8 @@ export default {
if (this.tunnelConnectRetryCount > MAX_TUNNEL_CONNECT_RETRY_COUNT)
throw error;

this.connectorPromise = Promise.resolve(null);

return this._getConnector();
});

Expand Down Expand Up @@ -326,6 +330,9 @@ export default {
},

async openBrowser (id, pageUrl, browserName) {
if (!process.env['SAUCE_USERNAME'] || !process.env['SAUCE_ACCESS_KEY'])
throw new Error(AUTH_FAILED_ERROR);

var capabilities = this._generateCapabilities(browserName);
var connector = await this._getConnector();

Expand All @@ -335,7 +342,10 @@ export default {
WAIT_FOR_FREE_MACHINES_MAX_ATTEMPT_COUNT
);

var newBrowser = await connector.startBrowser(capabilities, pageUrl);
var newBrowser = await connector.startBrowser(capabilities, pageUrl, {
jobName: process.env['SAUCE_JOB'],
build: process.env['SAUCE_BUILD']
});

this.openedBrowsers[id] = newBrowser;

Expand Down
4 changes: 2 additions & 2 deletions test/mocha/browser-names-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('Browser names', function () {
'[email protected]:Windows 10',
'iPhone 6 [email protected]',
'Samsung Galaxy S7 [email protected]',
'Android Emulator Phone@4.3',
'Android Emulator Phone@4.4',
'iPad [email protected]',
'iPhone [email protected]'
]);
Expand All @@ -48,7 +48,7 @@ describe('Browser names', function () {
'[email protected]:Windows 8',
'IE@11:Windows 10',
'iPhone [email protected]',
'Android Emulator Tablet@4.3',
'Android Emulator Tablet@4.4',
'[email protected]',
'IE@11:Linux'
];
Expand Down

0 comments on commit 33d1dec

Please sign in to comment.