Skip to content

Commit

Permalink
TW-815: [e2e] Add contact positive. Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-tsx committed Jul 20, 2023
1 parent 07cce10 commit bfb058d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
7 changes: 6 additions & 1 deletion e2e/src/page-objects/pages/address-book.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export class AddressBookPage extends Page {
}

isContactAdded(hash: string) {
return findElement(AddressBookSelectors.contactItem, { hash }, VERY_SHORT_TIMEOUT);
return findElement(
AddressBookSelectors.contactItem,
{ hash },
VERY_SHORT_TIMEOUT,
`The contact with address: '${hash}' not found`
);
}
}
22 changes: 16 additions & 6 deletions e2e/src/utils/search.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,24 @@ const buildTestIDSelector = (testID: string) => `[data-testid="${testID}"]`;

type OtherSelectors = Record<string, string>;

export const findElement = async (testID: string, otherSelectors?: OtherSelectors, timeout = MEDIUM_TIMEOUT) => {
export const findElement = async (
testID: string,
otherSelectors?: OtherSelectors,
timeout = MEDIUM_TIMEOUT,
errorTitle?: string
) => {
const selector = buildSelector(testID, otherSelectors);

return await findElementBySelectors(selector, timeout);
return await findElementBySelectors(selector, timeout, errorTitle);
};

export const findElementBySelectors = async (selectors: string, timeout = MEDIUM_TIMEOUT) => {
const element = await BrowserContext.page.waitForSelector(selectors, { visible: true, timeout });
export const findElementBySelectors = async (selectors: string, timeout = MEDIUM_TIMEOUT, errorTitle?: string) => {
const element = await BrowserContext.page.waitForSelector(selectors, { visible: true, timeout }).catch(error => {
if (errorTitle && error instanceof Error) {
error.message = `${errorTitle}\n` + error.message;
}
throw error;
});

if (isDefined(element)) {
return element;
Expand All @@ -40,11 +50,11 @@ export const findElements = async (testID: string) => {
class PageElement {
constructor(public testID: string, public otherSelectors?: OtherSelectors, public notSelectors?: OtherSelectors) {}

findElement(timeout?: number) {
findElement(timeout?: number, errorTitle?: string) {
let selectors = buildSelector(this.testID, this.otherSelectors);
if (this.notSelectors) selectors += buildNotSelector(this.notSelectors);

return findElementBySelectors(selectors, timeout);
return findElementBySelectors(selectors, timeout, errorTitle);
}
waitForDisplayed(timeout?: number) {
return this.findElement(timeout);
Expand Down

0 comments on commit bfb058d

Please sign in to comment.