UNPKG

derby-webdriverio

Version:
165 lines (163 loc) 6.06 kB
// Generated by CoffeeScript 1.12.7 (function() { module.exports = function(browser) { var makeWaitForPageLoad, modelMethod; browser.addCommand('shouldExist', function() { return this.waitForExist.apply(this, arguments).should.eventually.be["true"]; }); browser.addCommand('shouldNotExist', function(selector) { return this.waitForExist(selector, void 0, true).should.eventually.be["true"]; }); browser.addCommand('shouldBeVisible', function() { return this.waitForVisible.apply(this, arguments).should.eventually.be["true"]; }); browser.addCommand('shouldNotBeVisible', function(selector) { return this.waitForVisible(selector, void 0, true).should.eventually.be["true"]; }); browser.addCommand('shouldExecute', function() { return this.execute.apply(this, arguments).then(function(ret) { return ret.value; }).should.eventually.be["true"]; }); browser.addCommand('historyPush', function(url) { return this.execute(function(url) { var _push; delete window._rendered; _push = function(url) { if (app.history != null) { return app.history.push(url); } else { return history.pushState({}, '', url); } }; return _push(url); }, url).waitUntil(function() { return this.execute(function() { return window._rendered; }).then(function(ret) { return ret.value; }); }); }); browser.addCommand('historyRefresh', function() { return this.execute(function() { var _refresh; delete window._rendered; _refresh = function() { if (app.history != null) { return app.history.refresh(); } else { return history.pushState({}, '', location.pathname + location.search); } }; return _refresh(); }).waitUntil(function() { return this.execute(function() { return window._rendered; }).then(function(ret) { return ret.value; }); }); }); makeWaitForPageLoad = function(fnName) { return function() { var args, isReact; args = arguments; isReact = null; return this.execute(function() { if (window.IS_REACT) { return true; } delete window._rendered; return false; }).then(function(ret) { return isReact = ret.value; }).then(function() { return this[fnName].apply(this, args); }).then(function() { return this.waitUntil(function() { if (isReact) { return this.pause(5000).then(function() { return true; }); } return this.execute(function() { return window._rendered; }).then(function(ret) { return ret.value; }); }); }); }; }; browser.addCommand('urlAndWait', function() { var isReact; isReact = null; return this.url.apply(this, arguments).execute(function() { return window.IS_REACT; }).then(function(ret) { return isReact = ret.value; }).then(function() { return this.waitUntil(function() { if (isReact) { return this.pause(5000).then(function() { return true; }); } return this.execute(function() { return window._rendered; }).then(function(ret) { return ret.value; }); }); }); }); browser.addCommand('clickAndWait', makeWaitForPageLoad('click')); browser.addCommand('elementIdClickAndWait', makeWaitForPageLoad('elementIdClick')); browser.addCommand('submitFormAndWait', makeWaitForPageLoad('submitForm')); browser.addCommand('selectByVisibleTextAndWait', makeWaitForPageLoad('selectByVisibleText')); browser.addCommand('selectByValueAndWait', makeWaitForPageLoad('selectByValue')); browser.addCommand('selectByIndexAndWait', makeWaitForPageLoad('selectByIndex')); browser.addCommand('selectByAttributeAndWait', makeWaitForPageLoad('selectByAttribute')); modelMethod = function(method, isAsync) { return function() { return this[isAsync ? 'executeAsync' : 'execute'].apply(this, [ function(method, isAsync) { var args, done, lastArgIndex, res; done = void 0; lastArgIndex = arguments.length; if (isAsync) { done = arguments[arguments.length - 1]; lastArgIndex = arguments.length - 1; } args = Array.prototype.slice.call(arguments, 2, lastArgIndex); return res = (app.model || model)[method].apply(app.model || model, args.concat([ function() { return typeof done === "function" ? done(res) : void 0; } ])); }, method, !!isAsync ].concat(Array.prototype.slice.call(arguments))).then(function(ret) { return ret.value; }); }; }; ['get', 'getCopy', 'getDeepCopy'].forEach(function(method) { return browser.addCommand('model' + method.charAt(0).toUpperCase() + method.slice(1), modelMethod(method)); }); ['set', 'del', 'setNull', 'setDiff', 'setDiffDeep', 'add', 'increment', 'push', 'unshift', 'insert', 'pop', 'shift', 'remove', 'move', 'stringInsert', 'stringRemove'].forEach(function(method) { return browser.addCommand('model' + method.charAt(0).toUpperCase() + method.slice(1), modelMethod(method, true)); }); return browser.addCommand('waitForModel', function() { return this.executeAsync(function(cb) { var _pingId; _pingId = '__ping_' + (app.model || model).id(); return (app.model || model).add('service', { id: _pingId }, cb); }).then(function(ret) { return ret.value; }); }); }; }).call(this);