37
test/selectors/actionHelper.ts
Normal file
37
test/selectors/actionHelper.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { $, $$ } from '@wdio/globals';
|
||||
import { dictionary } from './index.js';
|
||||
|
||||
type SelectorNode = string | Record<string, unknown>;
|
||||
|
||||
export function getSelector(route: string): string {
|
||||
const value = route.split('.').reduce<unknown>((current, segment) => {
|
||||
if (!current || typeof current !== 'object') return undefined;
|
||||
return (current as Record<string, unknown>)[segment];
|
||||
}, dictionary);
|
||||
|
||||
if (typeof value !== 'string' || value.trim() === '') {
|
||||
throw new Error(`Selector route "${route}" does not resolve to a selector string.`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
export async function getElement(route: string, shouldBeVisible = true): Promise<ReturnType<typeof $>> {
|
||||
const element = $(getSelector(route));
|
||||
if (shouldBeVisible) {
|
||||
await element.waitForExist({ timeout: 60_000 });
|
||||
await element.waitForDisplayed({ timeout: 60_000 });
|
||||
} else {
|
||||
await element.waitForDisplayed({ timeout: 60_000, reverse: true });
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
export async function getElements(route: string): Promise<ReturnType<typeof $$>> {
|
||||
const selector = getSelector(route);
|
||||
const firstElement = $(selector);
|
||||
await firstElement.waitForExist({ timeout: 60_000 });
|
||||
await firstElement.waitForDisplayed({ timeout: 60_000 });
|
||||
return $$(selector);
|
||||
}
|
||||
|
||||
export type { SelectorNode };
|
||||
7
test/selectors/index.ts
Normal file
7
test/selectors/index.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import loginSelectors from './page-objects/login.js';
|
||||
import secureSelectors from './page-objects/secure.js';
|
||||
|
||||
export const dictionary = {
|
||||
...loginSelectors,
|
||||
...secureSelectors,
|
||||
};
|
||||
9
test/selectors/page-objects/login.ts
Normal file
9
test/selectors/page-objects/login.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
const loginSelectors = {
|
||||
loginPage: {
|
||||
inputUsername: '#username',
|
||||
inputPassword: '#password',
|
||||
submitButton: 'button[type="submit"]',
|
||||
},
|
||||
};
|
||||
|
||||
export default loginSelectors;
|
||||
7
test/selectors/page-objects/secure.ts
Normal file
7
test/selectors/page-objects/secure.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
const secureSelectors = {
|
||||
securePage: {
|
||||
flashAlert: '#flash',
|
||||
},
|
||||
};
|
||||
|
||||
export default secureSelectors;
|
||||
Reference in New Issue
Block a user