Skip to content

Commit

Permalink
allow to specify Sauce backend region
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-bromann committed Nov 30, 2018
1 parent 544badd commit 6e5ac70
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
18 changes: 12 additions & 6 deletions docs/guide/testrunner/configurationfile.md
Expand Up @@ -37,6 +37,12 @@ exports.config = {
user: 'webdriverio',
key: 'xxxxxxxxxxxxxxxx-xxxxxx-xxxxx-xxxxxxxxx',
//
// If you run your tests on SauceLabs you can specify the region you want to run your tests
// in via the `region` property. You can either provide the full region name or the short handle:
// us: us-west-1 (default)
// eu: eu-central-1
region: 'eu', // for eu-central-1
//
// ==================
// Specify Test Files
// ==================
Expand Down Expand Up @@ -82,8 +88,8 @@ exports.config = {
chromeOptions: {
// to run chrome headless the following flags are required
// (see https://developers.google.com/web/updates/2017/04/headless-chrome)
// args: ['--headless', '--disable-gpu'],
}
// args: ['--headless', '--disable-gpu'],
}
}, {
// maxInstances can get overwritten per capability. So if you have an in house Selenium
// grid with only 5 firefox instance available you can make sure that not more than
Expand Down Expand Up @@ -142,9 +148,9 @@ exports.config = {
// Saves a screenshot to a given path if a command fails.
screenshotPath: 'shots',
//
// Set a base URL in order to shorten url command calls. If your `url` parameter starts
// with `/`, the base url gets prepended, not including the path portion of your baseUrl.
// If your `url` parameter starts without a scheme or `/` (like `some/path`), the base url
// Set a base URL in order to shorten url command calls. If your `url` parameter starts
// with `/`, the base url gets prepended, not including the path portion of your baseUrl.
// If your `url` parameter starts without a scheme or `/` (like `some/path`), the base url
// gets prepended directly.
baseUrl: 'http://localhost:8080',
//
Expand Down Expand Up @@ -257,7 +263,7 @@ exports.config = {
* @param {Array.<String>} specs List of spec file paths that are to be run
*/
beforeSession: function (config, capabilities, specs) {
},
},
/**
* Gets executed before test execution begins. At this point you can access to all global
* variables like `browser`. It is the perfect place to define custom commands.
Expand Down
6 changes: 6 additions & 0 deletions examples/wdio.conf.js
Expand Up @@ -24,6 +24,12 @@ exports.config = {
user: 'webdriverio',
key: 'xxxxxxxxxxxxxxxx-xxxxxx-xxxxx-xxxxxxxxx',
//
// If you run your tests on SauceLabs you can specify the region you want to run your tests
// in via the `region` property. You can either provide the full region name or the short handle:
// us: us-west-1 (default)
// eu: eu-central-1
region: 'eu', // for eu-central-1
//
// ==================
// Specify Test Files
// ==================
Expand Down
14 changes: 13 additions & 1 deletion lib/helpers/detectSeleniumBackend.js
@@ -1,6 +1,15 @@
const DEFAULT_HOST = '127.0.0.1'
const DEFAULT_PORT = 4444

const REGION_MAPPING = {
'eu': 'eu-central-1'
}

function getSauceEndpoint (region) {
const dc = region ? (REGION_MAPPING[region] || region) + '.' : ''
return `${dc}saucelabs.com`
}

/**
* helper to detect the Selenium backend according to given capabilities
*/
Expand All @@ -20,6 +29,7 @@ let detectSeleniumBackend = function (capabilities) {
*/
if (!capabilities.user || !capabilities.key) {
return {
protocol: 'http',
host: DEFAULT_HOST,
port: DEFAULT_PORT
}
Expand All @@ -31,6 +41,7 @@ let detectSeleniumBackend = function (capabilities) {
*/
if (capabilities.key.length === 20) {
return {
protocol: 'http',
host: 'hub.browserstack.com',
port: 80
}
Expand All @@ -42,6 +53,7 @@ let detectSeleniumBackend = function (capabilities) {
*/
if (capabilities.key.length === 32) {
return {
protocol: 'http',
host: 'hub.testingbot.com',
port: 80
}
Expand All @@ -53,7 +65,7 @@ let detectSeleniumBackend = function (capabilities) {
*/
return {
protocol: 'https',
host: 'ondemand.saucelabs.com',
host: `ondemand.${getSauceEndpoint(capabilities.region)}`,
port: 443
}
}
Expand Down
6 changes: 6 additions & 0 deletions lib/helpers/wdio.conf.ejs
Expand Up @@ -25,6 +25,12 @@ exports.config = {
//
user: process.env.<%= answers.env_user %>,
key: process.env.<%= answers.env_key %>,
//
// If you run your tests on SauceLabs you can specify the region you want to run your tests
// in via the `region` property. You can either provide the full region name or the short handle:
// us: us-west-1 (default)
// eu: eu-central-1
// region: 'eu', // for eu-central-1
<% }
if(answers.backend.indexOf('In the cloud') > -1) { %>
<% } %>
Expand Down
1 change: 0 additions & 1 deletion lib/webdriverio.js
Expand Up @@ -40,7 +40,6 @@ let WebdriverIO = function (args, modifier) {
* merge default options with given user options
*/
let options = merge({
protocol: 'http',
waitforTimeout: 1000,
waitforInterval: 500,
coloredLogs: true,
Expand Down

0 comments on commit 6e5ac70

Please sign in to comment.