diff --git a/src/helper/web/webHelper.ts b/src/helper/web/webHelper.ts index 527f446..7b13046 100644 --- a/src/helper/web/webHelper.ts +++ b/src/helper/web/webHelper.ts @@ -84,24 +84,56 @@ export class WebHelper { //TBD } + /** + * The function asserts that the current page URL matches the expected URL. + * @param {string} url - The `url` parameter is a string that represents the expected URL of a web + * page. + */ async assertPageURL(url: string): Promise { - console.log("Assertion for Page URL"); + console.log(`Asserts that page url is ${url}.`); await expect(this.webPage).toHaveURL(url); } + /** + * The function asserts that the page title matches the expected title. + * @param {string} title - The title parameter is a string that represents the expected title of the + * web page. + */ async assertPageTitle(title: string): Promise { - console.log("Assertion for Page Title"); + console.log(`Asserts that page title is ${title}.`); await expect(this.webPage).toHaveTitle(title); } + /** + * The function opens a new tab in a browser context, navigates to a specified URL, and returns the + * page object representing the new tab. + * @param {string} url - A string representing the URL of the webpage that you want to open in a new + * tab. + * @returns a Promise that resolves to a Page object. + */ async openNewTab(url: string): Promise { const pageOne = await this.browserContext.newPage(); await pageOne.goto(url); return pageOne; } + + /** + * The function takes a screenshot of a web page and saves it as an image file. + * @param {string} imageName - The imageName parameter is a string that specifies the name of the + * screenshot image file. If no value is provided, it defaults to "screenshot.png". + */ async takeScreenshot(imageName: string = `screenshot.png`): Promise { await this.webPage.screenshot({ path: `${imageName}`, fullPage: true }); } + /** + * The function takes a locator and an optional image name as parameters, finds the element on a web + * page using the locator, and takes a screenshot of the element. + * @param {string} locator - The `locator` parameter is a string that represents the element you want + * to take a screenshot of. It can be a CSS selector, an XPath expression, or any other valid locator + * strategy supported by the `this.webPage.locator` method. + * @param {string} imageName - The `imageName` parameter is a string that specifies the name of the + * screenshot image file. If no value is provided, it defaults to "screenshot.png". + */ async takeScreenshotOfElement( locator: string, imageName: string = `screenshot.png` @@ -109,4 +141,69 @@ export class WebHelper { const el = await this.webPage.locator(locator); await el.screenshot({ path: `${imageName}` }); } + + /** + * The function checks if an element on a web page contains the expected text. + * @param {string} target - A string representing the target element to locate on the web page. + * @param {string} expectedText - The expected text that you want the element to contain. + */ + async elementContainText( + target: string, + expectedText: string + ): Promise { + console.log( + `Asserts that element ${target} contains text ${expectedText}.` + ); + const el = await this.webPage.locator(target); + await expect(el).toContainText(expectedText); + } + + /** + * The function checks if an element on a web page has the expected text. + * @param {string} target - The target parameter is a string that represents the locator for the + * element you want to check for text. It could be a CSS selector, an XPath expression, or any other + * valid locator strategy supported by the testing framework you are using. + * @param {string} expectedText - The expected text that the element should have. + */ + async elementHasText(target: string, expectedText: string): Promise { + console.log( + `Asserts that element ${target} has expected text ${expectedText}.` + ); + const el = await this.webPage.locator(target); + await expect(el).toHaveText(expectedText); + } + + /** + * The function asserts that a specified element is visible on a web page. + * @param {string} target - The `target` parameter is a string that represents the locator of the + * element you want to check for visibility. It could be a CSS selector, an XPath expression, or any + * other valid locator that can be used to identify the element on the web page. + */ + async elementIsVisible(target: string): Promise { + console.log(`Asserts that element ${target} is visible.`); + expect(await this.webPage.locator(target)).toBeVisible(); + } + + /** + * The function asserts that a specified element is not visible on a web page. + * @param {string} target - The target parameter is a string that represents the locator or selector + * for the element that you want to check for visibility. It can be a CSS selector, an XPath + * expression, or any other valid locator that can be used to identify the element on the web page. + */ + async elementIsNotVisible(target: string): Promise { + console.log(`Asserts that element ${target} is not visible.`); + expect(await this.webPage.locator(target)).toBeHidden(); + } + + async elementHasAttributeAndValue( + target: string, + attribute: string, + attributeVal: string + ): Promise { + console.log( + `Asserts that '${target}' has a specific attribute '${attribute}' with the expected value '${attributeVal}'.` + ); + //expect(await (target).toHaveAttribute(attribute, attributeVal)); + + } }