async _preInit() { await this.driver.switchTo().defaultContent(); await this.driver.wait( until.ableToSwitchToFrame( this.editoriFrameSelector ), this.explicitWaitMS, 'Could not locate the editor iFrame.' ); await this.driver.sleep( 2000 ); }
/** * {{> doubleClick }} */ async doubleClick(locator, context = null) { const el = await findClickable.call(this, locator, context); assertElementExists(el, locator, 'Clickable'); return this.browser.evaluate(el => window.codeceptjs.doubleClickEl(el), el) .wait(this.options.waitForAction); }
it('should open new tab', () => I.amOnPage('/info') .then(() => I.openNewTab()) .then(() => I.wait(1)) .then(() => I.seeInCurrentUrl('about:blank')) .then(() => I.grabNumberOfOpenTabs()) .then(numPages => assert.equal(numPages, 2)));
/** * {{> waitForElement }} */ async waitForElement(locator, sec) { this.browser.options.waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout; locator = new Locator(locator, 'css'); return this.browser.wait((by, locator) => window.codeceptjs.findElement(by, locator) !== null, locator.type, locator.value).catch((err) => { if (err.message && err.message.indexOf('.wait() timed out after') > -1) { throw new Error(`element (${JSON.stringify(locator)}) still not present on page after ${sec} sec`); } else throw err; }); }
checkerBrowser.sleep(sleepTime).wait(expectParams[0], { timeout: 1000, noerror: true }).then(function(elements){ return elements.length; })
/** * {{> type }} */ async type(keys, delay = null) { if (!Array.isArray(keys)) { keys = keys.split(''); } for (const key of keys) { await this.page.keyboard.press(key); if (delay) await this.wait(delay / 1000); } }
constructor (options) { super() if (typeof options === 'string' || Array.isArray(options)) { options = { cmd: options } } this.cmd = options.cmd this.cwd = path.resolve(options.cwd || '.') this.wait = options.wait || 1e3 this.port = null this[kProcess] = null }
static async switchToIFrame( driver ) { const iFrameSelector = By.css( '.web-preview__frame' ); const webPreview = By.css( '.web-preview__inner.is-visible.is-loaded' ); await driver.switchTo().defaultContent(); await driverHelper.waitTillPresentAndDisplayed( driver, webPreview ); return await driver.wait( until.ableToSwitchToFrame( iFrameSelector ), this.explicitWaitMS, 'Could not switch to web preview iFrame' ); }
it('should assert when there is no ability to switch to next tab', () => I.amOnPage('/') .then(() => I.click('More info')) .then(() => I.wait(1)) // Wait is required because the url is change by previous statement (maybe related to #914) .then(() => I.switchToNextTab(2)) .then(() => I.wait(2)) .then(() => assert.equal(true, false, 'Throw an error if it gets this far (which it should not)!')) .catch((e) => { assert.equal(e.message, 'There is no ability to switch to next tab with offset 2'); }));
it('should switch to next tab', () => I.amOnPage('/info') .then(() => I.wait(1)) .then(() => I.grabNumberOfOpenTabs()) .then(numPages => assert.equal(numPages, 1)) .then(() => I.click('New tab')) .then(() => I.switchToNextTab()) .then(() => I.wait(2)) .then(() => I.seeCurrentUrlEquals('/login')) .then(() => I.grabNumberOfOpenTabs()) .then(numPages => assert.equal(numPages, 2)));
/** * {{> rightClick }} */ async rightClick(locator, context = null) { const el = await findClickable.call(this, locator, context); assertElementExists(el, locator, 'Clickable'); return this.browser.evaluate(el => window.codeceptjs.rightClickEl(el), el) .wait(this.options.waitForAction); }
/** * {{> checkOption }} */ async checkOption(field, context = null) { const els = await findCheckable.call(this, field, context); assertElementExists(els[0], field, 'Checkbox or radio'); return this.browser.evaluate(els => window.codeceptjs.checkEl(els[0]), els) .wait(this.options.waitForAction); }