diff --git a/.eslintrc b/.eslintrc index 97b14ba7..e4fc2d59 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,7 +1,4 @@ { - "parserOptions": { - "ecmaVersion": 6, - }, "env": { "browser": true, "node": true, diff --git a/package.json b/package.json index 2d07d02a..ab6f6bc1 100644 --- a/package.json +++ b/package.json @@ -34,24 +34,23 @@ "delegate": "^3.0.0" }, "devDependencies": { - "browserify": "^12.0.1", + "browserify": "^13.0.0", "connect": "^3.4.0", "gulp": "^3.9.0", "gulp-eslint": "^2.0.0", "gulp-sourcemaps": "^1.6.0", "gulp-uglify": "^1.5.1", "gulp-util": "^3.0.7", - "gulp-webdriver": "^1.0.2", - "lodash": "^3.10.1", + "gulp-webdriver": "^2.0.1", + "lodash": "^4.8.2", "mocha": "^2.3.4", "ngrok": "^2.1.6", - "saucelabs": "^1.0.1", "selenium-server-standalone-jar": "^2.48.2", - "selenium-webdriver": "^2.48.2", "serve-static": "^1.10.0", - "uglify-js": "^2.6.1", "vinyl-buffer": "^1.0.0", "vinyl-source-stream": "^1.1.0", - "webdriverio": "^3.3.0" + "wdio-mocha-framework": "^0.2.12", + "wdio-sauce-service": "^0.2.2", + "webdriverio": "^4.0.5" } } diff --git a/test/analytics.js b/test/analytics.js index c195d385..c0ead628 100644 --- a/test/analytics.js +++ b/test/analytics.js @@ -15,7 +15,7 @@ */ -var get = require('lodash/object/get'); +var get = require('lodash/get'); module.exports = { diff --git a/test/autotrack.js b/test/autotrack.js index d82f2658..b7594563 100644 --- a/test/autotrack.js +++ b/test/autotrack.js @@ -23,7 +23,7 @@ var constants = require('../lib/constants'); describe('autotrack', function() { afterEach(function() { - return browser + browser .execute(ga.clearHitData) .execute(ga.run, 'eventTracker:remove') .execute(ga.run, 'mediaQueryTracker:remove') @@ -34,11 +34,11 @@ describe('autotrack', function() { .execute(ga.run, 'remove'); }); - it('should provide all plugins', function *() { + it('should provide all plugins', function() { - var gaplugins = (yield browser + var gaplugins = browser .url('/test/autotrack.html') - .execute(ga.getProvidedPlugins)) + .execute(ga.getProvidedPlugins) .value; assert(gaplugins.Autotrack); @@ -50,16 +50,15 @@ describe('autotrack', function() { assert(gaplugins.UrlChangeTracker); }); - it('should provide plugins even if sourced before the tracking snippet', - function *() { + function() { - var gaplugins = (yield browser + var gaplugins = browser .url('/test/autotrack-reorder.html') .execute(ga.run, 'create', 'UA-XXXXX-Y', 'auto') .execute(ga.trackHitData) .execute(ga.run, 'require', 'autotrack') - .execute(ga.getProvidedPlugins)) + .execute(ga.getProvidedPlugins) .value; assert(gaplugins.Autotrack); @@ -70,22 +69,23 @@ describe('autotrack', function() { assert(gaplugins.SocialTracker); assert(gaplugins.UrlChangeTracker); - var hitData = (yield browser + var hitData = browser .execute(ga.run, 'send', 'pageview') - .execute(ga.getHitData)).value; + .execute(ga.getHitData) + .value; assert.equal(hitData.length, 1); }); - it('should work with renaming the global object', function *() { + it('should work with renaming the global object', function() { - var gaplugins = (yield browser + var gaplugins = browser .url('/test/autotrack-rename.html') .execute(ga.run, 'create', 'UA-XXXXX-Y', 'auto') .execute(ga.trackHitData) .execute(ga.run, 'require', 'autotrack') - .execute(ga.getProvidedPlugins)) + .execute(ga.getProvidedPlugins) .value; assert(gaplugins.Autotrack); @@ -96,9 +96,10 @@ describe('autotrack', function() { assert(gaplugins.SocialTracker); assert(gaplugins.UrlChangeTracker); - var hitData = (yield browser + var hitData = browser .execute(ga.run, 'send', 'pageview') - .execute(ga.getHitData)).value; + .execute(ga.getHitData) + .value; assert.equal(hitData.length, 1); }); @@ -106,7 +107,7 @@ describe('autotrack', function() { it('should include the &did param with all hits', function() { - return browser + browser .url('/test/autotrack.html') .execute(ga.run, 'create', 'UA-XXXXX-Y', 'auto') .execute(ga.trackHitData) diff --git a/test/event-tracker.js b/test/event-tracker.js index a4fd85d7..f7fd28ab 100644 --- a/test/event-tracker.js +++ b/test/event-tracker.js @@ -23,28 +23,28 @@ var constants = require('../lib/constants'); describe('eventTracker', function() { before(function() { - return browser.url('/test/event-tracker.html'); + browser.url('/test/event-tracker.html'); }); beforeEach(function() { - return browser + browser .execute(ga.run, 'create', 'UA-XXXXX-Y', 'auto') .execute(ga.trackHitData); }); afterEach(function () { - return browser + browser .execute(ga.clearHitData) .execute(ga.run, 'eventTracker:remove') .execute(ga.run, 'remove'); }); - it('should support declarative event binding to DOM elements', function *() { + it('should support declarative event binding to DOM elements', function() { - var hitData = (yield browser + var hitData = browser .execute(ga.run, 'require', 'eventTracker') .click('#event-button') - .execute(ga.getHitData)) + .execute(ga.getHitData) .value; assert.equal(hitData[0].eventCategory, 'foo'); @@ -54,12 +54,12 @@ describe('eventTracker', function() { }); - it('should support only specifying some of the event fields', function *() { + it('should support only specifying some of the event fields', function() { - var hitData = (yield browser + var hitData = browser .execute(ga.run, 'require', 'eventTracker') .click('#event-button-some-fields') - .execute(ga.getHitData)) + .execute(ga.getHitData) .value; assert.equal(hitData[0].eventCategory, 'foo'); @@ -70,24 +70,24 @@ describe('eventTracker', function() { it('should not capture clicks without the category and action fields', - function *() { + function() { - var hitData = (yield browser + var hitData = browser .execute(ga.run, 'require', 'eventTracker') .click('#event-button-missing-fields') - .execute(ga.getHitData)) + .execute(ga.getHitData) .value; assert.equal(hitData.length, 0); }); - it('should support customizing the attribute prefix', function *() { + it('should support customizing the attribute prefix', function() { - var hitData = (yield browser + var hitData = browser .execute(ga.run, 'require', 'eventTracker', {attributePrefix: ''}) .click('#event-button-custom-prefix') - .execute(ga.getHitData)) + .execute(ga.getHitData) .value; assert.equal(hitData[0].eventCategory, 'foo'); @@ -99,7 +99,7 @@ describe('eventTracker', function() { it('should include the &did param with all hits', function() { - return browser + browser .execute(ga.run, 'require', 'eventTracker') .execute(ga.run, 'send', 'pageview') .waitUntil(ga.hitDataMatches([['[0].devId', constants.DEV_ID]])); diff --git a/test/media-query-tracker.js b/test/media-query-tracker.js index d45b6451..c6e949d8 100644 --- a/test/media-query-tracker.js +++ b/test/media-query-tracker.js @@ -50,16 +50,16 @@ var autotrackOpts = { describe('mediaQueryTracker', function() { - before(function *() { - browserCaps = (yield browser.session()).value; + before(function() { + browserCaps = browser.session().value; // Loads the autotrack file since no custom HTML is needed. - yield browser.url('/test/autotrack.html'); + browser.url('/test/autotrack.html'); }); beforeEach(function() { - return browser + browser .setViewportSize({width: 800, height: 600}, false) .execute(ga.run, 'create', 'UA-XXXXX-Y', 'auto') .execute(ga.trackHitData); @@ -67,7 +67,7 @@ describe('mediaQueryTracker', function() { afterEach(function () { - return browser + browser .execute(ga.clearHitData) .execute(ga.run, 'mediaQueryTracker:remove') .execute(ga.run, 'remove'); @@ -78,7 +78,7 @@ describe('mediaQueryTracker', function() { if (notSupportedInBrowser()) return; - return browser + browser .execute(ga.run, 'require', 'mediaQueryTracker', autotrackOpts) .waitUntil(ga.trackerDataMatches([ ['dimension1', 'lg'], @@ -91,13 +91,15 @@ describe('mediaQueryTracker', function() { if (notSupportedInBrowser()) return; - return browser + browser .execute(ga.run, 'require', 'mediaQueryTracker', autotrackOpts) .setViewportSize({width: 400, height: 400}, false) .waitUntil(ga.trackerDataMatches([ ['dimension1', 'sm'], ['dimension2', 'sm'] - ])) + ])); + + browser .waitUntil(ga.hitDataMatches([ ['[0].eventCategory', 'Width'], ['[0].eventAction', 'change'], @@ -109,20 +111,20 @@ describe('mediaQueryTracker', function() { }); - it('should wait for the timeout to set or send changes', function *() { + it('should wait for the timeout to set or send changes', function() { if (notSupportedInBrowser()) return; - yield browser + browser .execute(ga.run, 'require', 'mediaQueryTracker', autotrackOpts) .setViewportSize({width: 400, height: 400}, false); var timeoutStart = Date.now(); - yield browser.waitUntil(ga.trackerDataMatches([ + browser.waitUntil(ga.trackerDataMatches([ ['dimension1', 'sm'], ['dimension2', 'sm'] - ])) - .waitUntil(ga.hitDataMatches([ + ])); + browser.waitUntil(ga.hitDataMatches([ ['length', 2] ])); var timeoutDuration = Date.now() - timeoutStart; @@ -131,26 +133,26 @@ describe('mediaQueryTracker', function() { }); - it('should support customizing the timeout period', function *() { + it('should support customizing the timeout period', function() { if (notSupportedInBrowser()) return; - yield browser + browser .execute(ga.run, 'require', 'mediaQueryTracker', Object.assign({}, autotrackOpts, {mediaQueryChangeTimeout: 0})) .setViewportSize({width: 400, height: 400}, false); var shortTimeoutStart = Date.now(); - yield browser.waitUntil(ga.trackerDataMatches([ + browser.waitUntil(ga.trackerDataMatches([ ['dimension1', 'sm'], ['dimension2', 'sm'] - ])) - .waitUntil(ga.hitDataMatches([ + ])); + browser.waitUntil(ga.hitDataMatches([ ['length', 2] ])); var shortTimeoutDuration = Date.now() - shortTimeoutStart; - yield browser + browser .execute(ga.clearHitData) .execute(ga.run, 'mediaQueryTracker:remove') .execute(ga.run, 'remove') @@ -161,11 +163,11 @@ describe('mediaQueryTracker', function() { .setViewportSize({width: 400, height: 400}, false); var longTimeoutStart = Date.now(); - yield browser.waitUntil(ga.trackerDataMatches([ + browser.waitUntil(ga.trackerDataMatches([ ['dimension1', 'sm'], ['dimension2', 'sm'] - ])) - .waitUntil(ga.hitDataMatches([ + ])); + browser.waitUntil(ga.hitDataMatches([ ['length', 2] ])); var longTimeoutDuration = Date.now() - longTimeoutStart; @@ -180,7 +182,7 @@ describe('mediaQueryTracker', function() { if (notSupportedInBrowser()) return; - return browser + browser .execute(requireMediaQueryTrackerWithChangeTemplate) .setViewportSize({width: 400, height: 400}, false) .waitUntil(ga.hitDataMatches([ @@ -192,7 +194,7 @@ describe('mediaQueryTracker', function() { it('should include the &did param with all hits', function() { - return browser + browser .execute(ga.run, 'require', 'mediaQueryTracker') .execute(ga.run, 'send', 'pageview') .waitUntil(ga.hitDataMatches([['[0].devId', constants.DEV_ID]])); diff --git a/test/outbound-form-tracker.js b/test/outbound-form-tracker.js index 27fa3fc7..59842df4 100644 --- a/test/outbound-form-tracker.js +++ b/test/outbound-form-tracker.js @@ -28,14 +28,14 @@ describe('outboundFormTracker', function() { afterEach(stopTracking); - it('should send events on outbound form submits', function *() { + it('should send events on outbound form submits', function() { - var hitData = (yield browser + var hitData = browser .execute(utilities.stopFormSubmitEvents) .execute(utilities.stubBeacon) .execute(ga.run, 'require', 'outboundFormTracker') .click('#submit-1') - .execute(ga.getHitData)) + .execute(ga.getHitData) .value; assert.equal(hitData[0].eventCategory, 'Outbound Form'); @@ -44,28 +44,28 @@ describe('outboundFormTracker', function() { }); - it('should not send events on local form submits', function *() { + it('should not send events on local form submits', function() { - var hitData = (yield browser + var hitData = browser .execute(utilities.stopFormSubmitEvents) .execute(utilities.stubBeacon) .execute(ga.run, 'require', 'outboundFormTracker') .click('#submit-2') - .execute(ga.getHitData)) + .execute(ga.getHitData) .value; assert(!hitData.length); }); - it('should work with forms missing the action attribute', function *() { + it('should work with forms missing the action attribute', function() { - var hitData = (yield browser + var hitData = browser .execute(utilities.stopFormSubmitEvents) .execute(utilities.stubBeacon) .execute(ga.run, 'require', 'outboundFormTracker') .click('#submit-3') - .execute(ga.getHitData)) + .execute(ga.getHitData) .value; assert(!hitData.length); @@ -73,57 +73,57 @@ describe('outboundFormTracker', function() { it('should allow customizing what is considered an outbound form', - function *() { + function() { - var testData = (yield browser + var testData = browser .execute(utilities.stopFormSubmitEvents) .execute(utilities.stubBeacon) .execute(requireOutboundFormTrackerWithConditional) .click('#submit-1') .click('#submit-2') .click('#submit-3') - .execute(ga.getHitData)) + .execute(ga.getHitData) .value; assert(!testData.length); }); - it('should navigate to the proper outbound location on submit', function *() { + it('should navigate to the proper outbound location on submit', function() { - yield browser + browser .execute(utilities.stubBeacon) .execute(ga.run, 'require', 'outboundFormTracker') .click('#submit-1') .waitUntil(utilities.urlMatches('https://google-analytics.com/collect')); // Restores the page state. - yield setupPage(); + setupPage(); }); - it('should navigate to the proper local location on submit', function *() { + it('should navigate to the proper local location on submit', function() { - yield browser + browser .execute(utilities.stubBeacon) .execute(ga.run, 'require', 'outboundFormTracker') .click('#submit-2') .waitUntil(utilities.urlMatches('/test/blank.html')); // Restores the page state. - yield setupPage(); + setupPage(); }); it('should stop the event when beacon is not supported and re-emit ' + - 'after the hit succeeds or times out', function* () { + 'after the hit succeeds or times out', function() { - var hitData = (yield browser + var hitData = browser .execute(utilities.disableProgramaticFormSubmits) .execute(utilities.stubNoBeacon) .execute(ga.run, 'require', 'outboundFormTracker') .click('#submit-1') - .execute(ga.getHitData)) + .execute(ga.getHitData) .value; // Tests that the hit is sent. @@ -132,16 +132,16 @@ describe('outboundFormTracker', function() { assert.equal(hitData[0].eventLabel, 'https://google-analytics.com/collect'); // Tests that navigation actually happens - yield setupPage(); - yield startTracking(); - yield browser + setupPage(); + startTracking(); + browser .execute(utilities.stubNoBeacon) .execute(ga.run, 'require', 'outboundFormTracker') .click('#submit-1') .waitUntil(utilities.urlMatches('https://google-analytics.com/collect')); // Restores the page state. - yield setupPage(); + setupPage(); // TODO(philipwalton): figure out a way to test the hitCallback timing out. }); @@ -149,7 +149,7 @@ describe('outboundFormTracker', function() { it('should include the &did param with all hits', function() { - return browser + browser .execute(ga.run, 'require', 'outboundFormTracker') .execute(ga.run, 'send', 'pageview') .waitUntil(ga.hitDataMatches([['[0].devId', constants.DEV_ID]])); @@ -160,19 +160,17 @@ describe('outboundFormTracker', function() { /** * Navigates to the outbound form tracker test page. - * @return {Promise} The webdriverio browser promise object. */ function setupPage() { - return browser.url('/test/outbound-form-tracker.html'); + browser.url('/test/outbound-form-tracker.html'); } /** * Initiates the tracker and capturing hit data. - * @return {Promise} The webdriverio browser promise object. */ function startTracking() { - return browser + browser .execute(ga.run, 'create', 'UA-XXXXX-Y', 'auto') .execute(ga.trackHitData); } @@ -180,10 +178,9 @@ function startTracking() { /** * Stops capturing hit data and remove the plugin and tracker. - * @return {Promise} The webdriverio browser promise object. */ function stopTracking() { - return browser + browser .execute(utilities.unstopFormSubmitEvents) .execute(ga.clearHitData) .execute(ga.run, 'outboundFormTracker:remove') diff --git a/test/outbound-link-tracker.js b/test/outbound-link-tracker.js index e3b2897f..5719fadf 100644 --- a/test/outbound-link-tracker.js +++ b/test/outbound-link-tracker.js @@ -28,14 +28,14 @@ describe('outboundLinkTracker', function() { afterEach(stopTracking); - it('should send events on outbound link clicks', function *() { + it('should send events on outbound link clicks', function() { - var hitData = (yield browser + var hitData = browser .execute(utilities.stopLinkClickEvents) .execute(utilities.stubBeacon) .execute(ga.run, 'require', 'outboundLinkTracker') .click('#outbound-link') - .execute(ga.getHitData)) + .execute(ga.getHitData) .value; assert.equal(hitData.length, 1); @@ -45,29 +45,29 @@ describe('outboundLinkTracker', function() { }); - it('should not send events on local link clicks', function *() { + it('should not send events on local link clicks', function() { - var hitData = (yield browser + var hitData = browser .execute(utilities.stopLinkClickEvents) .execute(utilities.stubBeacon) .execute(ga.run, 'require', 'outboundLinkTracker') .click('#local-link') - .execute(ga.getHitData)) + .execute(ga.getHitData) .value; assert.equal(hitData.length, 0); }); - it('should not send events on non-http(s) protocol links', function*() { + it('should not send events on non-http(s) protocol links', function() { - var hitData = (yield browser + var hitData = browser .execute(utilities.stopLinkClickEvents) .execute(utilities.stubBeacon) .execute(ga.run, 'require', 'outboundLinkTracker') .click('#javascript-protocol') .click('#file-protocol') - .execute(ga.getHitData)) + .execute(ga.getHitData) .value; assert.equal(hitData.length, 0); @@ -75,55 +75,55 @@ describe('outboundLinkTracker', function() { it('should allow customizing what is considered an outbound link', - function*() { + function() { - var hitData = (yield browser + var hitData = browser .execute(utilities.stopLinkClickEvents) .execute(utilities.stubBeacon) .execute(requireOutboundLinkTrackerWithConditional) .click('#outbound-link') - .execute(ga.getHitData)) + .execute(ga.getHitData) .value; assert.equal(hitData.length, 0); }); - it('should navigate to the proper location on outbound clicks', function *() { + it('should navigate to the proper location on outbound clicks', function() { - yield browser + browser .execute(utilities.stubBeacon) .execute(ga.run, 'require', 'outboundLinkTracker') .click('#outbound-link') .waitUntil(utilities.urlMatches('https://google-analytics.com/collect')); // Restores the page state. - yield setupPage(); + setupPage(); }); - it('should navigate to the proper location on local clicks', function *() { + it('should navigate to the proper location on local clicks', function() { - yield browser + browser .execute(utilities.stubBeacon) .execute(ga.run, 'require', 'outboundLinkTracker') .click('#local-link') .waitUntil(utilities.urlMatches('/test/blank.html')); // Restores the page state. - yield setupPage(); + setupPage(); }); it('should set the target to "_blank" when beacon is not supported', - function* () { + function() { - var target = (yield browser + var target = browser .execute(utilities.stubNoBeacon) .execute(utilities.stopLinkClickEvents) .execute(ga.run, 'require', 'outboundLinkTracker') .click('#outbound-link') - .getAttribute('#outbound-link', 'target')); + .getAttribute('#outbound-link', 'target'); assert.equal('_blank', target); }); @@ -131,7 +131,7 @@ describe('outboundLinkTracker', function() { it('should include the &did param with all hits', function() { - return browser + browser .execute(ga.run, 'require', 'outboundLinkTracker') .execute(ga.run, 'send', 'pageview') .waitUntil(ga.hitDataMatches([['[0].devId', constants.DEV_ID]])); @@ -142,19 +142,17 @@ describe('outboundLinkTracker', function() { /** * Navigates to the outbound link tracker test page. - * @return {Promise} The webdriverio browser promise object. */ function setupPage() { - return browser.url('/test/outbound-link-tracker.html'); + browser.url('/test/outbound-link-tracker.html'); } /** * Initiates the tracker and capturing hit data. - * @return {Promise} The webdriverio browser promise object. */ function startTracking() { - return browser + browser .execute(ga.run, 'create', 'UA-XXXXX-Y', 'auto') .execute(ga.trackHitData); } @@ -162,10 +160,9 @@ function startTracking() { /** * Stops capturing hit data and remove the plugin and tracker. - * @return {Promise} The webdriverio browser promise object. */ function stopTracking() { - return browser + browser .execute(utilities.unstopLinkClickEvents) .execute(ga.clearHitData) .execute(ga.run, 'outboundLinkTracker:remove') diff --git a/test/social-tracker.js b/test/social-tracker.js index 7c74135b..7b14ca67 100644 --- a/test/social-tracker.js +++ b/test/social-tracker.js @@ -25,34 +25,34 @@ var browserCaps; describe('socialTracker', function() { - before(function *() { - browserCaps = (yield browser.session()).value; + before(function() { + browserCaps = browser.session().value; - yield browser.url('/test/social-tracker.html'); + browser.url('/test/social-tracker.html'); }); beforeEach(function() { - return browser + browser .execute(ga.run, 'create', 'UA-XXXXX-Y', 'auto') .execute(ga.trackHitData); }); afterEach(function () { - return browser + browser .execute(ga.clearHitData) .execute(ga.run, 'socialTracker:remove') .execute(ga.run, 'remove'); }); - it('should support declarative event binding to DOM elements', function *() { + it('should support declarative event binding to DOM elements', function() { - var hitData = (yield browser + var hitData = browser .execute(ga.run, 'require', 'socialTracker') .click('#social-button') - .execute(ga.getHitData)) + .execute(ga.getHitData) .value; assert.equal(hitData.length, 1); @@ -62,24 +62,24 @@ describe('socialTracker', function() { }); it('should not capture clicks without the network, action, and target fields', - function *() { + function() { - var hitData = (yield browser + var hitData = browser .execute(ga.run, 'require', 'socialTracker') .click('#social-button-missing-fields') - .execute(ga.getHitData)) + .execute(ga.getHitData) .value; assert.equal(hitData.length, 0); }); - it('should support customizing the attribute prefix', function *() { + it('should support customizing the attribute prefix', function() { - var hitData = (yield browser + var hitData = browser .execute(ga.run, 'require', 'socialTracker', {attributePrefix: ''}) .click('#social-button-custom-prefix') - .execute(ga.getHitData)) + .execute(ga.getHitData) .value; assert.equal(hitData.length, 1); @@ -90,21 +90,19 @@ describe('socialTracker', function() { it('should support tweets and follows from the official twitter widgets', - function *() { + function() { if (notSupportedInBrowser()) return; - yield browser.execute(ga.run, 'require', 'socialTracker'); + browser.execute(ga.run, 'require', 'socialTracker'); - var tweetFrame = (yield browser - .waitForVisible('iframe.twitter-share-button') - .element('iframe.twitter-share-button')).value; + browser.waitForVisible('iframe.twitter-share-button'); + var tweetFrame = browser.element('iframe.twitter-share-button').value; - var followFrame = (yield browser - .waitForVisible('iframe.twitter-follow-button') - .element('iframe.twitter-follow-button')).value; + browser.waitForVisible('iframe.twitter-follow-button'); + var followFrame = browser.element('iframe.twitter-follow-button').value; - yield browser + browser .frame(tweetFrame) .click('a') .frame() @@ -123,17 +121,17 @@ describe('socialTracker', function() { // TODO(philipwalton): figure out why this doesn't work... - // it('should support likes from the official facebook widget', function *() { + // it('should support likes from the official facebook widget', function() { - // var mainWindow = (yield browser + // var mainWindow = browser // .url('/test/social-tracker-widgets.html') - // .windowHandle()).value; + // .windowHandle().value; - // var likeFrame = (yield browser + // var likeFrame = browser // .waitForVisible('.fb-like iframe') - // .element('.fb-like iframe')).value; + // .element('.fb-like iframe').value; - // yield browser + // browser // .frame(likeFrame) // .click('form .pluginButtonLabel') // .debug(); @@ -142,7 +140,7 @@ describe('socialTracker', function() { it('should include the &did param with all hits', function() { - return browser + browser .execute(ga.run, 'require', 'socialTracker') .execute(ga.run, 'send', 'pageview') .waitUntil(ga.hitDataMatches([['[0].devId', constants.DEV_ID]])); diff --git a/test/url-change-tracker.js b/test/url-change-tracker.js index 1c84b780..e80ef024 100644 --- a/test/url-change-tracker.js +++ b/test/url-change-tracker.js @@ -26,78 +26,78 @@ var baseUrl = browser.options.baseUrl; describe('urlTracker', function() { - before(function *() { - browserCaps = (yield browser.session()).value; + before(function() { + browserCaps = browser.session().value; - yield browser.url('/test/url-change-tracker.html'); + browser.url('/test/url-change-tracker.html'); }); beforeEach(function() { - return browser + browser .execute(ga.run, 'create', 'UA-XXXXX-Y', 'auto') .execute(ga.trackHitData); }); afterEach(function () { - return browser + browser .execute(ga.clearHitData) .execute(ga.run, 'urlChangeTracker:remove') .execute(ga.run, 'remove'); }); - it('should capture URL changes via pushState and popstate', function *() { + it('should capture URL changes via pushState and popstate', function() { if (notSupportedInBrowser()) return; - yield browser.execute(ga.run, 'require', 'urlChangeTracker'); + browser.execute(ga.run, 'require', 'urlChangeTracker'); - var fooUrl = (yield browser + var fooUrl = browser .click('#foo') - .url()) + .url() .value; assert.equal(fooUrl, baseUrl + '/test/foo.html'); - var barUrl = (yield browser + var barUrl = browser .click('#bar') - .url()) + .url() .value; assert.equal(barUrl, baseUrl + '/test/bar.html'); - var quxUrl = (yield browser + var quxUrl = browser .click('#qux') - .url()) + .url() .value; assert.equal(quxUrl, baseUrl + '/test/qux.html'); - var back1Url = (yield browser + var back1Url = browser .back() - .url()) + .url() .value; assert.equal(back1Url, baseUrl + '/test/bar.html'); - var back2Url = (yield browser + var back2Url = browser .back() - .url()) + .url() .value; assert.equal(back2Url, baseUrl + '/test/foo.html'); - var back3Url = (yield browser + var back3Url = browser .back() - .url()) + .url() .value; assert.equal(back3Url, baseUrl + '/test/url-change-tracker.html'); - var hitData = (yield browser - .execute(ga.getHitData)) + var hitData = browser + .execute(ga.getHitData) .value; assert.equal(hitData[0].page, '/test/foo.html'); @@ -115,86 +115,86 @@ describe('urlTracker', function() { }); it('should update the tracker but not send hits when using replaceState', - function *() { + function() { if (notSupportedInBrowser()) return; - yield browser.execute(ga.run, 'require', 'urlChangeTracker'); + browser.execute(ga.run, 'require', 'urlChangeTracker'); - var url = (yield browser + var url = browser .click('#replace') - .url()) + .url() .value; // Replace state was called to just use the pathname value. assert.equal(url, baseUrl + '/test/replaced.html'); - url = (yield browser + url = browser .click('#restore') - .url()) + .url() .value; // Replace state was called to just use the pathname value. assert.equal(url, baseUrl + '/test/url-change-tracker.html'); - var hitData = (yield browser - .execute(ga.getHitData)) + var hitData = browser + .execute(ga.getHitData) .value; assert.equal(hitData.length, 0); }); - it('should not capture hash changes', function *() { + it('should not capture hash changes', function() { if (notSupportedInBrowser()) return; - yield browser.execute(ga.run, 'require', 'urlChangeTracker'); + browser.execute(ga.run, 'require', 'urlChangeTracker'); - var url = (yield browser + var url = browser .click('#hash') - .url()) + .url() .value; assert.equal(url, baseUrl + '/test/url-change-tracker.html#hash'); - var backUrl = (yield browser + var backUrl = browser .back() - .url()) + .url() .value; assert.equal(backUrl, baseUrl + '/test/url-change-tracker.html'); - var hitData = (yield browser - .execute(ga.getHitData)) + var hitData = browser + .execute(ga.getHitData) .value; assert.equal(hitData.length, 0); }); - it('should support customizing what is considered a change', function *() { + it('should support customizing what is considered a change', function() { if (notSupportedInBrowser()) return; - yield browser.execute(requireUrlChangeTrackerTrackerWithConditional); + browser.execute(requireUrlChangeTrackerTrackerWithConditional); - var fooUrl = (yield browser + var fooUrl = browser .click('#foo') - .url()) + .url() .value; assert.equal(fooUrl, baseUrl + '/test/foo.html'); - var backUrl = (yield browser + var backUrl = browser .back() - .url()) + .url() .value; assert.equal(backUrl, baseUrl + '/test/url-change-tracker.html'); - var hitData = (yield browser - .execute(ga.getHitData)) + var hitData = browser + .execute(ga.getHitData) .value; assert.equal(hitData.length, 0); @@ -203,7 +203,7 @@ describe('urlTracker', function() { it('should include the &did param with all hits', function() { - return browser + browser .execute(ga.run, 'require', 'urlChangeTracker') .execute(ga.run, 'send', 'pageview') .waitUntil(ga.hitDataMatches([['[0].devId', constants.DEV_ID]])); diff --git a/wdio.conf.js b/wdio.conf.js index cd305b06..cc2e6855 100644 --- a/wdio.conf.js +++ b/wdio.conf.js @@ -15,77 +15,8 @@ */ -var SauceLabs = require('saucelabs'); - - -// When running on CI, this will be true -var isSauceLabs = process.env.SAUCE_USERNAME && process.env.SAUCE_ACCESS_KEY; - - -// https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/ -var capabilities = [ - {browserName: 'chrome'}, - {browserName: 'firefox'} -]; - -if (isSauceLabs) { - capabilities = [ - { - browserName: 'chrome', - platform: 'Windows 10' - }, - { - browserName: 'firefox', - platform: 'OS X 10.11' - }, - { - browserName: 'safari', - platform: 'OS X 10.11', - version: '9.0', - }, - { - browserName: 'safari', - platform: 'OS X 10.8', - version: '6' - }, - // TODO(philipwalton) Edge webdriver is too flaky to support at this time. - // Wait for full support and then re-add: - // https://dev.windows.com/en-us/microsoft-edge/platform/status/webdriver/details/ - // { - // browserName: 'MicrosoftEdge', - // platform: 'Windows 10' - // }, - { - browserName: 'internet explorer', - platform: 'Windows 8.1', - version: '11' - }, - { - browserName: 'internet explorer', - platform: 'Windows 8', - version: '10' - }, - { - browserName: 'internet explorer', - platform: 'Windows 7', - version: '9' - } - ]; - - capabilities.forEach(function(cap) { - cap['name'] = 'analytics.js autotrack tests - ' + cap.browserName + - ' - ' + (cap.version || 'latest'); - - cap['build'] = process.env.TRAVIS_BUILD_NUMBER; - }); -} - exports.config = { - user: process.env.SAUCE_USERNAME, - key: process.env.SAUCE_ACCESS_KEY, - // updateJob: true, - // // ================== // Specify Test Files @@ -106,37 +37,55 @@ exports.config = { // ============ // Capabilities // ============ - // Define your capabilities here. WebdriverIO can run multiple capabilties at the same + // Define your capabilities here. WebdriverIO can run multiple capabilities at the same // time. Depending on the number of capabilities, WebdriverIO launches several test - // sessions. Within your capabilities you can overwrite the spec and exclude option in + // sessions. Within your capabilities you can overwrite the spec and exclude options in // order to group specific specs to a specific capability. // - // If you have trouble getting all important capabilities together, check out the - // Sauce Labs platform configurator - a great tool to configure your capabilities: - // https://docs.saucelabs.com/reference/platforms-configurator + // First, you can define how many instances should be started at the same time. Let's + // say you have 3 different capabilities (Chrome, Firefox, and Safari) and you have + // set maxInstances to 1; wdio will spawn 3 processes. Therefore, if you have 10 spec + // files and you set maxInstances to 10, all spec files will get tested at the same time + // and 30 processes will get spawned. The property handles how many capabilities + // from the same test should run tests. // - capabilities: capabilities, + capabilities: getCapabilities(), // // =================== // Test Configurations // =================== // Define all options that are relevant for the WebdriverIO instance here // + // By default WebdriverIO commands are executed in a synchronous way using + // the wdio-sync package. If you still want to run your tests in an async way + // e.g. using promises you can set the sync option to false. + sync: true, + // // Level of logging verbosity: silent | verbose | command | data | result | error logLevel: 'silent', // // Enables colors for log output. coloredLogs: true, // + // Saves a screenshot to a given path if a command fails. + // screenshotPath: './errorShots/', + // // Set a base URL in order to shorten url command calls. If your url parameter starts - // with "/", the base url gets prepended. + // with "/", then the base url gets prepended. baseUrl: process.env.BASE_URL || 'http://localhost:8080', // - // Default timeout for all waitForXXX commands. - waitforTimeout: process.env.CI ? 60000 : 5000, + // Default timeout for all waitFor* commands. + waitforTimeout: 100000, + // + // Default timeout in milliseconds for request + // if Selenium Grid doesn't send response + connectionRetryTimeout: 100000, + // + // Default request retries count + connectionRetryCount: 3, // // Initialize the browser instance with a WebdriverIO plugin. The object should have the - // plugin name as key and the desired plugin options as property. Make sure you have + // plugin name as key and the desired plugin options as properties. Make sure you have // the plugin installed before running any tests. The following plugins are currently // available: // WebdriverCSS: https://github.com/webdriverio/webdrivercss @@ -153,77 +102,158 @@ exports.config = { // browserevent: {} // }, // + // Test runner services + // Services take over a specific job you don't want to take care of. They enhance + // your test setup with almost no effort. Unlike plugins, they don't add new + // commands. Instead, they hook themselves up into the test process. + services: ['sauce'], + user: process.env.SAUCE_USERNAME, + key: process.env.SAUCE_ACCESS_KEY, + // // Framework you want to run your specs with. - // The following are supported: mocha, jasmine and cucumber + // The following are supported: Mocha, Jasmine, and Cucumber // see also: http://webdriver.io/guide/testrunner/frameworks.html // - // Make sure you have the node package for the specific framework installed before running - // any tests. If not please install the following package: - // Mocha: `$ npm install mocha` - // Jasmine: `$ npm install jasmine` - // Cucumber: `$ npm install cucumber` + // Make sure you have the wdio adapter package for the specific framework installed + // before running any tests. framework: 'mocha', // // Test reporter for stdout. - // The following are supported: dot (default), spec and xunit + // The following are supported: dot (default), spec, and xunit // see also: http://webdriver.io/guide/testrunner/reporters.html - reporter: 'spec', - + // reporters: ['dot'], // // Options to be passed to Mocha. // See the full list at http://mochajs.org/ mochaOpts: { ui: 'bdd', - timeout: 60000 + timeout: 100000 }, - // // ===== // Hooks // ===== - // Run functions before or after the test. If one of them returns with a promise, WebdriverIO - // will wait until that promise got resolved to continue. + // WedriverIO provides several hooks you can use to interfere with the test process in order to enhance + // it and to build services around it. You can either apply a single function or an array of + // methods to it. If one of them returns with a promise, WebdriverIO will wait until that promise got + // resolved to continue. // - // Gets executed before all workers get launched. - onPrepare: function() { - // do something - }, + // Gets executed once before all workers get launched. + // onPrepare: function (config, capabilities) { + // }, // - // Gets executed before test execution begins. At this point you will have access to all global - // variables like `browser`. It is the perfect place to define custom commands. - before: function() { - // do something - }, + // Gets executed before test execution begins. At this point you can access all global + // variables, such as `browser`. It is the perfect place to define custom commands. + // before: function (capabilities, specs) { + // }, + // + // Hook that gets executed before the suite starts + // beforeSuite: function (suite) { + // }, + // + // Hook that gets executed _before_ a hook within the suite starts (e.g. runs before calling + // beforeEach in Mocha) + // beforeHook: function () { + // }, + // + // Hook that gets executed _after_ a hook within the suite starts (e.g. runs after calling + // afterEach in Mocha) + // afterHook: function () { + // }, + // + // Function to be executed before a test (in Mocha/Jasmine) or a step (in Cucumber) starts. + // beforeTest: function (test) { + // }, + // + // Runs before a WebdriverIO command gets executed. + // beforeCommand: function (commandName, args) { + // }, + // + // Runs after a WebdriverIO command gets executed + // afterCommand: function (commandName, args, result, error) { + // }, + // + // Function to be executed after a test (in Mocha/Jasmine) or a step (in Cucumber) starts. + // afterTest: function (test) { + // }, + // + // Hook that gets executed after the suite has ended + // afterSuite: function (suite) { + // }, // // Gets executed after all tests are done. You still have access to all global variables from // the test. - after: function(failures, sessionId) { - // When runnign in SauceLabs, update the job with the test status. - if (process.env.SAUCE_USERNAME && process.env.SAUCE_ACCESS_KEY) { - var sauceAccount = new SauceLabs({ - username: process.env.SAUCE_USERNAME, - password: process.env.SAUCE_ACCESS_KEY - }); - return new Promise(function(resolve, reject) { - var data = { - passed: !failures, - build: process.env.TRAVIS_BUILD_NUMBER - }; - sauceAccount.updateJob(sessionId, data, function(err, res) { - if (err) { - reject(err); - } - else { - resolve(); - } - }); - }); - } - }, + // after: function (capabilities, specs) { + // }, // // Gets executed after all workers got shut down and the process is about to exit. It is not // possible to defer the end of the process using a promise. - onComplete: function() { - // do something - } -}; + // onComplete: function(exitCode) { + // } +} + +function getCapabilities() { + + // When running on CI, this will be true + var isSauceLabs = process.env.SAUCE_USERNAME && process.env.SAUCE_ACCESS_KEY; + + // https://wiki.saucelabs.com/display/DOCS/Platform+Configurator#/ + var capabilities = [ + {browserName: 'chrome'}, + {browserName: 'firefox'} + ]; + + if (isSauceLabs) { + capabilities = [ + { + browserName: 'chrome', + platform: 'Windows 10' + }, + { + browserName: 'firefox', + platform: 'OS X 10.11' + }, + { + browserName: 'safari', + platform: 'OS X 10.11', + version: '9.0', + }, + { + browserName: 'safari', + platform: 'OS X 10.8', + version: '6' + }, + // TODO(philipwalton) Edge webdriver is too flaky to support at this time. + // Wait for full support and then re-add: + // https://dev.windows.com/en-us/microsoft-edge/platform/status/webdriver/details/ + // { + // browserName: 'MicrosoftEdge', + // platform: 'Windows 10' + // }, + { + browserName: 'internet explorer', + platform: 'Windows 8.1', + version: '11' + }, + { + browserName: 'internet explorer', + platform: 'Windows 8', + version: '10' + }, + { + browserName: 'internet explorer', + platform: 'Windows 7', + version: '9' + } + ]; + + capabilities.forEach(function(cap) { + cap['name'] = 'analytics.js autotrack tests - ' + cap.browserName + + ' - ' + (cap.version || 'latest'); + + cap['build'] = process.env.TRAVIS_BUILD_NUMBER; + }); + }; + + return capabilities; +}