Skip to content

Commit

Permalink
[ftr] wrap all elements so we can swap out leadfoot without disturbin…
Browse files Browse the repository at this point in the history
…g tests
  • Loading branch information
spalger committed Nov 29, 2018
1 parent e31203e commit 230ec88
Show file tree
Hide file tree
Showing 5 changed files with 443 additions and 35 deletions.
13 changes: 7 additions & 6 deletions test/functional/page_objects/visual_builder_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function VisualBuilderPageProvider({ getService, getPageObjects }) {
const find = getService('find');
const retry = getService('retry');
const log = getService('log');
const browser = getService('browser');
const testSubjects = getService('testSubjects');
const comboBox = getService('comboBox');
const PageObjects = getPageObjects(['common', 'header', 'visualize']);
Expand Down Expand Up @@ -64,12 +65,12 @@ export function VisualBuilderPageProvider({ getService, getPageObjects }) {
// a textarea we must really select all text and remove it, and cannot use
// clearValue().
if (process.platform === 'darwin') {
await input.session.pressKeys([Keys.COMMAND, 'a']); // Select all Mac
await browser.pressKeys([Keys.COMMAND, 'a']); // Select all Mac
} else {
await input.session.pressKeys([Keys.CONTROL, 'a']); // Select all for everything else
await browser.pressKeys([Keys.CONTROL, 'a']); // Select all for everything else
}
await input.session.pressKeys(Keys.NULL); // Release modifier keys
await input.session.pressKeys(Keys.BACKSPACE); // Delete all content
await browser.pressKeys(Keys.NULL); // Release modifier keys
await browser.pressKeys(Keys.BACKSPACE); // Delete all content
await input.type(markdown);
await PageObjects.header.waitUntilLoadingHasFinished();
}
Expand Down Expand Up @@ -104,7 +105,7 @@ export function VisualBuilderPageProvider({ getService, getPageObjects }) {

async getRhythmChartLegendValue() {
const metricValue = await find.byCssSelector('.tvbLegend__itemValue');
await metricValue.session.moveMouseTo(metricValue);
await metricValue.moveMouseTo();
return await metricValue.getVisibleText();
}

Expand Down Expand Up @@ -207,7 +208,7 @@ export function VisualBuilderPageProvider({ getService, getPageObjects }) {
const el = await testSubjects.find('comboBoxSearchInput');
await el.clearValue();
await el.type(timeField);
await el.session.pressKeys(Keys.RETURN);
await browser.pressKeys(Keys.RETURN);
await PageObjects.header.waitUntilLoadingHasFinished();
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/functional/page_objects/visualize_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -492,14 +492,14 @@ export function VisualizePageProvider({ getService, getPageObjects }) {

const advancedLinkState = await advancedLink.getAttribute('class');
if (advancedLinkState.includes('fa-caret-right')) {
await advancedLink.session.moveMouseTo(advancedLink);
await advancedLink.moveMouseTo();
log.debug('click advancedLink');
await advancedLink.click();
}
const checkbox = await find.byCssSelector('input[ng-model="axis.scale.setYExtents"]');
const checkboxState = await checkbox.getAttribute('class');
if (checkboxState.includes('ng-empty')) {
await checkbox.session.moveMouseTo(checkbox);
await checkbox.moveMouseTo();
await checkbox.click();
}
const maxField = await find.byCssSelector('[ng-model="axis.scale.max"]');
Expand Down
8 changes: 6 additions & 2 deletions test/functional/services/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,12 @@ export function BrowserProvider({ getService }) {
* @param {number} yOffset Optional
* @return {Promise<void>}
*/
async moveMouseTo(...args) {
await remote.moveMouseTo(...args);
async moveMouseTo(element, xOffset, yOffset) {
if (element) {
await element.moveMouseTo();
} else {
await remote.moveMouseTo(null, xOffset, yOffset);
}
}

/**
Expand Down
74 changes: 49 additions & 25 deletions test/functional/services/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* under the License.
*/

import { ElementWrapper } from './lib/element_wrapper';

// Many of our tests use the `exists` functions to determine where the user is. For
// example, you'll see a lot of code like:
// if (!testSubjects.exists('someElementOnPageA')) {
Expand All @@ -40,6 +42,14 @@ export function FindProvider({ getService }) {

const defaultFindTimeout = config.get('timeouts.find');

const wrap = leadfootElement => (
new ElementWrapper(leadfootElement, remote)
);

const wrapAll = leadfootElements => (
leadfootElements.map(wrap)
);

class Find {
async _withTimeout(timeout, block) {
try {
Expand Down Expand Up @@ -76,26 +86,26 @@ export function FindProvider({ getService }) {
async byName(selector, timeout = defaultFindTimeout) {
log.debug(`find.byName(${selector})`);
return await this._ensureElementWithTimeout(timeout, async remote => {
return await remote.findByName(selector);
return wrap(await remote.findByName(selector));
});
}

async byCssSelector(selector, timeout = defaultFindTimeout) {
log.debug(`findByCssSelector ${selector}`);
return await this._ensureElementWithTimeout(timeout, async remote => {
return await remote.findByCssSelector(selector);
return wrap(await remote.findByCssSelector(selector));
});
}

async byClassName(selector, timeout = defaultFindTimeout) {
log.debug(`findByCssSelector ${selector}`);
return await this._ensureElementWithTimeout(timeout, async remote => {
return await remote.findByClassName(selector);
return wrap(await remote.findByClassName(selector));
});
}

async activeElement() {
return await remote.getActiveElement();
return wrap(await remote.getActiveElement());
}

async setValue(selector, text) {
Expand Down Expand Up @@ -126,57 +136,70 @@ export function FindProvider({ getService }) {

async allByLinkText(selector, timeout = defaultFindTimeout) {
log.debug('find.allByLinkText: ' + selector);
return await this.allByCustom(remote => remote.findAllByLinkText(selector), timeout);
return await this.allByCustom(
async remote => wrapAll(await remote.findAllByLinkText(selector)),
timeout
);
}

async allByCssSelector(selector, timeout = defaultFindTimeout) {
log.debug('in findAllByCssSelector: ' + selector);
return await this.allByCustom(remote => remote.findAllByCssSelector(selector), timeout);
return await this.allByCustom(
async remote => wrapAll(await remote.findAllByCssSelector(selector)),
timeout
);
}

async descendantExistsByCssSelector(selector, parentElement, timeout = WAIT_FOR_EXISTS_TIME) {
log.debug('Find.descendantExistsByCssSelector: ' + selector);
return await this.exists(async () => await parentElement.findDisplayedByCssSelector(selector), timeout);
return await this.exists(
async () => wrap(await parentElement.findDisplayedByCssSelector(selector)),
timeout
);
}

async descendantDisplayedByCssSelector(selector, parentElement) {
log.debug('Find.descendantDisplayedByCssSelector: ' + selector);
return await this._ensureElement(async () => await parentElement.findDisplayedByCssSelector(selector));
return await this._ensureElement(
async () => wrap(await parentElement.findDisplayedByCssSelector(selector))
);
}

async allDescendantDisplayedByCssSelector(selector, parentElement) {
log.debug(`Find.allDescendantDisplayedByCssSelector(${selector})`);
const allElements = await parentElement.findAllByCssSelector(selector);
return await Promise.all(
allElements.map((element) => this._ensureElement(async () => element))
allElements.map((element) => (
this._ensureElement(async () => wrap(element))
))
);
}

async displayedByCssSelector(selector, timeout = defaultFindTimeout, parentElement) {
async displayedByCssSelector(selector, timeout = defaultFindTimeout) {
log.debug('in displayedByCssSelector: ' + selector);
return await this._ensureElementWithTimeout(timeout, async remote => {
return await remote.findDisplayedByCssSelector(selector);
}, parentElement);
return wrap(await remote.findDisplayedByCssSelector(selector));
});
}

async byLinkText(selector, timeout = defaultFindTimeout) {
log.debug('Find.byLinkText: ' + selector);
return await this._ensureElementWithTimeout(timeout, async remote => {
return await remote.findByLinkText(selector);
return wrap(await remote.findByLinkText(selector));
});
}

async findDisplayedByLinkText(selector, timeout = defaultFindTimeout) {
log.debug('Find.byLinkText: ' + selector);
return await this._ensureElementWithTimeout(timeout, async remote => {
return await remote.findDisplayedByLinkText(selector);
return wrap(await remote.findDisplayedByLinkText(selector));
});
}

async byPartialLinkText(partialLinkText, timeout = defaultFindTimeout) {
log.debug(`find.byPartialLinkText(${partialLinkText})`);
return await this._ensureElementWithTimeout(timeout, async remote => {
return await remote.findByPartialLinkText(partialLinkText);
return wrap(await remote.findByPartialLinkText(partialLinkText));
});
}

Expand All @@ -193,26 +216,27 @@ export function FindProvider({ getService }) {

async existsByLinkText(linkText, timeout = WAIT_FOR_EXISTS_TIME) {
log.debug(`existsByLinkText ${linkText}`);
return await this.exists(async remote => await remote.findDisplayedByLinkText(linkText), timeout);
return await this.exists(async remote => wrap(await remote.findDisplayedByLinkText(linkText)), timeout);
}

async existsByDisplayedByCssSelector(selector, timeout = WAIT_FOR_EXISTS_TIME) {
log.debug(`existsByDisplayedByCssSelector ${selector}`);
return await this.exists(async remote => await remote.findDisplayedByCssSelector(selector), timeout);
return await this.exists(async remote => wrap(await remote.findDisplayedByCssSelector(selector)), timeout);
}

async existsByCssSelector(selector, timeout = WAIT_FOR_EXISTS_TIME) {
log.debug(`existsByCssSelector ${selector}`);
return await this.exists(async remote => await remote.findByCssSelector(selector), timeout);
return await this.exists(async remote => wrap(await remote.findByCssSelector(selector)), timeout);
}

async clickByCssSelectorWhenNotDisabled(selector, { timeout } = { timeout: defaultFindTimeout }) {
log.debug(`Find.clickByCssSelectorWhenNotDisabled`);

// Don't wrap this code in a retry, or stale element checks may get caught here and the element
// will never be re-grabbed. Let errors bubble, but continue checking for disabled property until
// it's gone.
const element = await this.byCssSelector(selector, timeout);
await remote.moveMouseTo(element);
await element.moveMouseTo();

const clickIfNotDisabled = async (element, resolve) => {
const disabled = await element.getProperty('disabled');
Expand All @@ -232,7 +256,7 @@ export function FindProvider({ getService }) {
log.debug(`clickByPartialLinkText(${linkText})`);
await retry.try(async () => {
const element = await this.byPartialLinkText(linkText, timeout);
await remote.moveMouseTo(element);
await element.moveMouseTo();
await element.click();
});
}
Expand All @@ -241,7 +265,7 @@ export function FindProvider({ getService }) {
log.debug(`clickByLinkText(${linkText})`);
await retry.try(async () => {
const element = await this.byLinkText(linkText, timeout);
await remote.moveMouseTo(element);
await element.moveMouseTo();
await element.click();
});
}
Expand All @@ -257,7 +281,7 @@ export function FindProvider({ getService }) {
if (index === -1) {
throw new Error('Button not found');
}
return allButtons[index];
return wrap(allButtons[index]);
});
}

Expand All @@ -273,22 +297,22 @@ export function FindProvider({ getService }) {
log.debug(`clickByCssSelector(${selector})`);
await retry.try(async () => {
const element = await this.byCssSelector(selector, timeout);
await remote.moveMouseTo(element);
await element.moveMouseTo();
await element.click();
});
}
async clickByDisplayedLinkText(linkText, timeout = defaultFindTimeout) {
log.debug(`clickByDisplayedLinkText(${linkText})`);
await retry.try(async () => {
const element = await this.findDisplayedByLinkText(linkText, timeout);
await remote.moveMouseTo(element);
await element.moveMouseTo();
await element.click();
});
}
async clickDisplayedByCssSelector(selector, timeout = defaultFindTimeout) {
await retry.try(async () => {
const element = await this.findDisplayedByCssSelector(selector, timeout);
await remote.moveMouseTo(element);
await element.moveMouseTo();
await element.click();
});
}
Expand Down
Loading

0 comments on commit 230ec88

Please sign in to comment.