idea-at
Version:
Automated Testing suite for IDEA projects
111 lines (110 loc) • 5.55 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.failIfErrorMessage = exports.expectSuccessMessage = exports.checkLoadingSpinner = exports.clickOnIonAlertButtonByText = exports.clickOnIonSelectByText = exports.selectItemInListByText = exports.getItemCountInIonList = exports.getIonSearchbarInput = exports.getIonButtonByIcon = exports.getIonInputByTestId = void 0;
const test_1 = require("@playwright/test");
/**
* Gets an ion-input element by its test ID
* @param page - The Playwright Page object
* @param testId - The test ID value to search for
* @param testIdAttribute - The attribute name used for test IDs (defaults to 'testId')
* @returns Locator for the input element inside the ion-input
*/
const getIonInputByTestId = (page, testId, testIdAttribute = 'testId') => page.locator(`ion-input[${testIdAttribute}="${testId}"] input`);
exports.getIonInputByTestId = getIonInputByTestId;
/**
* Gets an ion-button element that contains an ion-icon with the specified icon name
* @param page - The Playwright Page object
* @param icon - The icon name to search for (matches either icon or name attribute)
* @returns Locator for the ion-button element containing the specified icon
*/
const getIonButtonByIcon = (page, icon) => page.locator(`ion-button:has(ion-icon[icon="${icon}"], ion-icon[name="${icon}"])`);
exports.getIonButtonByIcon = getIonButtonByIcon;
/**
* Gets the input element within an ion-searchbar component
* @param page - The Playwright Page object
* @returns Locator for the input element inside the ion-searchbar
*/
const getIonSearchbarInput = (page) => page.locator(`ion-searchbar input`);
exports.getIonSearchbarInput = getIonSearchbarInput;
/**
* Gets the count of ion-item elements within an ion-list
* @param page - The Playwright Page object
* @param timeout - Maximum time in ms to wait for items to appear (defaults to 10000)
* @returns Promise that resolves to the number of ion-items found
*/
const getItemCountInIonList = async (page, timeout = 10000) => {
await page.waitForSelector('ion-list ion-item', { timeout });
return await page.$$eval('ion-list ion-item', items => items.length);
};
exports.getItemCountInIonList = getItemCountInIonList;
/**
* Selects an ion-item element in an ion-list by matching its text content
* @param page - The Playwright Page object
* @param text - The text content to search for within the ion-item
* @param timeout - Maximum time in ms to wait for items to appear (defaults to 10000)
* @returns Promise that resolves when the item is clicked
*/
const selectItemInListByText = async (page, text, timeout = 10000) => {
await page.waitForSelector('ion-list ion-item', { timeout });
await page.click(`ion-list ion-item >> text=${text}`);
};
exports.selectItemInListByText = selectItemInListByText;
/**
* Clicks on an ion-select element and selects an option by its text content
* @param page - The Playwright Page object
* @param input - Locator for the ion-select element to click
* @param text - The text content of the option to select
* @returns Promise that resolves when the option is selected
*/
const clickOnIonSelectByText = async (page, input, text) => {
await input.click();
await page.waitForSelector('ion-select-popover', { state: 'visible' });
await page.click(`ion-select-popover ion-item >> text=${text}`);
};
exports.clickOnIonSelectByText = clickOnIonSelectByText;
/**
* Clicks on a button within an ion-alert dialog by matching its text content
* @param page - The Playwright Page object
* @param text - The text content of the button to click
* @returns Promise that resolves when the button is clicked
*/
const clickOnIonAlertButtonByText = async (page, text) => {
const alertButton = page.locator('.alert-button-group').locator(`text=${text}`);
await (0, test_1.expect)(alertButton).toBeVisible();
await alertButton.click();
};
exports.clickOnIonAlertButtonByText = clickOnIonAlertButtonByText;
/**
* Checks for the presence and subsequent hiding of a loading spinner element
* @param page - The Playwright Page object
* @param timeout - Maximum time in ms to wait for spinner to hide (defaults to 29000)
* @returns Promise that resolves when spinner is hidden
*/
const checkLoadingSpinner = async (page, timeout = 29000) => {
const loadingSpinner = page.locator('.loading-spinner');
await (0, test_1.expect)(loadingSpinner).toBeVisible();
await (0, test_1.expect)(loadingSpinner).toBeHidden({ timeout });
};
exports.checkLoadingSpinner = checkLoadingSpinner;
/**
* Checks for the presence of a success toast message on the page
* @param page - The Playwright Page object
* @returns Promise that resolves when success toast is visible
*/
const expectSuccessMessage = async (page) => {
const successToast = page.locator(`ion-toast[color="success"]`);
await (0, test_1.expect)(successToast).toBeVisible();
};
exports.expectSuccessMessage = expectSuccessMessage;
/**
* Checks that no error toast message is visible on the page
* @param page - The Playwright Page object
* @param timeout - Maximum time in ms to wait for error toast (defaults to 1000);
* must be small, to avoid the message to disappear normally
* @returns Promise that resolves if no error toast is found
*/
const failIfErrorMessage = async (page, timeout = 1000) => {
const errorToast = page.locator(`ion-toast[color="danger"]`);
await (0, test_1.expect)(errorToast).toBeHidden({ timeout });
};
exports.failIfErrorMessage = failIfErrorMessage;
;