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

Fix/add saucelabs eu dc #5083

Merged
merged 7 commits into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
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
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`;
}
}