Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
feat(saucelabs): add sauceRegion support for eu datacenters (#5083)
Browse files Browse the repository at this point in the history
This change allows user to define the backend region from sauce via the `sauceRegion` property, e.g. 

```js
    sauceUser: process.env.SAUCE_USERNAME,
    sauceKey: process.env.SAUCE_ACCESS_KEY,
    sauceRegion: 'eu',
```

Will run the test against `https://ondemand.eu-central-1.saucelabs.com:443/wd/hub/.`

```js
    sauceUser: process.env.SAUCE_USERNAME,
    sauceKey: process.env.SAUCE_ACCESS_KEY,
    sauceRegion: 'us',

    // the default
    sauceUser: process.env.SAUCE_USERNAME,
    sauceKey: process.env.SAUCE_ACCESS_KEY,
```

Will run the test against https://ondemand.saucelabs.com:443/wd/hub/
  • Loading branch information
wswebcreation authored and cnishina committed Dec 19, 2018
1 parent 3a5e413 commit db1b638
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,13 @@ export interface Config {
* ignored. The tests will be run remotely using Sauce Labs.
*/
sauceKey?: string;
/**
* If you run your tests on SauceLabs you can specify the region you want to run your tests
* in via the `sauceRegion` property. Available short handles for regions are:
* us: us-west-1 (default)
* eu: eu-central-1
*/
sauceRegion?: string;
/**
* Use sauceAgent if you need custom HTTP agent to connect to saucelabs.com APIs.
* This is needed if your computer is behind a corporate proxy.
Expand Down
23 changes: 21 additions & 2 deletions lib/driverProviders/sauce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import {Logger} from '../logger';
import {DriverProvider} from './driverProvider';

const SauceLabs = require('saucelabs');
const SAUCE_REGIONS: {[key: string]: string} = {
'us': '', // default endpoint
'eu': 'eu-central-1.'
};

let logger = new Logger('sauce');
export class Sauce extends DriverProvider {
Expand Down Expand Up @@ -55,6 +59,7 @@ export class Sauce extends DriverProvider {
protected setupDriverEnv(): q.Promise<any> {
let deferred = q.defer();
this.sauceServer_ = new SauceLabs({
hostname: this.getSauceEndpoint(this.config_.sauceRegion),
username: this.config_.sauceUser,
password: this.config_.sauceKey,
agent: this.config_.sauceAgent,
Expand All @@ -66,8 +71,9 @@ export class Sauce extends DriverProvider {
let protocol = this.config_.sauceSeleniumUseHttp ? 'http://' : 'https://';
let auth = protocol + this.config_.sauceUser + ':' + this.config_.sauceKey + '@';
this.config_.seleniumAddress = auth +
(this.config_.sauceSeleniumAddress ? this.config_.sauceSeleniumAddress :
'ondemand.saucelabs.com:443/wd/hub');
(this.config_.sauceSeleniumAddress ?
this.config_.sauceSeleniumAddress :
`ondemand.${this.getSauceEndpoint(this.config_.sauceRegion)}:443/wd/hub`);

// Append filename to capabilities.name so that it's easier to identify
// tests.
Expand All @@ -82,4 +88,17 @@ export class Sauce extends DriverProvider {
deferred.resolve();
return deferred.promise;
}

/**
* Get the Sauce Labs endpoint
* @private
* @param {string} region
* @return {string} The endpoint that needs to be used
*/
private getSauceEndpoint(region: string): string {
const dc = region ?
typeof SAUCE_REGIONS[region] !== 'undefined' ? SAUCE_REGIONS[region] : (region + '.') :
'';
return `${dc}saucelabs.com`;
}
}

0 comments on commit db1b638

Please sign in to comment.