Skip to content

Commit

Permalink
[services/testSubjects] reduce retry usage, add waitForEnabled (elast…
Browse files Browse the repository at this point in the history
…ic#66538)

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
dmlemeshko and elasticmachine committed May 18, 2020
1 parent 8aa49d0 commit 75917f0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 34 deletions.
3 changes: 1 addition & 2 deletions test/functional/page_objects/home_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ export function HomePageProvider({ getService, getPageObjects }: FtrProviderCont

async removeSampleDataSet(id: string) {
// looks like overkill but we're hitting flaky cases where we click but it doesn't remove
await testSubjects.isDisplayed(`removeSampleDataSet${id}`);
await testSubjects.isEnabled(`removeSampleDataSet${id}`);
await testSubjects.waitForEnabled(`removeSampleDataSet${id}`);
await testSubjects.click(`removeSampleDataSet${id}`);
await this._waitForSampleDataLoadingAction(id);
}
Expand Down
59 changes: 27 additions & 32 deletions test/functional/services/common/test_subjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,10 @@ export function TestSubjectsProvider({ getService }: FtrProviderContext) {
}

public async append(selector: string, text: string): Promise<void> {
return await retry.try(async () => {
log.debug(`TestSubjects.append(${selector}, ${text})`);
const input = await this.find(selector);
await input.click();
await input.type(text);
});
log.debug(`TestSubjects.append(${selector}, ${text})`);
const input = await this.find(selector);
await input.click();
await input.type(text);
}

public async clickWhenNotDisabled(
Expand All @@ -119,12 +117,10 @@ export function TestSubjectsProvider({ getService }: FtrProviderContext) {
}

public async doubleClick(selector: string, timeout: number = FIND_TIME): Promise<void> {
return await retry.try(async () => {
log.debug(`TestSubjects.doubleClick(${selector})`);
const element = await this.find(selector, timeout);
await element.moveMouseTo();
await element.doubleClick();
});
log.debug(`TestSubjects.doubleClick(${selector})`);
const element = await this.find(selector, timeout);
await element.moveMouseTo();
await element.doubleClick();
}

async descendantExists(selector: string, parentElement: WebElementWrapper): Promise<boolean> {
Expand Down Expand Up @@ -206,27 +202,21 @@ export function TestSubjectsProvider({ getService }: FtrProviderContext) {
}

public async isEnabled(selector: string): Promise<boolean> {
return await retry.try(async () => {
log.debug(`TestSubjects.isEnabled(${selector})`);
const element = await this.find(selector);
return await element.isEnabled();
});
log.debug(`TestSubjects.isEnabled(${selector})`);
const element = await this.find(selector);
return await element.isEnabled();
}

public async isDisplayed(selector: string): Promise<boolean> {
return await retry.try(async () => {
log.debug(`TestSubjects.isDisplayed(${selector})`);
const element = await this.find(selector);
return await element.isDisplayed();
});
log.debug(`TestSubjects.isDisplayed(${selector})`);
const element = await this.find(selector);
return await element.isDisplayed();
}

public async isSelected(selector: string): Promise<boolean> {
return await retry.try(async () => {
log.debug(`TestSubjects.isSelected(${selector})`);
const element = await this.find(selector);
return await element.isSelected();
});
log.debug(`TestSubjects.isSelected(${selector})`);
const element = await this.find(selector);
return await element.isSelected();
}

public async isSelectedAll(selectorAll: string): Promise<boolean[]> {
Expand All @@ -237,11 +227,9 @@ export function TestSubjectsProvider({ getService }: FtrProviderContext) {
}

public async getVisibleText(selector: string): Promise<string> {
return await retry.try(async () => {
log.debug(`TestSubjects.getVisibleText(${selector})`);
const element = await this.find(selector);
return await element.getVisibleText();
});
log.debug(`TestSubjects.getVisibleText(${selector})`);
const element = await this.find(selector);
return await element.getVisibleText();
}

async getVisibleTextAll(selectorAll: string): Promise<string[]> {
Expand Down Expand Up @@ -294,6 +282,13 @@ export function TestSubjectsProvider({ getService }: FtrProviderContext) {
await find.waitForElementHidden(element, timeout);
}

public async waitForEnabled(selector: string, timeout: number = TRY_TIME): Promise<void> {
await retry.tryForTime(timeout, async () => {
const element = await this.find(selector);
return (await element.isDisplayed()) && (await element.isEnabled());
});
}

public getCssSelector(selector: string): string {
return testSubjSelector(selector);
}
Expand Down

0 comments on commit 75917f0

Please sign in to comment.