Skip to content

Commit

Permalink
Fixing a capabilities error with saucelabs (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Gaunt authored Jan 19, 2017
1 parent cb9915f commit 02e9f64
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 26 deletions.
11 changes: 6 additions & 5 deletions src/browser-models/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

'use strict';

const seleniumWebdriver = require('selenium-webdriver');

/**
* A base class which all "types" of browser models extend.
*
Expand All @@ -34,6 +36,9 @@ class Browser {
}

this._config = config;
this._capabilities = new seleniumWebdriver.Capabilities();

this.addCapability(seleniumWebdriver.Capability.BROWSER_NAME, this.getId());
}

/**
Expand All @@ -46,11 +51,7 @@ class Browser {
* @param {String} value The capability value.
*/
addCapability(key, value) {
if (!this._capabilities) {
this._capabilities = {};
}

this._capabilities[key] = value;
this._capabilities.set(key, value);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/browser-models/saucelabs-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,8 @@ class SauceLabsBrowser extends Browser {
const builder = new webdriver
.Builder();

builder.usingServer('https://' + saucelabsDetails.username + ':' +
return builder.usingServer('https://' + saucelabsDetails.username + ':' +
saucelabsDetails.accessKey + '@ondemand.saucelabs.com:443/wd/hub');

return builder;
}
}

Expand Down
13 changes: 8 additions & 5 deletions src/saucelabs-browsers/chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

const SauceLabsBrowser = require('../browser-models/saucelabs-browser');
const ChromeConfig = require('../webdriver-config/chrome');

/**
* <p>Handles the prettyName and executable path for Chrome browser.</p>
*
Expand All @@ -33,6 +32,10 @@ class ChromeWebDriverBrowser extends SauceLabsBrowser {
*/
constructor(version) {
super(new ChromeConfig(), version);

// Set default platform to windows 10 otherwise it will be an out of
// date version of Chrome.
this.addCapability('platform', 'Windows 10');
}

/**
Expand All @@ -50,10 +53,10 @@ class ChromeWebDriverBrowser extends SauceLabsBrowser {
getSeleniumDriverBuilder() {
let builder = super.getSeleniumDriverBuilder();

builder = builder
.setChromeOptions(this.getSeleniumOptions())
.withCapabilities(this._capabilities)
.forBrowser(this.getId());
const seleniumOptions = this.getSeleniumOptions();
let capabilities = seleniumOptions.toCapabilities(this._capabilities);

builder = builder.withCapabilities(capabilities);

return builder;
}
Expand Down
4 changes: 1 addition & 3 deletions src/saucelabs-browsers/edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,11 @@ class EdgeWebDriverBrowser extends SauceLabsBrowser {
*/
getSeleniumDriverBuilder() {
let builder = super.getSeleniumDriverBuilder();

const seleniumOptions = this.getSeleniumOptions();
let capabilities = seleniumOptions.toCapabilities(this._capabilities);

builder = builder
.withCapabilities(capabilities)
.forBrowser(this.getId());
.withCapabilities(capabilities);

return builder;
}
Expand Down
18 changes: 17 additions & 1 deletion src/saucelabs-browsers/firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class FirefoxWebDriverBrowser extends SauceLabsBrowser {
*/
constructor(version) {
super(new FirefoxConfig(), version);

// Set default platform to windows 10 otherwise it will be an out of
// date version of Firefox.
this.addCapability('platform', 'Windows 10');
}

/**
Expand All @@ -49,13 +53,25 @@ class FirefoxWebDriverBrowser extends SauceLabsBrowser {
*/
getSeleniumDriverBuilder() {
let builder = super.getSeleniumDriverBuilder();

const seleniumOptions = this.getSeleniumOptions();
// FirefoxOptions.toCapabilities() don't take in options.
let capabilities = seleniumOptions.toCapabilities()
.merge(this._capabilities);

builder = builder
.withCapabilities(capabilities);

return builder;

/** let builder = super.getSeleniumDriverBuilder();
builder = builder
// Sauce Labs + Firefox is simple broken if I pass in the options
// .setFirefoxOptions(this.getSeleniumOptions())
.withCapabilities(this._capabilities)
.forBrowser(this.getId());
return builder;
return builder;**/
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/saucelabs-browsers/ie.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class IEWebDriverBrowser extends SauceLabsBrowser {
*/
getSeleniumDriverBuilder() {
let builder = super.getSeleniumDriverBuilder();
const seleniumOptions = this.getSeleniumOptions();
let capabilities = seleniumOptions.toCapabilities(this._capabilities);

builder = builder
.setIeOptions(this.getSeleniumOptions())
.withCapabilities(this._capabilities)
.forBrowser(this.getId());
.withCapabilities(capabilities);

return builder;
}
Expand Down
6 changes: 3 additions & 3 deletions src/saucelabs-browsers/opera.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class OperaDriverBrowser extends SauceLabsBrowser {
*/
getSeleniumDriverBuilder() {
let builder = super.getSeleniumDriverBuilder();
const seleniumOptions = this.getSeleniumOptions();
let capabilities = seleniumOptions.toCapabilities(this._capabilities);

builder = builder
.setOperaOptions(this.getSeleniumOptions())
.withCapabilities(this._capabilities)
.forBrowser(this.getId());
.withCapabilities(capabilities);

return builder;
}
Expand Down
6 changes: 3 additions & 3 deletions src/saucelabs-browsers/safari.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class SafariDriverBrowser extends SauceLabsBrowser {
*/
getSeleniumDriverBuilder() {
let builder = super.getSeleniumDriverBuilder();
const seleniumOptions = this.getSeleniumOptions();
let capabilities = seleniumOptions.toCapabilities(this._capabilities);

builder = builder
.setSafariOptions(this.getSeleniumOptions())
.withCapabilities(this._capabilities)
.forBrowser(this.getId());
.withCapabilities(capabilities);

return builder;
}
Expand Down

0 comments on commit 02e9f64

Please sign in to comment.