import { z } from "./z"; const { I } = inject(); /** * Wait Class */ class Wait { /** * Waits for an element to be removed or become invisible on the page * * ```js * Wait.waitUntilInvisibilityOfElement("//input[@id='login']",20); * ``` * * @param {String} locator locator located by xpath|CSS * @param {String} timeoutSecs in secs * */ static async waitUntilInvisibilityOfElement(locator: string, timeoutSecs?: number) { if (timeoutSecs != undefined) { console.log(`Timeout Passed To Paramater is:`, timeoutSecs); } await z.waitForInvisible(locator); } /** * Waits for an element to become visible on the page * * ```js * Wait.waitUntilVisibilityOfElement("//input[@id='login']",20); * ``` * * @param {String} locator located by xpath|CSS * @param {String} timeoutSecs in secs * */ static async waitUntilVisibilityOfElement(locator: string | CodeceptJS.Locator, timeoutSecs?: number) { try { if (timeoutSecs != undefined) { console.log(`Timeout Passed To Paramater is:`, timeoutSecs); } await z.waitForVisible(locator as string); } catch (error) { throw error; } } /** * Pauses for an execution for a number of secs * * ```js * Wait.waitForDefaultTimeout(20); * ``` * * @param {String} timeoutSecs in secs * */ static async waitForDefaultTimeout(timeoutSecs: number) { z.wait(timeoutSecs); } /** * Waits for an element to be clickable * * ```js * Wait.waitForElementClickable("//input[@id='login']",20); * ``` * * @param {String} locator located by xpath|CSS * @param {String} timeoutSecs in secs * */ static async waitForElementClickable(locator: string, timeoutSecs?: number) { if (timeoutSecs != undefined) { console.log(`Timeout Passed To Paramater is:`, timeoutSecs); } z.waitForClickable(locator); } /** * Waits for a text to appear * * ```js * Wait.waitForVisibilityOfText("Apple",20); * ``` * * @param {String} text * @param {String} timeoutSecs in secs * */ static async waitForVisibilityOfText(text: string, timeoutSecs?: number) { if (timeoutSecs != undefined) { console.log(`Timeout Passed To Paramater is:`, timeoutSecs); } z.waitForText(text); } /** * Waits for a specified value of attribute * * ```js * Wait.waitForVisibilityOfValue("//input[@id='name']","John",20); * ``` * @param {string} locator * @param {String} value "value" * @param {String} timeoutSecs in secs * */ static async waitForVisibilityOfValue(locator: string, value: string, timeoutSecs?: number) { if (timeoutSecs != undefined) { console.log(`Timeout Passed To Paramater is:`, timeoutSecs); } z.waitForValue(locator, value); } /** * Waits for an element to become enabled * * ```js * Wait.waitForElementToBeEnabled("//input[@id='login']",20); * ``` * * @param {String} locator specified by CSS | Xpath * @param {String} timeoutSecs in secs * */ static async waitForElementToBeEnabled(locator: string, timeoutSecs?: number) { if (timeoutSecs != undefined) { console.log(`Timeout Passed To Paramater is:`, timeoutSecs); } z.waitForEnabled(locator); } /** * Waits for an URL to match the expected * * ```js * Wait.waitForURLPresent("eInvoice#\auth\login",20); * ``` * * @param {String} URLPart * @param {String} timeoutSecs in secs * */ static async waitForURLPresent(URLPart: string, timeoutSecs?: number) { if (timeoutSecs != undefined) { console.log(`Timeout Passed To Paramater is:`, timeoutSecs); } I.waitInUrl(URLPart); } /** * Waits for an element * * ```js * await Wait.waitForElement("//input[@id='login']"",20); * ``` * * @param {String} locator specified by CSS | Xpath * @param {String} timeoutSecs in secs * */ static async waitForElement(locator: string, timeoutSecs?: number) { if (timeoutSecs != undefined) { console.log(`Timeout Passed To Paramater is:`, timeoutSecs); } z.waitForElement(locator); } /** * Waits for an element to not attached to DOM * * ```js * Wait.waitForElementToDetach("//input[@id='login']"",20); * ``` * * @param {String} locator specified by CSS | Xpath * @param {String} timeoutSecs in secs * */ static async waitForElementToDetach(locator: string, timeoutSecs?: number) { if (timeoutSecs != undefined) { console.log(`Timeout Passed To Paramater is:`, timeoutSecs); } z.waitForDetached(locator); } /** * Waits for a specified number of elements * * ```js * Wait.waitForNumberOfElementsToBeVisible("//input",10,20); * ``` * * @param {String} locator specified by CSS | Xpath * @param {number} numberOfElements of elements * @param {String} timeoutSecs in secs * */ static async waitForNumberOfElementsToBeVisible(locator: string, numberOfElements: number, timeoutSecs?: number) { if (timeoutSecs != undefined) { console.log(`Timeout Passed To Paramater is:`, timeoutSecs); } I.waitNumberOfVisibleElements(locator, numberOfElements); } /** * Waits for an element to hide * * ```js * Wait.waitForElementToHide(locator,20); * ``` * * @param {function} locator specified as CSS | Xpath * @param {String} timeoutSecs in secs * */ static async waitForElementToHide(locator: string, timeoutSecs?: number) { if (timeoutSecs != undefined) { console.log(`Timeout Passed To Paramater is:`, timeoutSecs); } I.waitToHide(locator); } } export default new Wait(); const _Wait = Wait; export { _Wait as Wait }; // for inheritance