From 02e9f64bd0a7795834007fecd8f16bbcbd969439 Mon Sep 17 00:00:00 2001 From: Matt Gaunt Date: Thu, 19 Jan 2017 08:31:54 -0800 Subject: [PATCH] Fixing a capabilities error with saucelabs (#78) --- src/browser-models/browser.js | 11 ++++++----- src/browser-models/saucelabs-browser.js | 4 +--- src/saucelabs-browsers/chrome.js | 13 ++++++++----- src/saucelabs-browsers/edge.js | 4 +--- src/saucelabs-browsers/firefox.js | 18 +++++++++++++++++- src/saucelabs-browsers/ie.js | 6 +++--- src/saucelabs-browsers/opera.js | 6 +++--- src/saucelabs-browsers/safari.js | 6 +++--- 8 files changed, 42 insertions(+), 26 deletions(-) diff --git a/src/browser-models/browser.js b/src/browser-models/browser.js index ce209a0..4927f1a 100644 --- a/src/browser-models/browser.js +++ b/src/browser-models/browser.js @@ -16,6 +16,8 @@ 'use strict'; +const seleniumWebdriver = require('selenium-webdriver'); + /** * A base class which all "types" of browser models extend. * @@ -34,6 +36,9 @@ class Browser { } this._config = config; + this._capabilities = new seleniumWebdriver.Capabilities(); + + this.addCapability(seleniumWebdriver.Capability.BROWSER_NAME, this.getId()); } /** @@ -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); } /** diff --git a/src/browser-models/saucelabs-browser.js b/src/browser-models/saucelabs-browser.js index a8952a3..1294c5c 100644 --- a/src/browser-models/saucelabs-browser.js +++ b/src/browser-models/saucelabs-browser.js @@ -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; } } diff --git a/src/saucelabs-browsers/chrome.js b/src/saucelabs-browsers/chrome.js index 9c72583..346bbb5 100644 --- a/src/saucelabs-browsers/chrome.js +++ b/src/saucelabs-browsers/chrome.js @@ -18,7 +18,6 @@ const SauceLabsBrowser = require('../browser-models/saucelabs-browser'); const ChromeConfig = require('../webdriver-config/chrome'); - /** *

Handles the prettyName and executable path for Chrome browser.

* @@ -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'); } /** @@ -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; } diff --git a/src/saucelabs-browsers/edge.js b/src/saucelabs-browsers/edge.js index d8337a0..ad777db 100644 --- a/src/saucelabs-browsers/edge.js +++ b/src/saucelabs-browsers/edge.js @@ -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; } diff --git a/src/saucelabs-browsers/firefox.js b/src/saucelabs-browsers/firefox.js index e166930..a17f7f5 100644 --- a/src/saucelabs-browsers/firefox.js +++ b/src/saucelabs-browsers/firefox.js @@ -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'); } /** @@ -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;**/ } } diff --git a/src/saucelabs-browsers/ie.js b/src/saucelabs-browsers/ie.js index 52903c0..fb5a53d 100644 --- a/src/saucelabs-browsers/ie.js +++ b/src/saucelabs-browsers/ie.js @@ -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; } diff --git a/src/saucelabs-browsers/opera.js b/src/saucelabs-browsers/opera.js index bf26d80..4e6752d 100644 --- a/src/saucelabs-browsers/opera.js +++ b/src/saucelabs-browsers/opera.js @@ -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; } diff --git a/src/saucelabs-browsers/safari.js b/src/saucelabs-browsers/safari.js index 75b6770..c52ab1a 100644 --- a/src/saucelabs-browsers/safari.js +++ b/src/saucelabs-browsers/safari.js @@ -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; }