diff --git a/lib/config.ts b/lib/config.ts index ccb0d89a8..0e817ec31 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -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. diff --git a/lib/driverProviders/sauce.ts b/lib/driverProviders/sauce.ts index d4b860551..3f43a6c46 100644 --- a/lib/driverProviders/sauce.ts +++ b/lib/driverProviders/sauce.ts @@ -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 { @@ -55,6 +59,7 @@ export class Sauce extends DriverProvider { protected setupDriverEnv(): q.Promise { 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, @@ -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. @@ -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`; + } }