From 8f99648d4f4ff2d0871e459e164a6d93b6ac7131 Mon Sep 17 00:00:00 2001 From: Andrey Pshenkin Date: Fri, 29 Jul 2016 12:08:48 +0300 Subject: [PATCH 01/10] close tabs after test, close browser after all tests --- lib/helper/WebDriverIO.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/helper/WebDriverIO.js b/lib/helper/WebDriverIO.js index 9b599bbbc..549c335bd 100644 --- a/lib/helper/WebDriverIO.js +++ b/lib/helper/WebDriverIO.js @@ -250,7 +250,16 @@ class WebDriverIO extends Helper { if (this.options.restart) return this.browser.end(); this.debugSection('Session', 'cleaning cookies and localStorage'); return this.browser.execute('localStorage.clear();').then(() => { - return this.browser.deleteCookie(); + return this.browser.deleteCookie().then(() => { + return this.browser.waitUntil(function () { + return this.browser.getTabIds().then(function (handles) { + for (var i = 0; i < handles.length - 1; i++) { + this.browser.close(handles[i]); + } + return this.browser.switchTab(handles[0]); + }); + }, 30000); + }); }); } @@ -263,6 +272,10 @@ class WebDriverIO extends Helper { return this.saveScreenshot(fileName); } + _afterAll() { + return this.browser.end(); + } + _withinBegin(locator) { withinStore.elFn = this.browser.element; withinStore.elsFn = this.browser.elements; From 13dc1c3e3813fad163f395eb56befcdd5299764d Mon Sep 17 00:00:00 2001 From: Andrey Pshenkin Date: Fri, 29 Jul 2016 14:01:08 +0300 Subject: [PATCH 02/10] revert changes, fix afterAll --- lib/helper/WebDriverIO.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/lib/helper/WebDriverIO.js b/lib/helper/WebDriverIO.js index 549c335bd..2d68c35c6 100644 --- a/lib/helper/WebDriverIO.js +++ b/lib/helper/WebDriverIO.js @@ -250,16 +250,7 @@ class WebDriverIO extends Helper { if (this.options.restart) return this.browser.end(); this.debugSection('Session', 'cleaning cookies and localStorage'); return this.browser.execute('localStorage.clear();').then(() => { - return this.browser.deleteCookie().then(() => { - return this.browser.waitUntil(function () { - return this.browser.getTabIds().then(function (handles) { - for (var i = 0; i < handles.length - 1; i++) { - this.browser.close(handles[i]); - } - return this.browser.switchTab(handles[0]); - }); - }, 30000); - }); + return this.browser.deleteCookie(); }); } @@ -273,7 +264,7 @@ class WebDriverIO extends Helper { } _afterAll() { - return this.browser.end(); + if (!this.options.restart) return this.browser.end(); } _withinBegin(locator) { From 59cb8029d65625caf1b440b1a1712a310442b893 Mon Sep 17 00:00:00 2001 From: Andrey Pshenkin Date: Fri, 29 Jul 2016 17:53:33 +0300 Subject: [PATCH 03/10] experemental --- lib/helper/WebDriverIO.js | 18 ++++++++++++++++-- package.json | 3 ++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/helper/WebDriverIO.js b/lib/helper/WebDriverIO.js index 2d68c35c6..37cc366c8 100644 --- a/lib/helper/WebDriverIO.js +++ b/lib/helper/WebDriverIO.js @@ -12,6 +12,8 @@ const assert = require('assert'); const path = require('path'); const requireg = require('requireg'); +import series from 'async/series'; + let withinStore = {}; /** @@ -249,8 +251,20 @@ class WebDriverIO extends Helper { _after() { if (this.options.restart) return this.browser.end(); this.debugSection('Session', 'cleaning cookies and localStorage'); - return this.browser.execute('localStorage.clear();').then(() => { - return this.browser.deleteCookie(); + async.series({ + one: function(callback) { + setTimeout(function() { + callback(null, this.browser.execute('localStorage.clear();')); + }, 200); + }, + two: function(callback){ + setTimeout(function() { + callback(null, this.browser.deleteCookie()); + }, 100); + } + }, function(err, results) { + console.log(results); + // results is now equal to: {one: 1, two: 2} }); } diff --git a/package.json b/package.json index a2f903ea7..38aa4f1c2 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,8 @@ "glob": "^6.0.1", "inquirer": "^0.11.0", "mocha": "^2.4.2", - "requireg": "^0.1.5" + "requireg": "^0.1.5", + "async": "^2.0.1" }, "devDependencies": { "chai": "^3.4.1", From b446fb82108884930e219aefe3fb1b5be941ba9e Mon Sep 17 00:00:00 2001 From: Andrey Pshenkin Date: Wed, 21 Sep 2016 19:19:23 +0300 Subject: [PATCH 04/10] Implement BeforeSuite AfterSuite --- lib/interfaces/bdd.js | 42 +++++++++++++++++++----------------------- lib/scenario.js | 25 +++++++++++++++++-------- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/lib/interfaces/bdd.js b/lib/interfaces/bdd.js index 82399c4ae..2dd3a23cd 100644 --- a/lib/interfaces/bdd.js +++ b/lib/interfaces/bdd.js @@ -6,7 +6,6 @@ var Suite = require('mocha/lib/suite'); var Test = require('mocha/lib/test'); var event = require('../event'); var scenario = require('../scenario'); -var recorder = require('../recorder'); var escapeRe = require('escape-string-regexp'); /** @@ -21,22 +20,9 @@ var escapeRe = require('escape-string-regexp'); * * @param {Suite} suite Root suite. */ -module.exports = function (suite) { +module.exports = function(suite) { var suites = [suite]; - suite.timeout(0); - - suite.beforeAll('codeceptjs.beforeSuite', function(done) { - recorder.start(); - event.dispatcher.emit(event.suite.before, suite); - recorder.add(() => done()); - }); - suite.afterAll('codeceptjs.afterSuite', function(done) { - recorder.start(); - event.dispatcher.emit(event.suite.after, suite); - recorder.add(() => done()); - }); - - suite.on('pre-require', function (context, file, mocha) { + suite.on('pre-require', function(context, file, mocha) { var common = require('mocha/lib/interfaces/common')(suites, context); // create dispatcher @@ -51,7 +37,7 @@ module.exports = function (suite) { * and/or tests. */ - context.Feature = function (title) { + context.Feature = function(title) { if (suites.length > 1) { suites.shift(); } @@ -62,14 +48,25 @@ module.exports = function (suite) { suite.beforeEach('codeceptjs.before', scenario.setup); suite.afterEach('finialize codeceptjs', scenario.teardown); + suite.beforeAll('codeceptjs.beforeSuite', scenario.suiteSetup); + suite.afterAll('codeceptjs.afterSuite', scenario.suiteTeardown); + return suite; }; - context.Background = context.Before = function (fn) { + context.BeforeSuite = function(fn) { + suites[0].beforeAll('BeforeSuite', scenario.injected(fn)); + }; + + context.AfterSuite = function(fn) { + suites[0].afterAll('AfterSuite', scenario.injected(fn)); + }; + + context.Background = context.Before = function(fn) { suites[0].beforeEach('Before', scenario.injected(fn)); }; - context.After = function (fn) { + context.After = function(fn) { suites[0].afterEach('After', scenario.injected(fn)); }; @@ -78,13 +75,12 @@ module.exports = function (suite) { * with the given `title` and callback `fn` * acting as a thunk. */ - context.Scenario = function (title, fn) { + context.Scenario = function(title, fn) { var suite = suites[0]; if (suite.pending) { fn = null; } var test = new Test(title, fn); - test.fullTitle = () => `${suite.title}: ${title}`; test.file = file; test.async = true; test.timeout(0); @@ -95,7 +91,7 @@ module.exports = function (suite) { /** * Exclusive test-case. */ - context.Scenario.only = function (title, fn) { + context.Scenario.only = function(title, fn) { var test = context.Scenario(title, fn); var reString = '^' + escapeRe(test.fullTitle()) + '$'; mocha.grep(new RegExp(reString)); @@ -104,7 +100,7 @@ module.exports = function (suite) { /** * Pending test case. */ - context.xScenario = context.Scenario.skip = function (title) { + context.xScenario = context.Scenario.skip = function(title) { context.Scenario(title); }; }); diff --git a/lib/scenario.js b/lib/scenario.js index ad83c08ea..97c2d7430 100644 --- a/lib/scenario.js +++ b/lib/scenario.js @@ -16,8 +16,8 @@ module.exports.test = (test) => { } test.steps = []; - test.fn = function (done) { - recorder.errHandler(function (err) { + test.fn = function(done) { + recorder.errHandler(function(err) { recorder.session.start('teardown'); event.emit(event.test.failed, test, err); recorder.add(() => done(err)); @@ -34,8 +34,8 @@ module.exports.test = (test) => { return test; } recorder.catch(); // catching possible errors in promises - let resumeTest = function () { - recorder.add('create new promises queue for generator',function (data) { + let resumeTest = function() { + recorder.add('create new promises queue for generator', function(data) { recorder.session.start('generator'); // creating a new promise chain try { let resume = res.next(data); @@ -67,8 +67,8 @@ module.exports.test = (test) => { /** * Injects arguments to function from controller */ -module.exports.injected = function (fn) { - return function () { +module.exports.injected = function(fn) { + return function() { try { fn.apply(this, getInjectedArguments(fn)); } catch (err) { @@ -81,15 +81,24 @@ module.exports.injected = function (fn) { /** * Starts promise chain, so helpers could enqueue their hooks */ -module.exports.setup = function () { +module.exports.setup = function() { recorder.start(); event.emit(event.test.before); }; -module.exports.teardown = function () { +module.exports.teardown = function() { event.emit(event.test.after); }; +module.exports.suiteSetup = function() { + recorder.start(); + event.emit(event.suite.before); +}; + +module.exports.suiteTeardown = function() { + event.emit(event.suite.after); +}; + function isGenerator(fn) { return fn.constructor.name === 'GeneratorFunction'; } From 6182693ea5eeaa569688b70dc2aa3aec9c8b95ba Mon Sep 17 00:00:00 2001 From: Andrey Pshenkin Date: Wed, 21 Sep 2016 19:24:56 +0300 Subject: [PATCH 05/10] Remove temp changes --- lib/helper/WebDriverIO.js | 205 +++++++++++++++++++------------------- lib/interfaces/bdd.js | 14 +++ package.json | 3 +- 3 files changed, 120 insertions(+), 102 deletions(-) diff --git a/lib/helper/WebDriverIO.js b/lib/helper/WebDriverIO.js index adbc8eb4e..b97adbf4e 100644 --- a/lib/helper/WebDriverIO.js +++ b/lib/helper/WebDriverIO.js @@ -12,7 +12,6 @@ const assert = require('assert'); const path = require('path'); const requireg = require('requireg'); -import series from 'async/series'; let withinStore = {}; @@ -201,25 +200,29 @@ class WebDriverIO extends Helper { } } - static _checkRequirements() - { + static _checkRequirements() { try { requireg("webdriverio"); - } catch(e) { + } catch (e) { return ["webdriverio"]; } } static _config() { - return [ - { name: 'url', message: "Base url of site to be tested", default: 'http://localhost' }, - { name: 'browser', message: 'Browser in which testing will be performed', default: 'firefox' } - ]; + return [{ + name: 'url', + message: "Base url of site to be tested", + default: 'http://localhost' + }, { + name: 'browser', + message: 'Browser in which testing will be performed', + default: 'firefox' + }]; } _beforeSuite() { if (!this.options.restart) { - this.debugSection('Session','Starting singleton browser session'); + this.debugSection('Session', 'Starting singleton browser session'); return this._startBrowser(); } } @@ -236,7 +239,10 @@ class WebDriverIO extends Helper { } if (this.options.windowSize && this.options.windowSize.indexOf('x') > 0) { let dimensions = this.options.windowSize.split('x'); - this.browser.windowHandleSize({ width: dimensions[0], height: dimensions[1] }); + this.browser.windowHandleSize({ + width: dimensions[0], + height: dimensions[1] + }); } return this.browser; } @@ -251,20 +257,9 @@ class WebDriverIO extends Helper { _after() { if (this.options.restart) return this.browser.end(); this.debugSection('Session', 'cleaning cookies and localStorage'); - async.series({ - one: function(callback) { - setTimeout(function() { - callback(null, this.browser.execute('localStorage.clear();')); - }, 200); - }, - two: function(callback){ - setTimeout(function() { - callback(null, this.browser.deleteCookie()); - }, 100); - } - }, function(err, results) { - console.log(results); - // results is now equal to: {one: 1, two: 2} + return this.browser.execute('localStorage.clear();').then(() => { + - + return this.browser.deleteCookie(); }); } @@ -277,19 +272,15 @@ class WebDriverIO extends Helper { return this.saveScreenshot(fileName); } - _afterAll() { - if (!this.options.restart) return this.browser.end(); - } - _withinBegin(locator) { withinStore.elFn = this.browser.element; withinStore.elsFn = this.browser.elements; this.context = locator; return this.browser.element(withStrictLocator(locator)).then((res) => { - this.browser.element = function (l) { + this.browser.element = function(l) { return this.elementIdElement(res.value.ELEMENT, l); }; - this.browser.elements = function (l) { + this.browser.elements = function(l) { return this.elementIdElements(res.value.ELEMENT, l); }; }); @@ -321,7 +312,7 @@ class WebDriverIO extends Helper { * ``` */ _locateCheckable(locator) { - return findCheckable(this.browser, locator).then(function(res){ + return findCheckable(this.browser, locator).then(function(res) { return res.value; }) } @@ -334,7 +325,7 @@ class WebDriverIO extends Helper { * ``` */ _locateClickable(locator) { - return findClickable(this.browser, locator).then(function(res){ + return findClickable(this.browser, locator).then(function(res) { return res.value; }) } @@ -347,7 +338,7 @@ class WebDriverIO extends Helper { * ``` */ _locateFields(locator) { - return findFields(this.browser, locator).then(function(res){ + return findFields(this.browser, locator).then(function(res) { return res.value; }) } @@ -371,7 +362,7 @@ class WebDriverIO extends Helper { if (context) { client = client.element(context); } - return findClickable(client, locator).then(function (res) { + return findClickable(client, locator).then(function(res) { if (!res.value || res.value.length === 0) { if (typeof(locator) === "object") locator = JSON.stringify(locator); throw new Error(`Clickable element ${locator.toString()} was not found by text|CSS|XPath`); @@ -389,7 +380,7 @@ class WebDriverIO extends Helper { if (context) { client = client.element(context); } - return findClickable(client, locator).then(function (res) { + return findClickable(client, locator).then(function(res) { if (!res.value || res.value.length === 0) { if (typeof(locator) === "object") locator = JSON.stringify(locator); throw new Error(`Clickable element ${locator.toString()} was not found by text|CSS|XPath`); @@ -410,7 +401,7 @@ class WebDriverIO extends Helper { * {{> ../webapi/fillField }} */ fillField(field, value) { - return findFields(this.browser, field).then(function (res) { + return findFields(this.browser, field).then(function(res) { if (!res.value || res.value.length === 0) { throw new Error(`Field ${field} not found by name|text|CSS|XPath`); } @@ -423,7 +414,7 @@ class WebDriverIO extends Helper { * {{> ../webapi/appendField }} */ appendField(field, value) { - return findFields(this.browser, field).then(function (res) { + return findFields(this.browser, field).then(function(res) { if (!res.value || res.value.length === 0) { throw new Error(`Field ${field} not found by name|text|CSS|XPath`); } @@ -437,7 +428,7 @@ class WebDriverIO extends Helper { * */ selectOption(select, option) { - return findFields(this.browser, select).then(function (res) { + return findFields(this.browser, select).then(function(res) { if (!res.value || res.value.length === 0) { throw new Error(`Selectable field ${select} not found by name|text|CSS|XPath`); } @@ -455,7 +446,9 @@ class WebDriverIO extends Helper { byVisibleText = `./option${normalized}|./optgroup/option${normalized}`; commands.push(this.elementIdElements(elem.ELEMENT, byVisibleText)); }); - return this.unify(commands, { extractValue: true }).then((els) => { + return this.unify(commands, { + extractValue: true + }).then((els) => { commands = []; let clickOptionFn = (el) => { if (el[0]) el = el[0]; @@ -474,7 +467,9 @@ class WebDriverIO extends Helper { commands.push(this.elementIdElements(elem.ELEMENT, byValue)); }); // try by value - return this.unify(commands, { extractValue: true }).then((els) => { + return this.unify(commands, { + extractValue: true + }).then((els) => { if (els.length === 0) { throw new Error(`Option ${option} in ${select} was found neither by visible text not by value`); } @@ -518,7 +513,7 @@ class WebDriverIO extends Helper { throw new Error(`Checkable ${field} cant be located by name|text|CSS|XPath`); } let elem = res.value[0]; - return client.elementIdSelected(elem.ELEMENT).then(function (isSelected) { + return client.elementIdSelected(elem.ELEMENT).then(function(isSelected) { if (isSelected.value) return true; return this[clickMethod](elem.ELEMENT); }); @@ -529,7 +524,7 @@ class WebDriverIO extends Helper { * {{> ../webapi/grabTextFrom }} */ grabTextFrom(locator) { - return this.browser.getText(withStrictLocator(locator)).then(function (text) { + return this.browser.getText(withStrictLocator(locator)).then(function(text) { return text; }); } @@ -543,16 +538,16 @@ class WebDriverIO extends Helper { * ``` */ grabHTMLFrom(locator) { - return this.browser.getHTML(withStrictLocator(locator)).then(function (html) { + return this.browser.getHTML(withStrictLocator(locator)).then(function(html) { return html; }); } /** * {{> ../webapi/grabValueFrom }} - */ + */ grabValueFrom(locator) { - return this.browser.getValue(withStrictLocator(locator)).then(function (text) { + return this.browser.getValue(withStrictLocator(locator)).then(function(text) { return text; }); } @@ -561,7 +556,7 @@ class WebDriverIO extends Helper { * {{> ../webapi/grabAttributeFrom }} */ grabAttributeFrom(locator, attr) { - return this.browser.getAttribute(withStrictLocator(locator), attr).then(function (text) { + return this.browser.getAttribute(withStrictLocator(locator), attr).then(function(text) { return text; }); } @@ -640,8 +635,8 @@ class WebDriverIO extends Helper { * {{> ../webapi/seeElement }} */ seeElement(locator) { - return this.browser.isVisible(withStrictLocator(locator)).then(function (res) { - return truth(`elements of ${locator}`,'to be seen').assert(res); + return this.browser.isVisible(withStrictLocator(locator)).then(function(res) { + return truth(`elements of ${locator}`, 'to be seen').assert(res); }); } @@ -649,7 +644,7 @@ class WebDriverIO extends Helper { * {{> ../webapi/dontSeeElement}} */ dontSeeElement(locator) { - return this.browser.isVisible(withStrictLocator(locator)).then(function (res) { + return this.browser.isVisible(withStrictLocator(locator)).then(function(res) { return truth(`elements of ${locator}`, 'to be seen').negate(res); }); } @@ -658,7 +653,7 @@ class WebDriverIO extends Helper { * {{> ../webapi/seeElementInDOM }} */ seeElementInDOM(locator) { - return this.browser.elements(withStrictLocator(locator)).then(function (res) { + return this.browser.elements(withStrictLocator(locator)).then(function(res) { return empty('elements').negate(res.value); }); } @@ -667,7 +662,7 @@ class WebDriverIO extends Helper { * {{> ../webapi/dontSeeElementInDOM }} */ dontSeeElementInDOM(locator) { - return this.browser.elements(withStrictLocator(locator)).then(function (res) { + return this.browser.elements(withStrictLocator(locator)).then(function(res) { return empty('elements').assert(res.value); }); } @@ -691,25 +686,25 @@ class WebDriverIO extends Helper { } /** - * asserts that an element appears a given number of times in the DOM - * Element is located by label or name or CSS or XPath. - * - * ```js - * I.seeNumberOfElements('#submitBtn', 1); - * ``` - */ + * asserts that an element appears a given number of times in the DOM + * Element is located by label or name or CSS or XPath. + * + * ```js + * I.seeNumberOfElements('#submitBtn', 1); + * ``` + */ seeNumberOfElements(selector, num) { return this.browser.elements(withStrictLocator(selector)) - .then(function (res) { - return assert.equal(res.value.length, num); - }); + .then(function(res) { + return assert.equal(res.value.length, num); + }); } /** * {{> ../webapi/seeInCurrentUrl }} */ seeInCurrentUrl(url) { - return this.browser.url().then(function (res) { + return this.browser.url().then(function(res) { return stringIncludes('url').assert(url, res.value); }); } @@ -718,7 +713,7 @@ class WebDriverIO extends Helper { * {{> ../webapi/dontSeeInCurrentUrl }} */ dontSeeInCurrentUrl(url) { - return this.browser.url().then(function (res) { + return this.browser.url().then(function(res) { return stringIncludes('url').negate(url, res.value); }); } @@ -733,8 +728,8 @@ class WebDriverIO extends Helper { } /** - * {{> ../webapi/dontSeeCurrentUrlEquals }} - */ + * {{> ../webapi/dontSeeCurrentUrlEquals }} + */ dontSeeCurrentUrlEquals(url) { return this.browser.url().then((res) => { return urlEquals(this.options.url).negate(url, res.value); @@ -817,7 +812,7 @@ class WebDriverIO extends Helper { * {{> ../webapi/seeCookie}} */ seeCookie(name) { - return this.browser.getCookie(name).then(function (res) { + return this.browser.getCookie(name).then(function(res) { return truth('cookie ' + name, 'to be set').assert(res); }); } @@ -826,7 +821,7 @@ class WebDriverIO extends Helper { * {{> ../webapi/dontSeeCookie}} */ dontSeeCookie(name) { - return this.browser.getCookie(name).then(function (res) { + return this.browser.getCookie(name).then(function(res) { return truth('cookie ' + name, 'to be set').negate(res); }); } @@ -843,7 +838,7 @@ class WebDriverIO extends Helper { * Don't confuse popups with modal windows, as created by [various libraries](http://jster.net/category/windows-modals-popups). */ acceptPopup() { - return this.browser.alertText().then(function (res) { + return this.browser.alertText().then(function(res) { if (res !== null) { return this.alertAccept(); } @@ -854,7 +849,7 @@ class WebDriverIO extends Helper { * Dismisses the active JavaScript popup, as created by window.alert|window.confirm|window.prompt. */ cancelPopup() { - return this.browser.alertText().then(function (res) { + return this.browser.alertText().then(function(res) { if (res !== null) { return this.alertDismiss(); } @@ -865,9 +860,9 @@ class WebDriverIO extends Helper { * Checks that the active JavaScript popup, as created by `window.alert|window.confirm|window.prompt`, contains the given string. */ seeInPopup(text) { - return this.browser.alertText().then(function (res) { + return this.browser.alertText().then(function(res) { if (res === null) { - throw new Error('Popup is not opened'); + throw new Error('Popup is not opened'); } stringIncludes('text in popup').assert(text, res); }); @@ -886,7 +881,7 @@ class WebDriverIO extends Helper { */ pressKey(key) { let modifier; - if (Array.isArray(key) && ~['Control','Command','Shift','Alt'].indexOf(key[0])) { + if (Array.isArray(key) && ~['Control', 'Command', 'Shift', 'Alt'].indexOf(key[0])) { modifier = key[0]; } return this.browser.keys(key).then(function() { @@ -902,16 +897,19 @@ class WebDriverIO extends Helper { if (width === 'maximize') { return this.browser.windowHandleMaximize(false); } - return this.browser.windowHandleSize({ width, height }); + return this.browser.windowHandleSize({ + width, + height + }); } - /** - * Drag an item to a destination element. - * - * ```js - * I.dragAndDrop('#dragHandle', '#container'); - * ``` - */ + /** + * Drag an item to a destination element. + * + * ```js + * I.dragAndDrop('#dragHandle', '#container'); + * ``` + */ dragAndDrop(srcElement, destElement) { return this.browser.dragAndDrop( withStrictLocator(srcElement), @@ -948,8 +946,8 @@ class WebDriverIO extends Helper { waitForText(text, sec, context) { sec = sec || this.options.waitForTimeout; context = context || 'body'; - return this.browser.waitUntil(function () { - return this.getText(context).then(function (source) { + return this.browser.waitUntil(function() { + return this.getText(context).then(function(source) { if (Array.isArray(source)) { return source.filter(part => part.indexOf(text) >= 0).length > 0; } @@ -1011,13 +1009,13 @@ function proceedSee(assertType, text, context) { } else { description = 'element ' + context; } - return this.browser.getText(withStrictLocator(context)).then(function (source) { + return this.browser.getText(withStrictLocator(context)).then(function(source) { return stringIncludes(description)[assertType](text, source); }); } function findClickable(client, locator) { - if (typeof (locator) === 'object') return client.elements(withStrictLocator(locator)); + if (typeof(locator) === 'object') return client.elements(withStrictLocator(locator)); if (isCSSorXPathLocator(locator)) return client.elements(locator); let literal = xpathLocator.literal(locator); @@ -1028,7 +1026,7 @@ function findClickable(client, locator) { `.//a/img[normalize-space(@alt)=${literal}]/ancestor::a`, `.//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][normalize-space(@value)=${literal}]` ]); - return client.elements(narrowLocator).then(function (els) { + return client.elements(narrowLocator).then(function(els) { if (els.value.length) { return els; } @@ -1040,7 +1038,7 @@ function findClickable(client, locator) { `.//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][./@name = ${literal}]`, `.//button[./@name = ${literal}]` ]); - return client.elements(wideLocator).then(function (els) { + return client.elements(wideLocator).then(function(els) { if (els.value.length) { return els; } @@ -1050,7 +1048,7 @@ function findClickable(client, locator) { } function findFields(client, locator) { - if (typeof (locator) === 'object') return client.elements(withStrictLocator(locator)); + if (typeof(locator) === 'object') return client.elements(withStrictLocator(locator)); if (isCSSorXPathLocator(locator)) return client.elements(locator); let literal = xpathLocator.literal(locator); @@ -1069,7 +1067,7 @@ function findFields(client, locator) { } function proceedSeeField(assertType, field, value) { - return findFields(this.browser, field).then(function (res) { + return findFields(this.browser, field).then(function(res) { if (!res.value || res.value.length === 0) { throw new Error(`Field ${field} not found by name|text|CSS|XPath`); } @@ -1083,7 +1081,9 @@ function proceedSeeField(assertType, field, value) { if (el.value === false) return; commands.push(this.elementIdAttribute(el.ELEMENT, 'value')); }); - this.unify(commands, { extractValue: true }).then((val) => { + this.unify(commands, { + extractValue: true + }).then((val) => { return stringIncludes('fields by ' + field)[assertType](value, val); }); }); @@ -1114,20 +1114,22 @@ function proceedSeeField(assertType, field, value) { } function proceedSeeCheckbox(assertType, field) { - return findFields(this.browser, field).then(function (res) { + return findFields(this.browser, field).then(function(res) { if (!res.value || res.value.length === 0) { throw new Error(`Field ${field} not found by name|text|CSS|XPath`); } let commands = []; res.value.forEach((el) => commands.push(this.elementIdSelected(el.ELEMENT))); - return this.unify(commands, { extractValue: true }).then((selected) => { + return this.unify(commands, { + extractValue: true + }).then((selected) => { return truth(`checkable field ${field}`, 'to be checked')[assertType](selected); }); }); } function findCheckable(client, locator) { - if (typeof (locator) === 'object') return client.elements(withStrictLocator(locator)); + if (typeof(locator) === 'object') return client.elements(withStrictLocator(locator)); if (isCSSorXPathLocator(locator)) return client.elements(locator); let literal = xpathLocator.literal(locator); @@ -1135,10 +1137,10 @@ function findCheckable(client, locator) { `.//input[@type = 'checkbox' or @type = 'radio'][(@id = //label[contains(normalize-space(string(.)), ${literal})]/@for) or @placeholder = ${literal}]`, `.//label[contains(normalize-space(string(.)), ${literal})]//input[@type = 'radio' or @type = 'checkbox']` ]); - return client.elements(byText).then(function (els) { + return client.elements(byText).then(function(els) { if (els.value.length) return els; let byName = `.//input[@type = 'checkbox' or @type = 'radio'][@name = ${literal}]`; - return client.elements(byName).then(function (els) { + return client.elements(byName).then(function(els) { if (els.value.length) return els; return client.elements(locator); // by css or xpath }); @@ -1157,18 +1159,21 @@ function isCSSorXPathLocator(locator) { function withStrictLocator(locator) { if (!locator) return null; - if (typeof (locator) !== 'object') return locator; + if (typeof(locator) !== 'object') return locator; let key = Object.keys(locator)[0]; let value = locator[key]; locator.toString = () => `{${key}: '${value}'}`; switch (key) { - case 'by': - case 'xpath': - case 'css': return value; - case 'id': return '#' + value; - case 'name': return `[name="${value}"]`; + case 'by': + case 'xpath': + case 'css': + return value; + case 'id': + return '#' + value; + case 'name': + return `[name="${value}"]`; } } diff --git a/lib/interfaces/bdd.js b/lib/interfaces/bdd.js index 2dd3a23cd..22ad105d8 100644 --- a/lib/interfaces/bdd.js +++ b/lib/interfaces/bdd.js @@ -6,6 +6,7 @@ var Suite = require('mocha/lib/suite'); var Test = require('mocha/lib/test'); var event = require('../event'); var scenario = require('../scenario'); +var recorder = require('../recorder'); var escapeRe = require('escape-string-regexp'); /** @@ -22,6 +23,19 @@ var escapeRe = require('escape-string-regexp'); */ module.exports = function(suite) { var suites = [suite]; + suite.timeout(0); + + suite.beforeAll('codeceptjs.beforeSuite', function(done) { + recorder.start(); + event.dispatcher.emit(event.suite.before, suite); + recorder.add(() => done()); + }); + suite.afterAll('codeceptjs.afterSuite', function(done) { + recorder.start(); + event.dispatcher.emit(event.suite.after, suite); + recorder.add(() => done()); + }); + suite.on('pre-require', function(context, file, mocha) { var common = require('mocha/lib/interfaces/common')(suites, context); diff --git a/package.json b/package.json index 1b939d2f1..190f0e8a3 100644 --- a/package.json +++ b/package.json @@ -33,8 +33,7 @@ "glob": "^6.0.1", "inquirer": "^0.11.0", "mocha": "^2.4.2", - "requireg": "^0.1.5", - "async": "^2.0.1" + "requireg": "^0.1.5" }, "devDependencies": { "chai": "^3.4.1", From 3ed77fc554f5dbc1f44e67961b4980d645d1143b Mon Sep 17 00:00:00 2001 From: Andrey Pshenkin Date: Wed, 21 Sep 2016 19:28:50 +0300 Subject: [PATCH 06/10] remove formatting --- lib/helper/WebDriverIO.js | 184 +++++++++++++++++--------------------- 1 file changed, 81 insertions(+), 103 deletions(-) diff --git a/lib/helper/WebDriverIO.js b/lib/helper/WebDriverIO.js index b97adbf4e..820576615 100644 --- a/lib/helper/WebDriverIO.js +++ b/lib/helper/WebDriverIO.js @@ -200,29 +200,25 @@ class WebDriverIO extends Helper { } } - static _checkRequirements() { + static _checkRequirements() + { try { requireg("webdriverio"); - } catch (e) { + } catch(e) { return ["webdriverio"]; } } static _config() { - return [{ - name: 'url', - message: "Base url of site to be tested", - default: 'http://localhost' - }, { - name: 'browser', - message: 'Browser in which testing will be performed', - default: 'firefox' - }]; + return [ + { name: 'url', message: "Base url of site to be tested", default: 'http://localhost' }, + { name: 'browser', message: 'Browser in which testing will be performed', default: 'firefox' } + ]; } _beforeSuite() { if (!this.options.restart) { - this.debugSection('Session', 'Starting singleton browser session'); + this.debugSection('Session','Starting singleton browser session'); return this._startBrowser(); } } @@ -239,10 +235,7 @@ class WebDriverIO extends Helper { } if (this.options.windowSize && this.options.windowSize.indexOf('x') > 0) { let dimensions = this.options.windowSize.split('x'); - this.browser.windowHandleSize({ - width: dimensions[0], - height: dimensions[1] - }); + this.browser.windowHandleSize({ width: dimensions[0], height: dimensions[1] }); } return this.browser; } @@ -258,7 +251,6 @@ class WebDriverIO extends Helper { if (this.options.restart) return this.browser.end(); this.debugSection('Session', 'cleaning cookies and localStorage'); return this.browser.execute('localStorage.clear();').then(() => { - - return this.browser.deleteCookie(); }); } @@ -277,10 +269,10 @@ class WebDriverIO extends Helper { withinStore.elsFn = this.browser.elements; this.context = locator; return this.browser.element(withStrictLocator(locator)).then((res) => { - this.browser.element = function(l) { + this.browser.element = function (l) { return this.elementIdElement(res.value.ELEMENT, l); }; - this.browser.elements = function(l) { + this.browser.elements = function (l) { return this.elementIdElements(res.value.ELEMENT, l); }; }); @@ -312,7 +304,7 @@ class WebDriverIO extends Helper { * ``` */ _locateCheckable(locator) { - return findCheckable(this.browser, locator).then(function(res) { + return findCheckable(this.browser, locator).then(function(res){ return res.value; }) } @@ -325,7 +317,7 @@ class WebDriverIO extends Helper { * ``` */ _locateClickable(locator) { - return findClickable(this.browser, locator).then(function(res) { + return findClickable(this.browser, locator).then(function(res){ return res.value; }) } @@ -338,7 +330,7 @@ class WebDriverIO extends Helper { * ``` */ _locateFields(locator) { - return findFields(this.browser, locator).then(function(res) { + return findFields(this.browser, locator).then(function(res){ return res.value; }) } @@ -362,7 +354,7 @@ class WebDriverIO extends Helper { if (context) { client = client.element(context); } - return findClickable(client, locator).then(function(res) { + return findClickable(client, locator).then(function (res) { if (!res.value || res.value.length === 0) { if (typeof(locator) === "object") locator = JSON.stringify(locator); throw new Error(`Clickable element ${locator.toString()} was not found by text|CSS|XPath`); @@ -380,7 +372,7 @@ class WebDriverIO extends Helper { if (context) { client = client.element(context); } - return findClickable(client, locator).then(function(res) { + return findClickable(client, locator).then(function (res) { if (!res.value || res.value.length === 0) { if (typeof(locator) === "object") locator = JSON.stringify(locator); throw new Error(`Clickable element ${locator.toString()} was not found by text|CSS|XPath`); @@ -401,7 +393,7 @@ class WebDriverIO extends Helper { * {{> ../webapi/fillField }} */ fillField(field, value) { - return findFields(this.browser, field).then(function(res) { + return findFields(this.browser, field).then(function (res) { if (!res.value || res.value.length === 0) { throw new Error(`Field ${field} not found by name|text|CSS|XPath`); } @@ -414,7 +406,7 @@ class WebDriverIO extends Helper { * {{> ../webapi/appendField }} */ appendField(field, value) { - return findFields(this.browser, field).then(function(res) { + return findFields(this.browser, field).then(function (res) { if (!res.value || res.value.length === 0) { throw new Error(`Field ${field} not found by name|text|CSS|XPath`); } @@ -428,7 +420,7 @@ class WebDriverIO extends Helper { * */ selectOption(select, option) { - return findFields(this.browser, select).then(function(res) { + return findFields(this.browser, select).then(function (res) { if (!res.value || res.value.length === 0) { throw new Error(`Selectable field ${select} not found by name|text|CSS|XPath`); } @@ -446,9 +438,7 @@ class WebDriverIO extends Helper { byVisibleText = `./option${normalized}|./optgroup/option${normalized}`; commands.push(this.elementIdElements(elem.ELEMENT, byVisibleText)); }); - return this.unify(commands, { - extractValue: true - }).then((els) => { + return this.unify(commands, { extractValue: true }).then((els) => { commands = []; let clickOptionFn = (el) => { if (el[0]) el = el[0]; @@ -467,9 +457,7 @@ class WebDriverIO extends Helper { commands.push(this.elementIdElements(elem.ELEMENT, byValue)); }); // try by value - return this.unify(commands, { - extractValue: true - }).then((els) => { + return this.unify(commands, { extractValue: true }).then((els) => { if (els.length === 0) { throw new Error(`Option ${option} in ${select} was found neither by visible text not by value`); } @@ -513,7 +501,7 @@ class WebDriverIO extends Helper { throw new Error(`Checkable ${field} cant be located by name|text|CSS|XPath`); } let elem = res.value[0]; - return client.elementIdSelected(elem.ELEMENT).then(function(isSelected) { + return client.elementIdSelected(elem.ELEMENT).then(function (isSelected) { if (isSelected.value) return true; return this[clickMethod](elem.ELEMENT); }); @@ -524,7 +512,7 @@ class WebDriverIO extends Helper { * {{> ../webapi/grabTextFrom }} */ grabTextFrom(locator) { - return this.browser.getText(withStrictLocator(locator)).then(function(text) { + return this.browser.getText(withStrictLocator(locator)).then(function (text) { return text; }); } @@ -538,16 +526,16 @@ class WebDriverIO extends Helper { * ``` */ grabHTMLFrom(locator) { - return this.browser.getHTML(withStrictLocator(locator)).then(function(html) { + return this.browser.getHTML(withStrictLocator(locator)).then(function (html) { return html; }); } /** * {{> ../webapi/grabValueFrom }} - */ + */ grabValueFrom(locator) { - return this.browser.getValue(withStrictLocator(locator)).then(function(text) { + return this.browser.getValue(withStrictLocator(locator)).then(function (text) { return text; }); } @@ -556,7 +544,7 @@ class WebDriverIO extends Helper { * {{> ../webapi/grabAttributeFrom }} */ grabAttributeFrom(locator, attr) { - return this.browser.getAttribute(withStrictLocator(locator), attr).then(function(text) { + return this.browser.getAttribute(withStrictLocator(locator), attr).then(function (text) { return text; }); } @@ -635,8 +623,8 @@ class WebDriverIO extends Helper { * {{> ../webapi/seeElement }} */ seeElement(locator) { - return this.browser.isVisible(withStrictLocator(locator)).then(function(res) { - return truth(`elements of ${locator}`, 'to be seen').assert(res); + return this.browser.isVisible(withStrictLocator(locator)).then(function (res) { + return truth(`elements of ${locator}`,'to be seen').assert(res); }); } @@ -644,7 +632,7 @@ class WebDriverIO extends Helper { * {{> ../webapi/dontSeeElement}} */ dontSeeElement(locator) { - return this.browser.isVisible(withStrictLocator(locator)).then(function(res) { + return this.browser.isVisible(withStrictLocator(locator)).then(function (res) { return truth(`elements of ${locator}`, 'to be seen').negate(res); }); } @@ -653,7 +641,7 @@ class WebDriverIO extends Helper { * {{> ../webapi/seeElementInDOM }} */ seeElementInDOM(locator) { - return this.browser.elements(withStrictLocator(locator)).then(function(res) { + return this.browser.elements(withStrictLocator(locator)).then(function (res) { return empty('elements').negate(res.value); }); } @@ -662,7 +650,7 @@ class WebDriverIO extends Helper { * {{> ../webapi/dontSeeElementInDOM }} */ dontSeeElementInDOM(locator) { - return this.browser.elements(withStrictLocator(locator)).then(function(res) { + return this.browser.elements(withStrictLocator(locator)).then(function (res) { return empty('elements').assert(res.value); }); } @@ -686,25 +674,25 @@ class WebDriverIO extends Helper { } /** - * asserts that an element appears a given number of times in the DOM - * Element is located by label or name or CSS or XPath. - * - * ```js - * I.seeNumberOfElements('#submitBtn', 1); - * ``` - */ + * asserts that an element appears a given number of times in the DOM + * Element is located by label or name or CSS or XPath. + * + * ```js + * I.seeNumberOfElements('#submitBtn', 1); + * ``` + */ seeNumberOfElements(selector, num) { return this.browser.elements(withStrictLocator(selector)) - .then(function(res) { - return assert.equal(res.value.length, num); - }); + .then(function (res) { + return assert.equal(res.value.length, num); + }); } /** * {{> ../webapi/seeInCurrentUrl }} */ seeInCurrentUrl(url) { - return this.browser.url().then(function(res) { + return this.browser.url().then(function (res) { return stringIncludes('url').assert(url, res.value); }); } @@ -713,7 +701,7 @@ class WebDriverIO extends Helper { * {{> ../webapi/dontSeeInCurrentUrl }} */ dontSeeInCurrentUrl(url) { - return this.browser.url().then(function(res) { + return this.browser.url().then(function (res) { return stringIncludes('url').negate(url, res.value); }); } @@ -728,8 +716,8 @@ class WebDriverIO extends Helper { } /** - * {{> ../webapi/dontSeeCurrentUrlEquals }} - */ + * {{> ../webapi/dontSeeCurrentUrlEquals }} + */ dontSeeCurrentUrlEquals(url) { return this.browser.url().then((res) => { return urlEquals(this.options.url).negate(url, res.value); @@ -812,7 +800,7 @@ class WebDriverIO extends Helper { * {{> ../webapi/seeCookie}} */ seeCookie(name) { - return this.browser.getCookie(name).then(function(res) { + return this.browser.getCookie(name).then(function (res) { return truth('cookie ' + name, 'to be set').assert(res); }); } @@ -821,7 +809,7 @@ class WebDriverIO extends Helper { * {{> ../webapi/dontSeeCookie}} */ dontSeeCookie(name) { - return this.browser.getCookie(name).then(function(res) { + return this.browser.getCookie(name).then(function (res) { return truth('cookie ' + name, 'to be set').negate(res); }); } @@ -838,7 +826,7 @@ class WebDriverIO extends Helper { * Don't confuse popups with modal windows, as created by [various libraries](http://jster.net/category/windows-modals-popups). */ acceptPopup() { - return this.browser.alertText().then(function(res) { + return this.browser.alertText().then(function (res) { if (res !== null) { return this.alertAccept(); } @@ -849,7 +837,7 @@ class WebDriverIO extends Helper { * Dismisses the active JavaScript popup, as created by window.alert|window.confirm|window.prompt. */ cancelPopup() { - return this.browser.alertText().then(function(res) { + return this.browser.alertText().then(function (res) { if (res !== null) { return this.alertDismiss(); } @@ -860,9 +848,9 @@ class WebDriverIO extends Helper { * Checks that the active JavaScript popup, as created by `window.alert|window.confirm|window.prompt`, contains the given string. */ seeInPopup(text) { - return this.browser.alertText().then(function(res) { + return this.browser.alertText().then(function (res) { if (res === null) { - throw new Error('Popup is not opened'); + throw new Error('Popup is not opened'); } stringIncludes('text in popup').assert(text, res); }); @@ -881,7 +869,7 @@ class WebDriverIO extends Helper { */ pressKey(key) { let modifier; - if (Array.isArray(key) && ~['Control', 'Command', 'Shift', 'Alt'].indexOf(key[0])) { + if (Array.isArray(key) && ~['Control','Command','Shift','Alt'].indexOf(key[0])) { modifier = key[0]; } return this.browser.keys(key).then(function() { @@ -897,19 +885,16 @@ class WebDriverIO extends Helper { if (width === 'maximize') { return this.browser.windowHandleMaximize(false); } - return this.browser.windowHandleSize({ - width, - height - }); + return this.browser.windowHandleSize({ width, height }); } - /** - * Drag an item to a destination element. - * - * ```js - * I.dragAndDrop('#dragHandle', '#container'); - * ``` - */ + /** + * Drag an item to a destination element. + * + * ```js + * I.dragAndDrop('#dragHandle', '#container'); + * ``` + */ dragAndDrop(srcElement, destElement) { return this.browser.dragAndDrop( withStrictLocator(srcElement), @@ -946,8 +931,8 @@ class WebDriverIO extends Helper { waitForText(text, sec, context) { sec = sec || this.options.waitForTimeout; context = context || 'body'; - return this.browser.waitUntil(function() { - return this.getText(context).then(function(source) { + return this.browser.waitUntil(function () { + return this.getText(context).then(function (source) { if (Array.isArray(source)) { return source.filter(part => part.indexOf(text) >= 0).length > 0; } @@ -1009,13 +994,13 @@ function proceedSee(assertType, text, context) { } else { description = 'element ' + context; } - return this.browser.getText(withStrictLocator(context)).then(function(source) { + return this.browser.getText(withStrictLocator(context)).then(function (source) { return stringIncludes(description)[assertType](text, source); }); } function findClickable(client, locator) { - if (typeof(locator) === 'object') return client.elements(withStrictLocator(locator)); + if (typeof (locator) === 'object') return client.elements(withStrictLocator(locator)); if (isCSSorXPathLocator(locator)) return client.elements(locator); let literal = xpathLocator.literal(locator); @@ -1026,7 +1011,7 @@ function findClickable(client, locator) { `.//a/img[normalize-space(@alt)=${literal}]/ancestor::a`, `.//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][normalize-space(@value)=${literal}]` ]); - return client.elements(narrowLocator).then(function(els) { + return client.elements(narrowLocator).then(function (els) { if (els.value.length) { return els; } @@ -1038,7 +1023,7 @@ function findClickable(client, locator) { `.//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][./@name = ${literal}]`, `.//button[./@name = ${literal}]` ]); - return client.elements(wideLocator).then(function(els) { + return client.elements(wideLocator).then(function (els) { if (els.value.length) { return els; } @@ -1048,7 +1033,7 @@ function findClickable(client, locator) { } function findFields(client, locator) { - if (typeof(locator) === 'object') return client.elements(withStrictLocator(locator)); + if (typeof (locator) === 'object') return client.elements(withStrictLocator(locator)); if (isCSSorXPathLocator(locator)) return client.elements(locator); let literal = xpathLocator.literal(locator); @@ -1067,7 +1052,7 @@ function findFields(client, locator) { } function proceedSeeField(assertType, field, value) { - return findFields(this.browser, field).then(function(res) { + return findFields(this.browser, field).then(function (res) { if (!res.value || res.value.length === 0) { throw new Error(`Field ${field} not found by name|text|CSS|XPath`); } @@ -1081,9 +1066,7 @@ function proceedSeeField(assertType, field, value) { if (el.value === false) return; commands.push(this.elementIdAttribute(el.ELEMENT, 'value')); }); - this.unify(commands, { - extractValue: true - }).then((val) => { + this.unify(commands, { extractValue: true }).then((val) => { return stringIncludes('fields by ' + field)[assertType](value, val); }); }); @@ -1114,22 +1097,20 @@ function proceedSeeField(assertType, field, value) { } function proceedSeeCheckbox(assertType, field) { - return findFields(this.browser, field).then(function(res) { + return findFields(this.browser, field).then(function (res) { if (!res.value || res.value.length === 0) { throw new Error(`Field ${field} not found by name|text|CSS|XPath`); } let commands = []; res.value.forEach((el) => commands.push(this.elementIdSelected(el.ELEMENT))); - return this.unify(commands, { - extractValue: true - }).then((selected) => { + return this.unify(commands, { extractValue: true }).then((selected) => { return truth(`checkable field ${field}`, 'to be checked')[assertType](selected); }); }); } function findCheckable(client, locator) { - if (typeof(locator) === 'object') return client.elements(withStrictLocator(locator)); + if (typeof (locator) === 'object') return client.elements(withStrictLocator(locator)); if (isCSSorXPathLocator(locator)) return client.elements(locator); let literal = xpathLocator.literal(locator); @@ -1137,10 +1118,10 @@ function findCheckable(client, locator) { `.//input[@type = 'checkbox' or @type = 'radio'][(@id = //label[contains(normalize-space(string(.)), ${literal})]/@for) or @placeholder = ${literal}]`, `.//label[contains(normalize-space(string(.)), ${literal})]//input[@type = 'radio' or @type = 'checkbox']` ]); - return client.elements(byText).then(function(els) { + return client.elements(byText).then(function (els) { if (els.value.length) return els; let byName = `.//input[@type = 'checkbox' or @type = 'radio'][@name = ${literal}]`; - return client.elements(byName).then(function(els) { + return client.elements(byName).then(function (els) { if (els.value.length) return els; return client.elements(locator); // by css or xpath }); @@ -1159,21 +1140,18 @@ function isCSSorXPathLocator(locator) { function withStrictLocator(locator) { if (!locator) return null; - if (typeof(locator) !== 'object') return locator; + if (typeof (locator) !== 'object') return locator; let key = Object.keys(locator)[0]; let value = locator[key]; locator.toString = () => `{${key}: '${value}'}`; switch (key) { - case 'by': - case 'xpath': - case 'css': - return value; - case 'id': - return '#' + value; - case 'name': - return `[name="${value}"]`; + case 'by': + case 'xpath': + case 'css': return value; + case 'id': return '#' + value; + case 'name': return `[name="${value}"]`; } } From d63bd3e070e60e696cfc07386d31206272285c7c Mon Sep 17 00:00:00 2001 From: Andrey Pshenkin Date: Wed, 21 Sep 2016 19:29:51 +0300 Subject: [PATCH 07/10] remove formatting --- lib/helper/WebDriverIO.js | 1 - lib/interfaces/bdd.js | 1 - 2 files changed, 2 deletions(-) diff --git a/lib/helper/WebDriverIO.js b/lib/helper/WebDriverIO.js index 820576615..39d8a4028 100644 --- a/lib/helper/WebDriverIO.js +++ b/lib/helper/WebDriverIO.js @@ -12,7 +12,6 @@ const assert = require('assert'); const path = require('path'); const requireg = require('requireg'); - let withinStore = {}; /** diff --git a/lib/interfaces/bdd.js b/lib/interfaces/bdd.js index 22ad105d8..8d5acad66 100644 --- a/lib/interfaces/bdd.js +++ b/lib/interfaces/bdd.js @@ -35,7 +35,6 @@ module.exports = function(suite) { event.dispatcher.emit(event.suite.after, suite); recorder.add(() => done()); }); - suite.on('pre-require', function(context, file, mocha) { var common = require('mocha/lib/interfaces/common')(suites, context); From bfb7e336df4ef30a15a9c35da761e24040dbe571 Mon Sep 17 00:00:00 2001 From: Andrey Pshenkin Date: Wed, 21 Sep 2016 19:32:57 +0300 Subject: [PATCH 08/10] remove Formatting --- lib/interfaces/bdd.js | 21 +++++++++++---------- lib/scenario.js | 16 ++++++++-------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/interfaces/bdd.js b/lib/interfaces/bdd.js index 8d5acad66..544337e9d 100644 --- a/lib/interfaces/bdd.js +++ b/lib/interfaces/bdd.js @@ -21,7 +21,7 @@ var escapeRe = require('escape-string-regexp'); * * @param {Suite} suite Root suite. */ -module.exports = function(suite) { +module.exports = function (suite) { var suites = [suite]; suite.timeout(0); @@ -35,7 +35,7 @@ module.exports = function(suite) { event.dispatcher.emit(event.suite.after, suite); recorder.add(() => done()); }); - suite.on('pre-require', function(context, file, mocha) { + suite.on('pre-require', function (context, file, mocha) { var common = require('mocha/lib/interfaces/common')(suites, context); // create dispatcher @@ -50,7 +50,7 @@ module.exports = function(suite) { * and/or tests. */ - context.Feature = function(title) { + context.Feature = function (title) { if (suites.length > 1) { suites.shift(); } @@ -67,19 +67,19 @@ module.exports = function(suite) { return suite; }; - context.BeforeSuite = function(fn) { + context.BeforeSuite = function (fn) { suites[0].beforeAll('BeforeSuite', scenario.injected(fn)); }; - context.AfterSuite = function(fn) { + context.AfterSuite = function (fn) { suites[0].afterAll('AfterSuite', scenario.injected(fn)); }; - context.Background = context.Before = function(fn) { + context.Background = context.Before = function (fn) { suites[0].beforeEach('Before', scenario.injected(fn)); }; - context.After = function(fn) { + context.After = function (fn) { suites[0].afterEach('After', scenario.injected(fn)); }; @@ -88,12 +88,13 @@ module.exports = function(suite) { * with the given `title` and callback `fn` * acting as a thunk. */ - context.Scenario = function(title, fn) { + context.Scenario = function (title, fn) { var suite = suites[0]; if (suite.pending) { fn = null; } var test = new Test(title, fn); + test.fullTitle = () => `${suite.title}: ${title}`; test.file = file; test.async = true; test.timeout(0); @@ -104,7 +105,7 @@ module.exports = function(suite) { /** * Exclusive test-case. */ - context.Scenario.only = function(title, fn) { + context.Scenario.only = function (title, fn) { var test = context.Scenario(title, fn); var reString = '^' + escapeRe(test.fullTitle()) + '$'; mocha.grep(new RegExp(reString)); @@ -113,7 +114,7 @@ module.exports = function(suite) { /** * Pending test case. */ - context.xScenario = context.Scenario.skip = function(title) { + context.xScenario = context.Scenario.skip = function (title) { context.Scenario(title); }; }); diff --git a/lib/scenario.js b/lib/scenario.js index 97c2d7430..14d36564d 100644 --- a/lib/scenario.js +++ b/lib/scenario.js @@ -16,8 +16,8 @@ module.exports.test = (test) => { } test.steps = []; - test.fn = function(done) { - recorder.errHandler(function(err) { + test.fn = function (done) { + recorder.errHandler(function (err) { recorder.session.start('teardown'); event.emit(event.test.failed, test, err); recorder.add(() => done(err)); @@ -34,7 +34,7 @@ module.exports.test = (test) => { return test; } recorder.catch(); // catching possible errors in promises - let resumeTest = function() { + let resumeTest = function () { recorder.add('create new promises queue for generator', function(data) { recorder.session.start('generator'); // creating a new promise chain try { @@ -67,7 +67,7 @@ module.exports.test = (test) => { /** * Injects arguments to function from controller */ -module.exports.injected = function(fn) { +module.exports.injected = function (fn) { return function() { try { fn.apply(this, getInjectedArguments(fn)); @@ -81,21 +81,21 @@ module.exports.injected = function(fn) { /** * Starts promise chain, so helpers could enqueue their hooks */ -module.exports.setup = function() { +module.exports.setup = function () { recorder.start(); event.emit(event.test.before); }; -module.exports.teardown = function() { +module.exports.teardown = function () { event.emit(event.test.after); }; -module.exports.suiteSetup = function() { +module.exports.suiteSetup = function () { recorder.start(); event.emit(event.suite.before); }; -module.exports.suiteTeardown = function() { +module.exports.suiteTeardown = function () { event.emit(event.suite.after); }; From d9d6f42876a9edffe2c0b7cbcbeb3617423b382c Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 22 Sep 2016 13:27:02 +0300 Subject: [PATCH 09/10] Fix AfterSuite Hook --- lib/scenario.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/scenario.js b/lib/scenario.js index 14d36564d..a99489327 100644 --- a/lib/scenario.js +++ b/lib/scenario.js @@ -35,7 +35,7 @@ module.exports.test = (test) => { } recorder.catch(); // catching possible errors in promises let resumeTest = function () { - recorder.add('create new promises queue for generator', function(data) { + recorder.add('create new promises queue for generator',function (data) { recorder.session.start('generator'); // creating a new promise chain try { let resume = res.next(data); @@ -96,6 +96,7 @@ module.exports.suiteSetup = function () { }; module.exports.suiteTeardown = function () { + recorder.start(); event.emit(event.suite.after); }; From 875e55bd04db60542eb637e10e8d7fa758511a9b Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 22 Sep 2016 13:28:26 +0300 Subject: [PATCH 10/10] Fix formatting --- lib/interfaces/bdd.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/interfaces/bdd.js b/lib/interfaces/bdd.js index 544337e9d..dc65e5382 100644 --- a/lib/interfaces/bdd.js +++ b/lib/interfaces/bdd.js @@ -35,6 +35,7 @@ module.exports = function (suite) { event.dispatcher.emit(event.suite.after, suite); recorder.add(() => done()); }); + suite.on('pre-require', function (context, file, mocha) { var common = require('mocha/lib/interfaces/common')(suites, context);