diff --git a/README.md b/README.md index 4c690c339..3a9dae117 100644 --- a/README.md +++ b/README.md @@ -81,9 +81,7 @@ describeCommon('Test Example', () => { ```json { - "include": [ - "specs/**/*.ts" - ] + "include": ["specs/**/*.ts"] } ``` diff --git a/src/commons/BrowserUtils.ts b/src/commons/BrowserUtils.ts index bb94b4b03..829d3032f 100644 --- a/src/commons/BrowserUtils.ts +++ b/src/commons/BrowserUtils.ts @@ -1,20 +1,27 @@ +import allureReporter from '@wdio/allure-reporter'; +import { Cookie } from '@wdio/protocols/build/types'; import admZip, { IZipEntry } from 'adm-zip'; import axios, { AxiosResponse } from 'axios'; import { assert } from 'chai'; +import * as fs from 'fs'; import { EOL } from 'os'; +import path from 'path'; +import { inspect } from 'util'; +import { Result, WdioCheckElementMethodOptions } from 'wdio-image-comparison-service'; +import { + ClickOptions, + DragAndDropCoordinate, + MoveToOptions, + ParsedCSSValue, + WaitForOptions, + WaitUntilOptions, +} from 'webdriverio'; +import { Location } from 'webdriverio/build/commands/element/getLocation'; +import { Size } from 'webdriverio/build/commands/element/getSize'; import { SpecialKeys } from '..'; import { MouseButton } from '../enums/MouseButton'; import { SelectorType } from '../enums/SelectorType'; import { Reporter } from './Reporter'; -import { inspect } from 'util'; -import { DragAndDropCoordinate, ParsedCSSValue, WaitForOptions } from 'webdriverio'; -import { Size } from 'webdriverio/build/commands/element/getSize'; -import { Location } from 'webdriverio/build/commands/element/getLocation'; -import { Cookie } from '@wdio/protocols/build/types'; -import * as fs from 'fs'; -import path from 'path'; -import allureReporter from '@wdio/allure-reporter'; -import { Result, WdioCheckElementMethodOptions } from 'wdio-image-comparison-service'; const DEFAULT_TIME_OUT: number = process.env.DEFAULT_TIME_OUT === undefined ? 60000 : Number(process.env.DEFAULT_TIME_OUT); @@ -53,9 +60,9 @@ export namespace BrowserUtils { /** * Inject a snippet of JavaScript into the page * for execution in the context of the currently selected frame - * @param script - js script to execute + * @param script - js script to execute in string format */ - export function executeScript(script: string): string { + export function execute(script: string): string { Reporter.debug(`Executing script: '${script}'`); return tryBlock(() => browser.execute(script), `Failed to execute script: ${script}`); } @@ -69,18 +76,10 @@ export namespace BrowserUtils { tryBlock(() => { const scrollToJS: string = `document.evaluate("${selector}", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.scrollIntoView()`; - executeScript(scrollToJS); + execute(scrollToJS); }, `Failed to scroll to element: [${selector}]`); } - /** - * Get system data tests executed on - * Usefully to add in Reporter before each test - */ - export function getSystemData(): string { - return String(browser.execute(() => navigator.appVersion)); - } - /** * Add a value to an element located by selector * @param selector element selector @@ -121,23 +120,31 @@ export namespace BrowserUtils { */ export function setHiddenElementValue(selector: string, value: string | number): void { Reporter.debug(`Set hidden element '${selector} with value: '${value}'`); - isExist(selector); + waitForExist(selector); tryBlock(() => $(selector).setValue(value), `Failed to set value: '${value}' to '${selector}'`); } /** - * Click an element located by selector + * Click on an element. + * + * Note: This issues a WebDriver click command for the selected element, which generally scrolls to and then clicks the selected element. + * However, if you have fixed-position elements (such as a fixed header or footer) that cover up the selected element after it is scrolled within the viewport, + * the click will be issued at the given coordinates, but will be received by your fixed (overlaying) element. In these cased the following error is thrown: + * Element is not clickable at point (x, x). Other element would receive the click: ..." + * To work around this, try to find the overlaying element and remove it via execute command so it doesn't interfere the click. + * You also can try to scroll to the element yourself using scroll with an offset appropriate for your scenario. * * Validate element is visible before clicking on it * @param selector element selector + * @param options { button, x, y } are optional. button can be one of [0, "left", 1, "middle", 2, "right"] */ - export function click(selector: string): void { + export function click(selector: string, options?: ClickOptions): void { Reporter.debug(`Click an element '${selector}'`); waitForEnabled(selector); waitForClickable(selector); tryBlock( - () => $(selector).click(), + () => $(selector).click(options), `Failed to click on '${selector}'` ); @@ -161,7 +168,7 @@ export namespace BrowserUtils { * to insure the navigation actually happened * @param url url for navigation */ - export function navigateToUrl(url: string): void { + export function url(url: string): void { Reporter.debug(`Navigate to '${url}'`); tryBlock(() => browser.url(url), `Failed to navigate to '${url}'`); } @@ -169,7 +176,7 @@ export namespace BrowserUtils { /** * Refresh browser's page */ - export function refreshBrowser(): void { + export function refresh(): void { Reporter.debug('Refresh browser page'); tryBlock( () => browser.refresh(), @@ -181,7 +188,7 @@ export namespace BrowserUtils { /** * Click browser's back button */ - export function backBrowser(): void { + export function back(): void { Reporter.debug('Click browser back button'); tryBlock(() => browser.back(), 'Failed to click browser back button'); } @@ -191,7 +198,7 @@ export namespace BrowserUtils { * Mainly useful for navigation validation * @param url expected current url */ - export function expectCurrentUrl(url: string): void { + export function waitForUrl(url: string): void { const expectedUrl: string = normalizeUrl(url); Reporter.debug(`Wait for URL to be , '${expectedUrl}'`); browser.waitUntil( @@ -223,30 +230,33 @@ export namespace BrowserUtils { /** * Wait Until - Will Return true in case condition met within the timeout or false if condition isn't met or not met within the timeout - * @param action - any condition as a function - * @param actionTimeout - specified time out if undefined Default time out is used - * @param errMessage - Custom message for time out + * @param condition condition to wait on + * @param options WaitForOptions options (optional) { timeout, timeoutMsg, interval } */ // eslint-disable-next-line @typescript-eslint/no-explicit-any - export function waitUntil(action: () => any, errMessage?: string, actionTimeout: number = DEFAULT_TIME_OUT): any { - return browser.waitUntil(() => action(), { timeout: actionTimeout, timeoutMsg: errMessage }); + export function waitUntil(condition: () => any, options?: WaitUntilOptions): any { + return browser.waitUntil(() => condition(), { ...{ timeout: DEFAULT_TIME_OUT }, ...options }); } /** - * Select a value in element - * Mostly used for drop down item selection from drop down list + * Select option with a specific value * @param selector elements selector - * @param value value to select + * @param attribute attribute of option element to get selected + * @param value value of option element to get selected */ - export function selectByValue(selector: string, value: string): void { - Reporter.debug(`Select by text '${value}' + export function selectByAttribute(selector: string, attribute: string, value: string | number): void { + Reporter.debug(`Select by value '${value}' of attribute '${attribute}' from '${selector}'`); - isExist(selector); + waitForExist(selector); - tryBlock(() => $(selector).selectByAttribute('value', value), `Failed to select ${value} from ${selector}`); + tryBlock( + () => $(selector).selectByAttribute(attribute, value), + `Failed to select value ${value} of attribute ${attribute} from ${selector}` + ); } /** + * Return true or false if the selected DOM-element is enabled * @param selector - element selector */ export function isEnabled(selector: string): boolean { @@ -258,15 +268,22 @@ export namespace BrowserUtils { /** * Wait for element to be enabled * @param selector element selector + * @param options WaitForOptions options (optional) { timeout, reverse, timeoutMsg, interval } */ - export function waitForEnabled(selector: string): void { + export function waitForEnabled(selector: string, options?: WaitForOptions): void { Reporter.debug(`Wait for an element to be enabled '${selector}'`); - waitForDisplayed(selector); - tryBlock(() => $(selector).waitForEnabled({ timeout: DEFAULT_TIME_OUT }), `Element not enabled '${selector}'`); + waitForDisplayed(selector, options); + /** + * If no options passed or options does not include timout, default timeout will be used + */ + tryBlock( + () => $(selector).waitForEnabled({ ...{ timeout: DEFAULT_TIME_OUT }, ...options }), + `Element not enabled '${selector}'` + ); } /** - * Indicate if Element is visible (without wait) + * Return true if the selected DOM-element is displayed * @param selector - element selector */ export function isDisplayed(selector: string): boolean { @@ -278,116 +295,76 @@ export namespace BrowserUtils { /** * Wait for an element to be visible by given selector * @param selector element selector + * @param options WaitForOptions options (optional) { timeout, reverse, timeoutMsg, interval } */ - export function waitForDisplayed(selector: string): void { + export function waitForDisplayed(selector: string, options?: WaitForOptions): void { Reporter.debug(`Wait for an element to be visible '${selector}'`); - isExist(selector); - tryBlock(() => $(selector).waitForDisplayed({ timeout: DEFAULT_TIME_OUT }), `Element not visible '${selector}'`); + if (options?.reverse) { + waitForExist(selector, options); + } + tryBlock( + () => $(selector).waitForDisplayed({ ...{ timeout: DEFAULT_TIME_OUT }, ...options }), + `Element not visible '${selector}'` + ); } /** * Wait for an element to be exist by given selector * @param selector element selector + * @param options WaitForOptions options (optional) { timeout, reverse, timeoutMsg, interval } */ - export function isExist(selector: string): void { + export function waitForExist(selector: string, options?: WaitForOptions): void { Reporter.debug(`Expect an element exist '${selector}'`); - - tryBlock(() => $(selector).waitForExist({ timeout: DEFAULT_TIME_OUT }), `Element not exist '${selector}'`); - } - - /** - * Wait for an element to be not visible by given selector - * - * @param selector element selector - */ - export function notVisible(selector: string): void { - Reporter.debug(`Validating element not visible '${selector}'`); - tryBlock(() => { - browser.waitUntil( - () => { - return !$(selector).isDisplayed(); - }, - { timeout: DEFAULT_TIME_OUT } - ); - }, `Failed to validate element not visible '${selector}'`); - } - - /** - * Wait until element not exist in dom - * @param notExistElementSelector element's selector - */ - export function notExist(notExistElementSelector: string): void { - Reporter.debug(`Validating element not exist '${notExistElementSelector}'`); - tryBlock( - () => - $(notExistElementSelector).waitForExist({ - timeout: DEFAULT_TIME_OUT, - reverse: true, - }), - `Failed to validate element not exist '${notExistElementSelector}'` + () => $(selector).waitForExist({ ...{ timeout: DEFAULT_TIME_OUT }, ...options }), + `Wait for exist '${selector}' with options ${JSON.stringify(options)} failed` ); } /** - * Switch to iframe by iframe selector - * Elements/widgets ( like dialogs, status bars and more) - * located inside an iframe has to be switch to it + * Change focus to another frame on the page. If the frame id is null, + * the server should switch to the page's default content. * * @param selector selector of frame to switch to */ export function switchToFrame(selector: string): void { Reporter.debug(`Validate iframe with selector ${selector} exist`); - isExist(selector); + waitForExist(selector); Reporter.debug(`Switching to an Iframe by selector '${selector}'`); tryBlock(() => browser.switchToFrame($(selector)), 'Failed to switch frame'); } /** - * Switch to other tab by id + * The Switch To Window command is used to select the current top-level browsing context for the current session, + * i.e. the one that will be used for processing commands. + * + * @param handle a string representing a window handle, should be one of the strings that was returned in a call to getWindowHandles */ - export function switchTab(handle: string): void { - Reporter.debug(`Switching tab by id: '${handle}'`); + export function switchToWindow(handle: string): void { + Reporter.debug(`Switching window by id: '${handle}'`); - tryBlock(() => browser.switchToWindow(handle), `Failed switch to tab by id: '${handle}'`); + tryBlock(() => browser.switchToWindow(handle), `Failed switch to window by id: '${handle}'`); } /** - * Over think method name - * Get ids of open tabs + * The Get Window Handles command returns a list of window handles for every open top-level browsing context. + * The order in which the window handles are returned is arbitrary. */ - export function getTabIds(): Array { + export function getWindowHandles(): Array { Reporter.debug('Get all ids of all open tabs'); - return tryBlock(() => browser.getWindowHandles(), 'Failed to get tab ids'); + return tryBlock(() => browser.getWindowHandles(), 'Failed to get window handles'); } /** - * Switch to parent frame - * Have to call it after switching to some iframe - * so the focus will be back on main page + * Change focus to the parent context. + * If the current context is the top level browsing context, the context remains unchanged. */ export function switchToParentFrame(): void { - Reporter.debug(`Switching to parent frame (${browser.capabilities['browserName']})`); - - switch (browser.capabilities['browserName']) { - case 'chrome': { - Reporter.debug('Case chrome'); - tryBlock(() => browser.switchToParentFrame(), 'Chrome: Failed to switch to parent frame'); - break; - } + Reporter.debug(`Switching to parent frame`); - case 'firefox': { - Reporter.debug('Case firefox'); - tryBlock(() => browser.switchToFrame(null), 'FireFox: Failed to switch to parent frame'); - break; - } - - default: { - throw new TypeError('Unable to execute due to unsupported Browser'); - } - } + tryBlock(() => browser.switchToParentFrame(), 'Failed to switch to parent frame'); } /** @@ -411,26 +388,14 @@ export namespace BrowserUtils { } /** - * Hover over an element by given selector - * - * Note: Uses moveToObject method that is currently deprecated - * @param selector selector of an element to hover - */ - export function hover(selector: string): void { - Reporter.debug(`Move to an element '${selector}'`); - waitForDisplayed(selector); - tryBlock(() => $(selector).moveTo(), `Failed to hover over '${selector}')`); - } - - /** - * Validate element text as expected + * Wait for text of an element * Actual texts EOL replaced with spaces, for better test readability, so you need to path one line string * Note: element should be visible, otherwise will return empty string(selenium requirement) * @param selector element selector with text * @param expectedText expected text */ - export function expectText(selector: string, expectedText: string): void { - Reporter.debug(`Validate element text is '${expectedText}' by selector '${selector}'`); + export function waitForText(selector: string, expectedText: string): void { + Reporter.debug(`Wait for text '${expectedText}' of element by selector '${selector}'`); waitForDisplayed(selector); const elementWithText: WebdriverIO.Element = $(selector); tryBlock( @@ -456,7 +421,9 @@ export namespace BrowserUtils { } /** - * Get text of an element by selector + * Get the text content from a DOM-element. + * Make sure the element you want to request the text from is interactable + * otherwise you will get an empty string as return value. * @param selector element's selector */ export function getText(selector: string): string { @@ -467,39 +434,39 @@ export namespace BrowserUtils { } /** - * Validate number of items found by selector as expected + * Wait for number of elements found by selector to equal expected number + * In case of expectedNumber is 0, validates no elements with given selector displayed * * @param selector selector of items to count - * @param expectedValue expected number of items - * @param selector - element locator + * @param expectedNumber expected number of items */ - export function expectNumberOfElements(selector: string, expectedValue: number): void { - Reporter.debug(`Expect Number Of Elements, '${expectedValue}' in '${selector}'`); - if (expectedValue === 0) { - notVisible(selector); + export function waitForNumberOfElements(selector: string, expectedNumber: number): void { + Reporter.debug(`Wait for number '${expectedNumber}' of elements by selector '${selector}'`); + if (expectedNumber === 0) { + waitForDisplayed(selector, { reverse: true }); } tryBlock( () => browser.waitUntil(() => { - return $$(selector).length === expectedValue; + return findElements(SelectorType.XPATH, selector).length === expectedNumber; }), - `Found number of elements by '${selector}' not equal '${expectedValue}'` + `Found number of elements by '${selector}' not equal '${expectedNumber}'` ); } /** - * Scroll to an element in list + * Scroll to an item in list * * Scroll in loop until the element is visible or fail on time out * Checks for size of list every iteration in case list is lazy loaded * @param selector selector of an element to scroll to * @param listSelector selector of list to scroll */ - export function scrollToElement(selector: string, listSelector: string): void { + export function scrollToItemInList(selector: string, listSelector: string): void { Reporter.debug(`Scroll in list '${listSelector}' until element '${selector}' is visible.`); - isExist(listSelector); // need to verify list is loaded + waitForExist(listSelector); // need to verify list is loaded if (isDisplayed(selector)) { return; } @@ -514,9 +481,9 @@ export namespace BrowserUtils { */ const xpath: string = `(${listSelector})[${last}]`; const scrollToJS: string = `document.evaluate("${xpath}", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.scrollIntoView()`; - executeScript(scrollToJS); + execute(scrollToJS); - last = findElements(SelectorType.XPATH, listSelector).length; + last = getNumberOfElements(listSelector); return $(selector).isDisplayed(); }), @@ -534,7 +501,7 @@ export namespace BrowserUtils { export function scrollTo(selector: string, x: number, y: number): void { waitForDisplayed(selector); const script: string = `(document.evaluate("${selector}", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue).scroll(${x}, ${y})`; - executeScript(script); + execute(script); } /** @@ -546,7 +513,7 @@ export namespace BrowserUtils { Reporter.debug(`Check iframe visibility is '${expectedVisibility}'`); switchToParentFrame(); // if iframe already focused, isExist will fail - isExist(iframeSelector); + waitForExist(iframeSelector); const cssDisplayProperty: string = 'display'; const iframeDisplayProperty: ParsedCSSValue = tryBlock( @@ -564,44 +531,24 @@ export namespace BrowserUtils { } /** - * Get element's attribute value + * Get an attribute from a DOM-element based on the attribute name. * @param selector element's selector to search for attribute - * @param attributeName attribute name to search for + * @param attributeName requested attribute name */ export function getAttribute(selector: string, attributeName: string): string { + waitForExist(selector); return tryBlock( - () => getAttributeAndVerify(selector, attributeName), + () => $(selector).getAttribute(attributeName), `Failed to get '${attributeName}' attribute from '${selector}'` ); } /** - * - * @param selector element's selector to search for attribute - * @param attributeName attribute name to search for - */ - function getAttributeAndVerify(selector: string, attributeName: string): string { - Reporter.debug(`Get Attribute '${attributeName}' in element '${selector}' And Verify not null.`); - isExist(selector); - - const stringResults: string = $$(selector).length === 1 ? $(selector).getAttribute(attributeName) : undefined; - - // Check for multiple results or no element found - if (stringResults === null || stringResults === undefined) { - assert.fail( - `Found multiple results matching requested attribute '${attributeName}' or no results for element: '${selector}'` - ); - } - - return stringResults; - } - - /** - * Check if value of given selector is as expected + * Wait for value of element to be as requested * @param selector element's selector to check the value * @param value expected value */ - export function expectValue(selector: string, value: string): void { + export function waitForValue(selector: string, value: string): void { Reporter.debug(`Validate element '${selector}' has value of '${value}'`); let currValue: string; @@ -617,13 +564,21 @@ export namespace BrowserUtils { } /** - * Check if attribute with given selector contain expected value + * Wait for attribute to contain requested value * @param selector element's selector to search for attribute * @param attributeName attribute name to search for * @param value value in attribute + * @param revert indicate either the requested value should or should not be contained */ - export function expectAttributeValue(selector: string, attributeName: string, value: string): void { - Reporter.debug(`Validate element '${selector}' has attribute '${attributeName}' which contains '${value}'`); + export function waitForAttributeValue( + selector: string, + attributeName: string, + value: string, + revert: boolean = false + ): void { + Reporter.debug( + `Validate element '${selector}' has ${revert ? 'not ' : ''}attribute '${attributeName}' that contains '${value}'` + ); let attributeValue: string; tryBlock( @@ -631,9 +586,9 @@ export namespace BrowserUtils { browser.waitUntil(() => { attributeValue = getAttribute(selector, attributeName); - return isContainWord(attributeValue, value); + return revert != isContainWord(attributeValue, value); }), - `Incorrect attribute '${attributeName}' value from '${selector}' ${EOL}Expected: value '${value}' not found` + `Incorrect attribute '${attributeName}' value from '${selector}'` ); } @@ -655,28 +610,6 @@ export namespace BrowserUtils { browser.pause(additionalWaitAfterLoad); } - /** - * Check if attribute with given selector NOT contain expected word - * @param selector element's selector to search for attribute - * @param attributeName attribute name to search for - * @param value value NOT in attribute - */ - export function expectNoAttributeValue(selector: string, attributeName: string, value: string): void { - let attributeValue: string; - Reporter.debug( - `Validate element '${selector}' doesn't have attribute '${attributeName}' which contains '${value}'` - ); - tryBlock( - () => - browser.waitUntil(() => { - attributeValue = getAttribute(selector, attributeName); - - return !isContainWord(attributeValue, value); - }), - `Incorrect attribute '${attributeName}' value from ${selector} ${EOL}. The Value '${value}'expected to not exist` - ); - } - /** * Check if word is a substring of given text * @param fullText string to search in @@ -695,7 +628,9 @@ export namespace BrowserUtils { } /** - * Get cssProperty value by it's name and element selector + * Get a css property from a DOM-element selected by given selector. + * The return value is formatted to be testable. + * Colors gets parsed via rgb2hex and all other properties get parsed via css-value. * @param selector element selector * @param cssPropertyName css property name */ @@ -709,47 +644,37 @@ export namespace BrowserUtils { } /** - * Set cookie - * Requires navigation to domain before setting cookie + * Sets one or more cookies for the current page. + * Make sure you are on the page that should receive the cookie. + * You can't set a cookie for an arbitrary page without being on that page. * * If no domain provided, will set cookie for current domain * Otherwise will first navigate to required domain(should be valid url), * set the cookie and navigate back to page it started from * @param cookie cookie to set - * @param domain domain to set cookie for */ - export function setCookie(cookie: Cookie, domain: string): void { - Reporter.debug(`Setting cookie: '${JSON.stringify(cookie)}'`); - - let currentUrl: string; - if (domain !== null) { - currentUrl = getUrl(); - navigateToUrl(domain); - } - + export function setCookies(cookie: Cookie | Array): void { + Reporter.debug(`Setting cookies: '${JSON.stringify(cookie)}'`); browser.setCookies(cookie); - - if (domain !== null) { - navigateToUrl(currentUrl); - } } /** - * Get cookie + * Retrieve a cookie visible to the current page * You can query a specific cookie by providing the cookie name or * retrieve all. */ export function getCookies(names?: Array | string): Array { Reporter.debug('Get cookies:'); - const cookie: Array = tryBlock(() => browser.getCookies(names), 'Failed to get cookie'); - Reporter.debug(JSON.stringify(cookie)); + const cookies: Array = tryBlock(() => browser.getCookies(names), 'Failed to get cookies'); + Reporter.debug(JSON.stringify(cookies)); - return cookie; + return cookies; } /** - * Delete cookie - * By providing a cookie name it just removes the single cookie or more when multiple names are passed. + * Delete cookies visible to the current page. + * By providing a cookie name it just removes the single cookie or more when multiple names are passed + * @param names names of cookies to be deleted (optional) */ export function deleteCookies(names?: Array | string): void { Reporter.debug('Delete cookies:'); @@ -758,7 +683,7 @@ export namespace BrowserUtils { } /** - * Get current Url + * The Get Current URL command returns the URL of the current top-level browsing context. */ export function getUrl(): string { const currentUrl: string = tryBlock(() => browser.getUrl(), 'Failed to get current url'); @@ -785,10 +710,10 @@ export namespace BrowserUtils { } /** - * Validate alert's text as expected - * @param expectedText expected alert's text + * Wait for alert's text to equal requested text + * @param expectedText requested alert's text */ - export function expectAlertText(expectedText: string): void { + export function waitForAlertText(expectedText: string): void { Reporter.debug(`Validate alert's text is '${expectedText}'`); tryBlock( @@ -805,10 +730,10 @@ export namespace BrowserUtils { } /** - * - * @param selector - element for get size + * Get the width and height for an DOM-element. + * @param selector requested element selector */ - export function getElementSize(selector: string): Size { + export function getSize(selector: string): Size { Reporter.debug(`Get Element: '${selector}' size`); waitForDisplayed(selector); @@ -816,84 +741,67 @@ export namespace BrowserUtils { } /** - * Change size of browser window + * Resizes browser window outer size according to provided width and height. * @param width - Width (px) * @param height - Height (px) */ export function setWindowSize(width: number, height: number): void { Reporter.debug(`Set window size to '${width}X${height}'`); - switch (browser.capabilities['browserName']) { - case 'chrome': { - tryBlock(() => browser.setWindowSize(width, height), 'Chrome: Failed to resize window'); - break; - } - - case 'firefox': { - tryBlock(() => browser.setWindowRect(0, 0, width, height), 'FireFox: Failed to resize window'); - break; - } - - default: { - throw new TypeError('Unable to execute due to unsupported Browser'); - } - } + tryBlock(() => browser.setWindowSize(width, height), 'Chrome: Failed to resize window'); } + /** + * Returns browser window size. + * output example `{ width: 1280, height: 767 }` + */ export function getWindowSize(): object { Reporter.debug('Get window size'); - if (browser.capabilities['browserName'] === 'chrome') { - return tryBlock(() => browser.getWindowSize(), 'Chrome: Failed to get window size'); - } - - if (browser.capabilities['browserName'] === 'firefox') { - return tryBlock(() => browser.getWindowRect(), 'FireFox: Failed to get window size'); - } - - throw new TypeError('Unable to execute due to unsupported Browser'); + return tryBlock(() => browser.getWindowSize(), 'Failed to get window size'); } /** - * - * @param mouseButton - {LEFT = 0, MIDDLE = 1 , RIGHT = 2} + * Click and hold the left mouse button (at the coordinates set by the last moveto command). + * Note that the next mouse-related command that should follow is buttonup. + * Any other mouse command (such as click or another call to buttondown) will yield undefined behaviour + * @param mouseButton - which button, enum: LEFT = 0, MIDDLE = 1 , RIGHT = 2, defaults to the left mouse button if not specified */ - export function pressMouseButton(mouseButton: MouseButton): void { - // Defaults to the left mouse button if not specified. - const selectedMouseButton: number = mouseButton === undefined ? MouseButton.LEFT : mouseButton; - Reporter.step(`Click mouse button '${selectedMouseButton}'`); - browser.buttonDown(selectedMouseButton); + export function buttonDown(mouseButton?: MouseButton): void { + Reporter.step(`Click mouse button down '${mouseButton ? MouseButton.LEFT : mouseButton}'`); + browser.buttonDown(mouseButton); } /** - * @param selector - element to move to, If not specified or is null, the offset is relative to current position of the mouse. - * @param xOffset - X (Pixels) offset to move to, relative to the top-left corner of the element If not specified, the mouse will move to the middle of the element. - * @param yOffset - Y (Pixels) offset to move to, relative to the top-left corner of the element. If not specified, the mouse will move to the middle of the element. + * Move the mouse by an offset of the specified element. + * If no element is specified, the move is relative to the current mouse cursor. + * If an element is provided but no offset, the mouse will be moved to the center of the element. + * If the element is not visible, it will be scrolled into view + * @param selector element to move to, If not specified or is null, the offset is relative to current position of the mouse. + * @param options moveTo command options. options example {xOffset: 5, yOffset: 6} */ - export function moveMouseCursorTo(selector: string, xOffset: number, yOffset: number): void { - Reporter.debug(`Move mouse cursor to element: '${selector}' with offset '${xOffset},${yOffset}'`); + export function moveTo(selector: string, options?: MoveToOptions): void { + Reporter.debug(`Move mouse cursor to element: '${selector}' with offset '${JSON.stringify(options)}'`); - isExist(selector); - $(selector).moveTo({ - xOffset, - yOffset, - }); + waitForExist(selector); + $(selector).moveTo(options); } /** - * @param mouseButton - {LEFT = 0, MIDDLE = 1 , RIGHT = 2} + * Releases the mouse button previously held (where the mouse is currently at). + * Must be called once for every buttondown command issued. + * See the note in click and buttondown about implications of out-of-order commands. + * @param mouseButton enum: LEFT = 0, MIDDLE = 1, RIGHT = 2, defaults to the left mouse button if not specified */ - export function releaseMouseButton(mouseButton: number): void { - // Defaults to the left mouse button if not specified. - const selectedMouseButton: number = mouseButton === undefined ? MouseButton.LEFT : mouseButton; - Reporter.step(`Release mouse button '${selectedMouseButton}'`); - browser.buttonUp(selectedMouseButton); + export function buttonUp(mouseButton: number): void { + Reporter.step(`Release mouse button '${mouseButton ? MouseButton.LEFT : mouseButton}'`); + browser.buttonUp(mouseButton); } /** * Determine an element’s location on the page. The point (0pix, 0pix) refers to the upper-left corner of the page. - * @param selector - element with requested position offset + * @param selector element with requested position offset */ - export function getElementLocation(selector: string): Location { - Reporter.debug(`Get Element location '${selector}'`); + export function getLocation(selector: string): Location { + Reporter.debug(`Get element's location '${selector}'`); return $(selector).getLocation(); } @@ -906,15 +814,17 @@ export namespace BrowserUtils { export function getNumberOfElements(selector: string): number { Reporter.debug(`Get number of elements by selector '${selector}'`); - return $$(selector).length; + return findElements(SelectorType.XPATH, selector).length; } /** - * Send a sequence of key strokes to the active element + * Send a sequence of key strokes to the active element. + * You can also use characters like "Left arrow" or "Back space". + * WebdriverIO will take care of translating them into unicode characters. * it can be single key or an array of keys * @param keysToSend key, array of keys or string array (chars) to send */ - export function sendKeys(keysToSend: SpecialKeys | Array | string | Array): void { + export function keys(keysToSend: SpecialKeys | Array | string | Array): void { Reporter.debug(`Sending Keys ${keysToSend}`); browser.keys(keysToSend); @@ -964,7 +874,7 @@ export namespace BrowserUtils { waitForDisplayed(selector); if (isTargetSelector) { - isExist(target as string); + waitForExist(target as string); } tryBlock( () => $(selector).dragAndDrop(isTargetSelector ? $(target as string) : (target as DragAndDropCoordinate)), @@ -1021,21 +931,6 @@ export namespace BrowserUtils { } } - /** - * Click an element located by selector - * - * Validate element is visible before clicking on it - * @param selector element selector - */ - export function rightClick(selector: string): void { - Reporter.debug(`Right click mouse button on the element '${selector}'`); - waitForEnabled(selector); - - waitForClickable(selector); - - tryBlock(() => $(selector).click({ button: 'right' }), `Failed to preform right click on '${selector}'`); - } - /** * Wait for element to be clickable * Will fail if the element not clickable after provided amount of time diff --git a/src/test/TestHelper.ts b/src/test/TestHelper.ts index f08915f3f..4465f24e1 100644 --- a/src/test/TestHelper.ts +++ b/src/test/TestHelper.ts @@ -16,7 +16,7 @@ export function describeCommon(name: string, body: () => any): void { * Navigate to sampleApp and wait for it to load */ beforeEach(() => { - BrowserUtils.navigateToUrl(sampleAppUrl); + BrowserUtils.url(sampleAppUrl); BrowserUtils.waitForDisplayed("//*[@id='top']"); }); diff --git a/src/test/sampleApp/index.html b/src/test/sampleApp/index.html index 776cdd937..55b85111d 100644 --- a/src/test/sampleApp/index.html +++ b/src/test/sampleApp/index.html @@ -338,7 +338,8 @@

Tests Sandbox

diff --git a/src/test/specs/AddValueSpec.ts b/src/test/specs/AddValueSpec.ts index 785eda4dc..7bb23e2b3 100644 --- a/src/test/specs/AddValueSpec.ts +++ b/src/test/specs/AddValueSpec.ts @@ -24,9 +24,8 @@ describeCommon('addValue', () => { .contains('still not enabled'); }); it('add value to not existing input', () => { - expect(() => BrowserUtils.addValue(`//input[@id='${TestUtils.randomString(5)}']`, TestUtils.randomString(5))) - .to.throw(Error) - .with.property('message') - .contains('Element not exist'); + expect(() => + BrowserUtils.addValue(`//input[@id='${TestUtils.randomString(5)}']`, TestUtils.randomString(5)) + ).to.throw(Error); }); }); diff --git a/src/test/specs/BackBrowserSpec.ts b/src/test/specs/BackBrowserSpec.ts index cedb9e2c0..bd9bc2bb8 100644 --- a/src/test/specs/BackBrowserSpec.ts +++ b/src/test/specs/BackBrowserSpec.ts @@ -4,10 +4,10 @@ import { describeCommon, sampleAppUrl } from '../TestHelper'; const navigationButton: string = "//button[@data-test='navigate-to-cloudinary']"; -describeCommon('BackBrowserSpec', () => { +describeCommon('BackSpec', () => { it('back browser', () => { $(navigationButton).click(); - BrowserUtils.backBrowser(); + BrowserUtils.back(); expect(browser.getUrl()).to.equal(sampleAppUrl); }); diff --git a/src/test/specs/ClickActionsSpec.ts b/src/test/specs/ClickActionsSpec.ts index 8f860262c..ef831fbd9 100644 --- a/src/test/specs/ClickActionsSpec.ts +++ b/src/test/specs/ClickActionsSpec.ts @@ -15,7 +15,7 @@ describeCommon('click', () => { }); it('doubleClick', () => { - BrowserUtils.navigateToUrl(sampleAppUrl); + BrowserUtils.url(sampleAppUrl); BrowserUtils.doubleClick(DOUBLE_CLICK_DIV); $(DOUBLE_CLICK_DIV).waitForDisplayed(); assert.equal($(DOUBLE_CLICK_DIV).getText(), 'Double click'); diff --git a/src/test/specs/DeleteCookiesSpec.ts b/src/test/specs/DeleteCookiesSpec.ts index b022a9c1c..1e72bed6c 100644 --- a/src/test/specs/DeleteCookiesSpec.ts +++ b/src/test/specs/DeleteCookiesSpec.ts @@ -5,13 +5,9 @@ import { describeCommon } from '../TestHelper'; /** * wdio-allure-ts deleteCookie tests */ -let cookie: WebDriver.Cookie; -const emptyCookie: WebDriver.Cookie = undefined; - describeCommon('DeleteCookieSpec', () => { beforeEach(() => { - cookie = { name: TestUtils.randomString(), value: TestUtils.randomString() }; - BrowserUtils.setCookie(cookie, null); + BrowserUtils.setCookies({ name: TestUtils.randomString(), value: TestUtils.randomString() }, null); }); it('expect empty cookie', () => { BrowserUtils.deleteCookies(); @@ -20,6 +16,6 @@ describeCommon('DeleteCookieSpec', () => { it('delete all cookie', () => { BrowserUtils.deleteCookies(); - assert.equal(BrowserUtils.getCookies()[0], emptyCookie, 'Cookie has not been removed'); + assert.equal(BrowserUtils.getCookies()[0], undefined, 'Cookie has not been removed'); }); }); diff --git a/src/test/specs/DoubleClickSpec.ts b/src/test/specs/DoubleClickSpec.ts index e4b69cf33..c227677e6 100644 --- a/src/test/specs/DoubleClickSpec.ts +++ b/src/test/specs/DoubleClickSpec.ts @@ -27,7 +27,7 @@ describeCommon('doubleClick', () => { .contains(`Element not visible '${hiddenElementSelector}'`); }); - it('double click disabled element', () => { + it.only('double click disabled element', () => { const disableElementSelector: string = "//button[@id='doubleClickDisabledButton']"; expect(() => BrowserUtils.doubleClick(disableElementSelector)) .to.throw(Error) diff --git a/src/test/specs/DragAndDropSpec.ts b/src/test/specs/DragAndDropSpec.ts index e5a2cad21..080caafb2 100644 --- a/src/test/specs/DragAndDropSpec.ts +++ b/src/test/specs/DragAndDropSpec.ts @@ -6,24 +6,21 @@ const ELEMENT: string = '#draggedSlider'; const TARGET: string = '#staticSlider'; const NOT_EXISTING_ELEMENT: string = '//*[@id="NotExistingElement_qweqwe"]'; -let beforeDragLocation: WebdriverIO.DragAndDropCoordinate; -let afterDragLocation: WebdriverIO.DragAndDropCoordinate; - /** * wdio-allure-ts drag and drop element */ describeCommon('dragAndDrop', () => { it('drag and drop to coordinate', () => { - beforeDragLocation = BrowserUtils.getElementLocation(ELEMENT); + const beforeDragLocation = BrowserUtils.getLocation(ELEMENT); BrowserUtils.dragAndDrop(ELEMENT, { x: 5, y: 0 }); - afterDragLocation = BrowserUtils.getElementLocation(ELEMENT); + const afterDragLocation = BrowserUtils.getLocation(ELEMENT); assert.isTrue(afterDragLocation.x > beforeDragLocation.x, 'Element position was not changed'); }); it('drag and drop to element', () => { const delta: number = 10; - beforeDragLocation = BrowserUtils.getElementLocation(TARGET); + const beforeDragLocation = BrowserUtils.getLocation(TARGET); BrowserUtils.dragAndDrop(ELEMENT, TARGET); - afterDragLocation = BrowserUtils.getElementLocation(ELEMENT); + const afterDragLocation = BrowserUtils.getLocation(ELEMENT); assert.isTrue( Math.abs(beforeDragLocation.x - afterDragLocation.x) < delta, 'Element was not dragged toward the target element' @@ -42,9 +39,6 @@ describeCommon('dragAndDrop', () => { .contains(`Failed to drag and drop ${ELEMENT} to`); }); it('drag and drop to non existing element', () => { - expect(() => BrowserUtils.dragAndDrop(ELEMENT, NOT_EXISTING_ELEMENT)) - .to.throw(Error) - .with.property('message') - .contains('Element not exist'); + expect(() => BrowserUtils.dragAndDrop(ELEMENT, NOT_EXISTING_ELEMENT)).to.throw(Error); }); }); diff --git a/src/test/specs/ExecuteScriptSpec.ts b/src/test/specs/ExecuteScriptSpec.ts index 25cedd222..a47ba7088 100644 --- a/src/test/specs/ExecuteScriptSpec.ts +++ b/src/test/specs/ExecuteScriptSpec.ts @@ -3,12 +3,12 @@ import { BrowserUtils } from '../..'; import { describeCommon } from '../TestHelper'; /** - * executeScript + * execute */ -describeCommon('executeScript', () => { +describeCommon('execute', () => { it('successful execution', () => { const script: string = " document.getElementById('executeScriptButtonId').click()"; - expect(() => BrowserUtils.executeScript(script)).to.not.throw(Error); + expect(() => BrowserUtils.execute(script)).to.not.throw(Error); const textDivSelector: string = "//*[@id='ExecuteScript']//*[@id='executeScriptDynamicText']"; expect($(textDivSelector).getText()).to.be.eqls('Cloudinary still rules!', 'script execution failed'); @@ -17,13 +17,13 @@ describeCommon('executeScript', () => { it('get string result', () => { const pageTitle = 'HTML Sandbox'; const script: string = 'return document.title'; - const currPageTitle = BrowserUtils.executeScript(script); + const currPageTitle = BrowserUtils.execute(script); expect(currPageTitle).to.be.eqls(pageTitle); }); it('failing execution', () => { const script: string = 'not a script'; - expect(() => BrowserUtils.executeScript(script)) + expect(() => BrowserUtils.execute(script)) .to.throw(Error) .with.property('message') .contains(`Failed to execute script: ${script}`); diff --git a/src/test/specs/ExpectAlertTextSpec.ts b/src/test/specs/ExpectAlertTextSpec.ts index a1b96dd61..7d3c0e375 100644 --- a/src/test/specs/ExpectAlertTextSpec.ts +++ b/src/test/specs/ExpectAlertTextSpec.ts @@ -5,24 +5,24 @@ import { describeCommon } from '../TestHelper'; const TEST_FIELD_SELECTOR: string = "//*[@id='ExpectAlertText']"; const TRIGGER_ALERT_BUTTON_SELECTOR: string = `${TEST_FIELD_SELECTOR}//button[@id='ExpectAlertTextTriggerAlert']`; -describeCommon('expectAlertText', () => { +describeCommon('waitForAlertText', () => { beforeEach(() => { browser.refresh(); }); it('correct text', () => { $(TRIGGER_ALERT_BUTTON_SELECTOR).click(); - expect(() => BrowserUtils.expectAlertText('Hello! I am an alert box!')).to.not.throw(); + expect(() => BrowserUtils.waitForAlertText('Hello! I am an alert box!')).to.not.throw(); }); it('incorrect text', () => { $(TRIGGER_ALERT_BUTTON_SELECTOR).click(); - expect(() => BrowserUtils.expectAlertText('Hello! I am not alert box!')) + expect(() => BrowserUtils.waitForAlertText('Hello! I am not alert box!')) .to.throw(Error) .with.property('message') .contains("Incorrect alert's text or alert not found."); }); it('no alert', () => { - expect(() => BrowserUtils.expectAlertText('Hello! I am an alert box!')) + expect(() => BrowserUtils.waitForAlertText('Hello! I am an alert box!')) .to.throw(Error) .with.property('message') .contains("Incorrect alert's text or alert not found."); diff --git a/src/test/specs/ExpectAttributeValueSpec.ts b/src/test/specs/ExpectAttributeValueSpec.ts index 377112035..39f05caa1 100644 --- a/src/test/specs/ExpectAttributeValueSpec.ts +++ b/src/test/specs/ExpectAttributeValueSpec.ts @@ -10,30 +10,30 @@ const CORRECT_ATTRIBUTE_VALUE: string = 'hello world'; const INCORRECT_ATTRIBUTE_VALUE: string = 'hello hello world'; /** - * wdio-allure-ts expectAttributeValueSpec + * wdio-allure-ts waitForAttributeValueSpec */ -describeCommon('expectAttributeValue', () => { +describeCommon('waitForAttributeValue', () => { it('correct value', () => { expect(() => - BrowserUtils.expectAttributeValue(SELECTOR_WITH_ATTRIBUTE, ATTRIBUTE_NAME, CORRECT_ATTRIBUTE_VALUE) + BrowserUtils.waitForAttributeValue(SELECTOR_WITH_ATTRIBUTE, ATTRIBUTE_NAME, CORRECT_ATTRIBUTE_VALUE) ).to.not.throw(Error); }); it('incorrect value', () => { - expect(() => BrowserUtils.expectAttributeValue(SELECTOR_WITH_ATTRIBUTE, ATTRIBUTE_NAME, INCORRECT_ATTRIBUTE_VALUE)) + expect(() => BrowserUtils.waitForAttributeValue(SELECTOR_WITH_ATTRIBUTE, ATTRIBUTE_NAME, INCORRECT_ATTRIBUTE_VALUE)) .to.throw(Error) .with.property('message') .contains(`Incorrect attribute`); }); it('incorrect selector', () => { - expect(() => BrowserUtils.expectAttributeValue(INCORRECT_SELECTOR, ATTRIBUTE_NAME, INCORRECT_ATTRIBUTE_VALUE)) + expect(() => BrowserUtils.waitForAttributeValue(INCORRECT_SELECTOR, ATTRIBUTE_NAME, INCORRECT_ATTRIBUTE_VALUE)) .to.throw(Error) .with.property('message') .contains(`Incorrect attribute`); }); it('incorrect attribute', () => { expect(() => - BrowserUtils.expectAttributeValue(INCORRECT_SELECTOR, INCORRECT_ATTRIBUTE_NAME, INCORRECT_ATTRIBUTE_VALUE) + BrowserUtils.waitForAttributeValue(INCORRECT_SELECTOR, INCORRECT_ATTRIBUTE_NAME, INCORRECT_ATTRIBUTE_VALUE) ) .to.throw(Error) .with.property('message') diff --git a/src/test/specs/ExpectCurrentUrlSpec.ts b/src/test/specs/ExpectCurrentUrlSpec.ts index e1b966d42..fc3db69ec 100644 --- a/src/test/specs/ExpectCurrentUrlSpec.ts +++ b/src/test/specs/ExpectCurrentUrlSpec.ts @@ -4,15 +4,15 @@ import { describeCommon, sampleAppUrl } from '../TestHelper'; const CLOUDINARY_URL: string = 'https://cloudinary.com'; /** - * wdio-allure-ts ExpectCurrentUrlSpec + * wdio-allure-ts waitForUrl */ -describeCommon('expectCurrentUrl', () => { +describeCommon('waitForUrl', () => { it('correct url', () => { - expect(() => BrowserUtils.expectCurrentUrl(sampleAppUrl)).to.not.throw(Error); + expect(() => BrowserUtils.waitForUrl(sampleAppUrl)).to.not.throw(Error); }); it('incorrect url', () => { - expect(() => BrowserUtils.expectCurrentUrl(CLOUDINARY_URL)) + expect(() => BrowserUtils.waitForUrl(CLOUDINARY_URL)) .to.throw(Error) .with.property('message') .equal(`Url not as expected '${CLOUDINARY_URL}'`); diff --git a/src/test/specs/ExpectNoAttributeValueSpec.ts b/src/test/specs/ExpectNoAttributeValueSpec.ts index 540bcd8b7..ae5ee54d6 100644 --- a/src/test/specs/ExpectNoAttributeValueSpec.ts +++ b/src/test/specs/ExpectNoAttributeValueSpec.ts @@ -9,34 +9,31 @@ const EMPTY_DIV: string = '//*[@id="formsWithoutAttribute"]//*[@id="noAttDiv"]'; describeCommon('expectNoAttributeValue', () => { it("Doesn't contains value", () => { expect(() => - BrowserUtils.expectNoAttributeValue(EMPTY_DIV, 'data-test', 'expectNoAttributeValueCent') + BrowserUtils.waitForAttributeValue(EMPTY_DIV, 'data-test', 'expectNoAttributeValueCent', true) ).to.not.throw(Error); }); it('Contains word substring', () => { expect(() => - BrowserUtils.expectNoAttributeValue(EMPTY_DIV, 'data-test', 'expectNoAttributeValueCenterrr') + BrowserUtils.waitForAttributeValue(EMPTY_DIV, 'data-test', 'expectNoAttributeValueCenterrr', true) ).to.not.throw(Error); }); it('Exact match error thrown', () => { - expect(() => BrowserUtils.expectNoAttributeValue(EMPTY_DIV, 'data-test', 'expectNoAttributeValueCenter')) + expect(() => BrowserUtils.waitForAttributeValue(EMPTY_DIV, 'data-test', 'expectNoAttributeValueCenter', true)) .to.throw(Error) .with.property('message') .contains('Incorrect attribute'); }); it('Element not exists', () => { - BrowserUtils.navigateToUrl(sampleAppUrl); - expect(() => BrowserUtils.expectNoAttributeValue('//NotExist', 'method', 'post')) - .to.throw(Error) - .with.property('message') - .contains('Element not exist'); + BrowserUtils.url(sampleAppUrl); + expect(() => BrowserUtils.waitForAttributeValue('//NotExist', 'method', 'post', true)).to.throw(Error); }); it('Attribute not exists', () => { - BrowserUtils.navigateToUrl(sampleAppUrl); - expect(() => BrowserUtils.expectNoAttributeValue(EMPTY_DIV, 'NotExist', 'post')) + BrowserUtils.url(sampleAppUrl); + expect(() => BrowserUtils.waitForAttributeValue(EMPTY_DIV, 'NotExist', 'post', true)) .to.throw(Error) .with.property('message') .contains('Incorrect attribute'); diff --git a/src/test/specs/ExpectNumberOfElementsSpec.ts b/src/test/specs/ExpectNumberOfElementsSpec.ts index 270fd2c9e..9c2c6e005 100644 --- a/src/test/specs/ExpectNumberOfElementsSpec.ts +++ b/src/test/specs/ExpectNumberOfElementsSpec.ts @@ -5,33 +5,30 @@ import { describeCommon } from '../TestHelper'; const SELECTION_BOX: string = '//*[@id="selection_list"]'; const LIST_ITEM: string = '//option'; -describeCommon('expectNumberOfElements', () => { +describeCommon('waitForNumberOfElements', () => { it('Expect number of elements equals', () => { - expect(() => BrowserUtils.expectNumberOfElements(`${SELECTION_BOX}${LIST_ITEM}`, 4)).to.not.throw(Error); + expect(() => BrowserUtils.waitForNumberOfElements(`${SELECTION_BOX}${LIST_ITEM}`, 4)).to.not.throw(Error); }); it('Expect number of elements not equals', () => { - expect(() => BrowserUtils.expectNumberOfElements(`${SELECTION_BOX}${LIST_ITEM}`, 3)) + expect(() => BrowserUtils.waitForNumberOfElements(`${SELECTION_BOX}${LIST_ITEM}`, 3)) .to.throw(Error) .with.property('message') .contains(`not equal`); }); it('Expect 0 elements equals', () => { - expect(() => BrowserUtils.expectNumberOfElements(`${SELECTION_BOX}`, 0)) - .to.throw(Error) - .with.property('message') - .contains(`element not visible`); + expect(() => BrowserUtils.waitForNumberOfElements("//div[@data-test='not-existing']", 0)).to.not.throw(Error); }); it('Expect 0 elements not equals', () => { - expect(() => BrowserUtils.expectNumberOfElements(`${SELECTION_BOX}${LIST_ITEM}`, 0)) + expect(() => BrowserUtils.waitForNumberOfElements(`${SELECTION_BOX}${LIST_ITEM}`, 0)) .to.throw(Error) .with.property('message') - .contains(`element not visible`); + .contains(`still existing`); }); it("Expect number of elements, element doesn't exists", () => { - expect(() => BrowserUtils.expectNumberOfElements(`//notExists`, 4)) + expect(() => BrowserUtils.waitForNumberOfElements(`//notExists`, 4)) .to.throw(Error) .with.property('message') .contains(`waitUntil condition timed out`); diff --git a/src/test/specs/ExpectTextSpec.ts b/src/test/specs/ExpectTextSpec.ts index 2ebfffc21..67c91e8b8 100644 --- a/src/test/specs/ExpectTextSpec.ts +++ b/src/test/specs/ExpectTextSpec.ts @@ -8,15 +8,15 @@ const DYNAMIC_TEXT_SELECTOR: string = `${TEST_FIELD_SELECTOR}//*[@id='dynamic_te const HIDDEN_TEXT_SELECTOR: string = `${TEST_FIELD_SELECTOR}//*[@id='hidden_text']`; const CHANGE_TEXT_BUTTON_SELECTOR: string = `${TEST_FIELD_SELECTOR}//button[@id='update_text']`; /** - * wdio-allure-ts expectedText tests + * wdio-allure-ts waitForText tests */ -describeCommon('expectText', () => { +describeCommon('waitForText', () => { it('correct text', () => { - expect(() => BrowserUtils.expectText(STATIC_TEXT_SELECTOR, 'Cloudinary rules!')).to.not.throw(); + expect(() => BrowserUtils.waitForText(STATIC_TEXT_SELECTOR, 'Cloudinary rules!')).to.not.throw(); }); it('hidden text', () => { - expect(() => BrowserUtils.expectText(HIDDEN_TEXT_SELECTOR, 'Cloudinary rules!')) + expect(() => BrowserUtils.waitForText(HIDDEN_TEXT_SELECTOR, 'Cloudinary rules!')) .to.throw() .with.property('message') .contains('Element not visible'); @@ -26,25 +26,25 @@ describeCommon('expectText', () => { $(CHANGE_TEXT_BUTTON_SELECTOR).waitForDisplayed(); $(CHANGE_TEXT_BUTTON_SELECTOR).click(); - BrowserUtils.expectText(DYNAMIC_TEXT_SELECTOR, 'Cloudinary still rules!'); + BrowserUtils.waitForText(DYNAMIC_TEXT_SELECTOR, 'Cloudinary still rules!'); }); it('fail on case sensitive', () => { - expect(() => BrowserUtils.expectText(STATIC_TEXT_SELECTOR, 'cloudinary rules!')) + expect(() => BrowserUtils.waitForText(STATIC_TEXT_SELECTOR, 'cloudinary rules!')) .to.throw(Error) .with.property('message') .contains('waitUntil condition timed out'); }); it('fail on spaces', () => { - expect(() => BrowserUtils.expectText(STATIC_TEXT_SELECTOR, 'Cloudinary rules!')) + expect(() => BrowserUtils.waitForText(STATIC_TEXT_SELECTOR, 'Cloudinary rules!')) .to.throw(Error) .with.property('message') .contains('waitUntil condition timed out'); }); it('fail on wrong text', () => { - expect(() => BrowserUtils.expectText(STATIC_TEXT_SELECTOR, 'Cloudinary not rules!')) + expect(() => BrowserUtils.waitForText(STATIC_TEXT_SELECTOR, 'Cloudinary not rules!')) .to.throw(Error) .with.property('message') .contains('waitUntil condition timed out'); diff --git a/src/test/specs/GetAttributeSpec.ts b/src/test/specs/GetAttributeSpec.ts index 807c066bb..1a32838fa 100644 --- a/src/test/specs/GetAttributeSpec.ts +++ b/src/test/specs/GetAttributeSpec.ts @@ -1,5 +1,4 @@ import { assert, expect } from 'chai'; -import { EOL } from 'os'; import { BrowserUtils } from '../..'; import { describeCommon } from '../TestHelper'; @@ -15,11 +14,8 @@ describeCommon('GetAttributeSpec of BrowserUtils Tests', () => { it('should fail on not existing attribute', () => { const selector: string = WRONG_ATTRIB_DIV; const attributeName: string = 'ONG'; - const errorMessage: string = `Failed to get '${attributeName}' attribute from '${selector}' ${EOL} AssertionError: Found multiple results matching requested attribute '${attributeName}' or no results for element: '${selector}'`; - expect(() => BrowserUtils.getAttribute(selector, attributeName)) - .to.throw(Error) - .with.property('message') - .contains(errorMessage); + const attr = BrowserUtils.getAttribute(selector, attributeName); + expect(attr).to.equal(null); }); }); diff --git a/src/test/specs/GetCookiesSpec.ts b/src/test/specs/GetCookiesSpec.ts index ce8c558bf..7612d2dcb 100644 --- a/src/test/specs/GetCookiesSpec.ts +++ b/src/test/specs/GetCookiesSpec.ts @@ -10,7 +10,7 @@ let cookie: WebDriver.Cookie; describeCommon('GetCookieSpec', () => { beforeEach(() => { cookie = { name: TestUtils.randomString(), value: TestUtils.randomString() }; - BrowserUtils.setCookie(cookie, null); + BrowserUtils.setCookies(cookie, null); }); it('expect unique cookie', () => { assert.equal(BrowserUtils.getCookies().length, 1, 'Incorrect number of retrieved cookies'); diff --git a/src/test/specs/GetCssPropertySpec.ts b/src/test/specs/GetCssPropertySpec.ts index 62fd8d7c1..e90aa8c85 100644 --- a/src/test/specs/GetCssPropertySpec.ts +++ b/src/test/specs/GetCssPropertySpec.ts @@ -5,7 +5,7 @@ import { describeCommon } from '../TestHelper'; const HEADER: string = '//*[@id="headerSection-1"]/h1'; /** - * wdio-allure-ts navigateToUrl action test + * wdio-allure-ts url action test */ describeCommon('getCssProperty', () => { it('retrieve css property', () => { diff --git a/src/test/specs/GetElementSizeSpec.ts b/src/test/specs/GetElementSizeSpec.ts index dda015f0c..775cae586 100644 --- a/src/test/specs/GetElementSizeSpec.ts +++ b/src/test/specs/GetElementSizeSpec.ts @@ -7,14 +7,14 @@ const ELEMENT_DIV: string = '//div[@id="getElementSize"]'; let size: { width?: number; height?: number } = {}; /** - * wdio-allure-ts get element size + * wdio-allure-ts getSize */ -describeCommon('getElementSize', () => { +describeCommon('getSizeSpec', () => { it('get element size', () => { const expectedWidth: number = 250; const expectedHeight: number = 150; - size = BrowserUtils.getElementSize(ELEMENT_DIV); + size = BrowserUtils.getSize(ELEMENT_DIV); assert.equal(size.width, expectedWidth, 'window width'); assert.equal(size.height, expectedHeight, 'window height'); }); diff --git a/src/test/specs/GetNumberOfElementsSpec.ts b/src/test/specs/GetNumberOfElementsSpec.ts index 37ff3f0b2..e9e691661 100644 --- a/src/test/specs/GetNumberOfElementsSpec.ts +++ b/src/test/specs/GetNumberOfElementsSpec.ts @@ -17,9 +17,6 @@ describeCommon('getNumberOfElements', () => { }); it('undefined selector value', () => { - expect(() => BrowserUtils.getNumberOfElements(undefined)) - .to.throw(Error) - .with.property('message') - .contains('selector needs to be typeof `string` or `function`'); + expect(() => BrowserUtils.getNumberOfElements(undefined)).to.throw(Error); }); }); diff --git a/src/test/specs/GetSystemDataSpec.ts b/src/test/specs/GetSystemDataSpec.ts deleted file mode 100644 index d8feb64f2..000000000 --- a/src/test/specs/GetSystemDataSpec.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { expect } from 'chai'; -import { BrowserUtils } from '../..'; - -describe('GetSystemData', () => { - it('correct data', () => { - expect(BrowserUtils.getSystemData()).to.contain('HeadlessChrome'); - }); -}); diff --git a/src/test/specs/HoverSpec.ts b/src/test/specs/HoverSpec.ts index 8eca0e3d0..27c9a327e 100644 --- a/src/test/specs/HoverSpec.ts +++ b/src/test/specs/HoverSpec.ts @@ -5,20 +5,17 @@ import { describeCommon } from '../TestHelper'; const HOVER_BUTTON: string = "//*[@id='HoverSpec']//*[@id='HoverButton']"; const NOT_EXISITING_ELEMENT_SELECTOR: string = "//*[@class='AndrzejTheKing']"; /** - * wdio-allure-ts Hover actions on test button + * wdio-allure-ts moveTo actions on test button */ -describeCommon('HoverAction', () => { +describeCommon('moveToSpec', () => { it('hoverTrue', () => { $(HOVER_BUTTON).scrollIntoView(); - BrowserUtils.hover(HOVER_BUTTON); + BrowserUtils.moveTo(HOVER_BUTTON); assert.equal($(HOVER_BUTTON).getCSSProperty('background-color').parsed.hex, '#4caf50'); }); it('hoverFalse', () => { - expect(() => BrowserUtils.hover(NOT_EXISITING_ELEMENT_SELECTOR)) - .to.throw(Error) - .with.property('message') - .contains('Element not exist'); + expect(() => BrowserUtils.moveTo(NOT_EXISITING_ELEMENT_SELECTOR)).to.throw(Error); }); }); diff --git a/src/test/specs/IsExistSpec.ts b/src/test/specs/IsExistSpec.ts index 62d329f3b..f942e82dd 100644 --- a/src/test/specs/IsExistSpec.ts +++ b/src/test/specs/IsExistSpec.ts @@ -7,18 +7,15 @@ const EXISTING_ELEMENT_SELECTOR: string = `${PARENT_SELECTOR}//*[@id='is-exist-b const NOT_EXISTING_ELEMENT_SELECTOR: string = `${PARENT_SELECTOR}//*[@id='not-existing-button']`; /** - * isExist + * waitForExist */ -describeCommon('isExist', () => { +describeCommon('waitForExist', () => { it('existing element', () => { - BrowserUtils.isExist(EXISTING_ELEMENT_SELECTOR); + BrowserUtils.waitForExist(EXISTING_ELEMENT_SELECTOR); }); it('not existing element', () => { - expect(() => BrowserUtils.isExist(NOT_EXISTING_ELEMENT_SELECTOR)) - .to.throw(Error) - .with.property('message') - .contains('Element not exist'); + expect(() => BrowserUtils.waitForExist(NOT_EXISTING_ELEMENT_SELECTOR)).to.throw(Error); }); }); diff --git a/src/test/specs/NavigateToUrlSpec.ts b/src/test/specs/NavigateToUrlSpec.ts index 1bba8ced7..1ee7c1558 100644 --- a/src/test/specs/NavigateToUrlSpec.ts +++ b/src/test/specs/NavigateToUrlSpec.ts @@ -2,10 +2,10 @@ import { BrowserUtils } from '../..'; import { describeCommon, sampleAppUrl } from '../TestHelper'; /** - * wdio-allure-ts navigateToUrl action test + * wdio-allure-ts url action test */ -describeCommon('navigateToUrl', () => { +describeCommon('url', () => { it('navigate successfully', () => { - BrowserUtils.navigateToUrl(sampleAppUrl); + BrowserUtils.url(sampleAppUrl); }); }); diff --git a/src/test/specs/NotExistSpec.ts b/src/test/specs/NotExistSpec.ts index 420cabc7c..4f289cf19 100644 --- a/src/test/specs/NotExistSpec.ts +++ b/src/test/specs/NotExistSpec.ts @@ -3,19 +3,19 @@ import { BrowserUtils } from '../..'; import { describeCommon } from '../TestHelper'; /** - * notExist + * waitForExist reverse:true */ -describeCommon('notExist', () => { +describeCommon('waitForExist reverse:true', () => { it('disappearing element', () => { const DISAPPEARING_BUTTON_SELECTOR: string = "//button[@id='not-existing-button']"; BrowserUtils.click(DISAPPEARING_BUTTON_SELECTOR); - expect(() => BrowserUtils.notExist(DISAPPEARING_BUTTON_SELECTOR)).to.not.throw(Error); + expect(() => BrowserUtils.waitForExist(DISAPPEARING_BUTTON_SELECTOR, { reverse: true })).to.not.throw(Error); }); it('fail on existing element', () => { const EXISTING_BUTTON_SELECTOR: string = "//button[@id='existing-button']"; - expect(() => BrowserUtils.notExist(EXISTING_BUTTON_SELECTOR)) + expect(() => BrowserUtils.waitForExist(EXISTING_BUTTON_SELECTOR, { reverse: true })) .to.throw(Error) .with.property('message') - .contains(`Failed to validate element not exist '${EXISTING_BUTTON_SELECTOR}'`); + .contains('still existing'); }); }); diff --git a/src/test/specs/NotVisibleSpec.ts b/src/test/specs/NotVisibleSpec.ts index 4dc92c9e1..ef279cb12 100644 --- a/src/test/specs/NotVisibleSpec.ts +++ b/src/test/specs/NotVisibleSpec.ts @@ -7,28 +7,31 @@ const NOT_VISIBLE_ELEMENT_SELECTOR: string = "//*[@data-test='not-visible-btn']" const NOT_EXIST_ELEMENT_SELECTOR: string = "//*[@data-test='no-such-element']"; const DISAPPEARING_ELEMENT_SELECTOR: string = "//*[@data-test='disappearing-btn']"; /** - * wdio-allure-ts notVisible action test + * wdio-allure-ts waitForDisplayed - reverse - true action test */ -describeCommon('notVisible', () => { - it('visible element', () => { - expect(() => BrowserUtils.notVisible(VISIBLE_ELEMENT_SELECTOR)) +describeCommon('waitForDisplayed - reverse: true', () => { + it('displayed element', () => { + expect(() => BrowserUtils.waitForDisplayed(VISIBLE_ELEMENT_SELECTOR, { reverse: true })) .to.throw(Error) .with.property('message') - .contains('Failed to validate element not visible'); + .contains(' still existing'); }); - it('notVisible element ', () => { - expect(() => BrowserUtils.notVisible(NOT_VISIBLE_ELEMENT_SELECTOR)).to.not.throw(Error); + it('notDisplayed but exist element ', () => { + expect(() => BrowserUtils.waitForDisplayed(NOT_VISIBLE_ELEMENT_SELECTOR, { reverse: true })) + .to.throw(Error) + .with.property('message') + .contains('still existing'); }); it('not exist element ', () => { - expect(() => BrowserUtils.notVisible(NOT_EXIST_ELEMENT_SELECTOR)).to.not.throw(Error); + expect(() => BrowserUtils.waitForDisplayed(NOT_EXIST_ELEMENT_SELECTOR, { reverse: true })).to.not.throw(Error); }); it('disappearing element', () => { expect(() => BrowserUtils.waitForDisplayed(DISAPPEARING_ELEMENT_SELECTOR)).to.not.throw(Error); $(DISAPPEARING_ELEMENT_SELECTOR).click(); - expect(() => BrowserUtils.notVisible(DISAPPEARING_ELEMENT_SELECTOR)).to.not.throw(Error); + expect(() => BrowserUtils.waitForDisplayed(DISAPPEARING_ELEMENT_SELECTOR, { reverse: true })).to.not.throw(Error); }); }); diff --git a/src/test/specs/RefreshBrowserSpec.ts b/src/test/specs/RefreshBrowserSpec.ts index 8a81442bf..fc98a1539 100644 --- a/src/test/specs/RefreshBrowserSpec.ts +++ b/src/test/specs/RefreshBrowserSpec.ts @@ -4,11 +4,11 @@ import { describeCommon } from '../TestHelper'; const REFRESH_BROWSER_FIELD: string = "//*[@id='RefreshBrowserSpec']//*[@id='RefreshBrowserCheckFiled']"; -describeCommon('RefreshBrowserAction', () => { - it('RefreshBrowserTrue', () => { +describeCommon('RefreshSpec', () => { + it('RefreshTrue', () => { $(REFRESH_BROWSER_FIELD).scrollIntoView(); $(REFRESH_BROWSER_FIELD).setValue('TestText'); - BrowserUtils.refreshBrowser(); + BrowserUtils.refresh(); $(REFRESH_BROWSER_FIELD).scrollIntoView(); $(REFRESH_BROWSER_FIELD).waitForDisplayed(); expect($(REFRESH_BROWSER_FIELD).getValue()).to.be.eq(''); diff --git a/src/test/specs/RightClickSpec.ts b/src/test/specs/RightClickSpec.ts index ae489be25..1e6176f8d 100644 --- a/src/test/specs/RightClickSpec.ts +++ b/src/test/specs/RightClickSpec.ts @@ -9,7 +9,7 @@ const RIGHT_CLICK_BUTTON_SELECTOR: string = "//*[@id='buttonRightMouseClick']"; */ describeCommon('RightClickSpec', () => { it('RightClick ', () => { - BrowserUtils.rightClick(RIGHT_CLICK_BUTTON_SELECTOR); + BrowserUtils.click(RIGHT_CLICK_BUTTON_SELECTOR, { button: 'right' }); assert.equal(BrowserUtils.getText(RIGHT_CLICK_BUTTON_SELECTOR), 'Button clicked'); }); }); diff --git a/src/test/specs/ScrollToElementSpec.ts b/src/test/specs/ScrollToElementSpec.ts index ea779f9b1..76f68688b 100644 --- a/src/test/specs/ScrollToElementSpec.ts +++ b/src/test/specs/ScrollToElementSpec.ts @@ -6,24 +6,24 @@ const TEST_FIELD_SELECTOR: string = "//*[@id='ScrollToElement']"; const LIST_SELECTOR: string = `${TEST_FIELD_SELECTOR}//*[@id='scroll-content']//*[@id='div-item']`; -describeCommon('scrollToElement', () => { +describeCommon('scrollTo', () => { it('scroll to element with lazy load', () => { const elementToScrollSelector: string = `${TEST_FIELD_SELECTOR}//*[@id='div-item' and text()='my awesome new div 4']`; assert.isFalse($(elementToScrollSelector).isDisplayed()); - BrowserUtils.scrollToElement(elementToScrollSelector, LIST_SELECTOR); + BrowserUtils.scrollToItemInList(elementToScrollSelector, LIST_SELECTOR); assert.isTrue($(elementToScrollSelector).isDisplayed()); }); it('scroll to already loaded element', () => { const elementToScrollSelector: string = `${TEST_FIELD_SELECTOR}//*[@id='div-item' and text()='my awesome new div 1']`; assert.isTrue($(elementToScrollSelector).isDisplayed()); - BrowserUtils.scrollToElement(elementToScrollSelector, LIST_SELECTOR); + BrowserUtils.scrollToItemInList(elementToScrollSelector, LIST_SELECTOR); }); it('fail to scroll', () => { const elementToScrollSelector: string = `${TEST_FIELD_SELECTOR}//*[@id='div-item' and text()='my awesome new div 100']`; assert.isFalse($(elementToScrollSelector).isDisplayed()); - expect(() => BrowserUtils.scrollToElement(elementToScrollSelector, LIST_SELECTOR)) + expect(() => BrowserUtils.scrollToItemInList(elementToScrollSelector, LIST_SELECTOR)) .to.throw(Error) .with.property('message') .contains('Failed to scroll to'); diff --git a/src/test/specs/ScrollToSpec.ts b/src/test/specs/ScrollToSpec.ts index 60cabdb27..71b8ab6a6 100644 --- a/src/test/specs/ScrollToSpec.ts +++ b/src/test/specs/ScrollToSpec.ts @@ -20,10 +20,10 @@ describeCommon('ScrollTo', () => { function getVerticalPosition(): number { const script: string = `return document.getElementById('${TEST_DIV_ID}').scrollTop`; - return Number(BrowserUtils.executeScript(script)); + return Number(BrowserUtils.execute(script)); } function getHorizontalPosition(): number { const script: string = `return document.getElementById('${TEST_DIV_ID}').scrollLeft`; - return Number(BrowserUtils.executeScript(script)); + return Number(BrowserUtils.execute(script)); } diff --git a/src/test/specs/SelectByValueSpec.ts b/src/test/specs/SelectByValueSpec.ts index a3d5dc542..564e08a46 100644 --- a/src/test/specs/SelectByValueSpec.ts +++ b/src/test/specs/SelectByValueSpec.ts @@ -15,20 +15,17 @@ const NOT_EXISTING_ELEMENT_SELECTOR: string = `${PARENT_SELECTOR}//*[@id='not-ex describeCommon('selectByValue', () => { it('select by existing value', () => { - BrowserUtils.selectByValue(EXISTING_ELEMENT_SELECTOR, EXISTING_VALUE); + BrowserUtils.selectByAttribute(EXISTING_ELEMENT_SELECTOR, 'value', EXISTING_VALUE); }); it('select by none existing value', () => { - expect(() => BrowserUtils.selectByValue(EXISTING_ELEMENT_SELECTOR, NOT_EXISTING_VALUE)) + expect(() => BrowserUtils.selectByAttribute(EXISTING_ELEMENT_SELECTOR, 'value', NOT_EXISTING_VALUE)) .to.throw(Error) .with.property('message') .contains('Failed to select '); }); it('select hidden element by value', () => { - expect(() => BrowserUtils.selectByValue(NOT_EXISTING_ELEMENT_SELECTOR, HIDDEN_VALUE)) - .to.throw(Error) - .with.property('message') - .contains('Element not exist'); + expect(() => BrowserUtils.selectByAttribute(NOT_EXISTING_ELEMENT_SELECTOR, 'value', HIDDEN_VALUE)).to.throw(Error); }); }); diff --git a/src/test/specs/SendKeysSpec.ts b/src/test/specs/SendKeysSpec.ts index af356b950..a796c52cc 100644 --- a/src/test/specs/SendKeysSpec.ts +++ b/src/test/specs/SendKeysSpec.ts @@ -7,7 +7,7 @@ const TEXT_INPUT: string = "//*[@id='SendKeys_input__text']"; const text: string = 'Cloudinary'; /** - * wdio-allure-ts sendKeys tests + * wdio-allure-ts keys tests */ describeCommon('SendKeysSpec', () => { beforeEach(() => { @@ -16,37 +16,37 @@ describeCommon('SendKeysSpec', () => { }); it('send string', () => { - BrowserUtils.sendKeys(text); + BrowserUtils.keys(text); assert.equal($(TEXT_INPUT).getValue(), text); }); it('send an array of strings', () => { const strArray: Array = ['C', 'L', 'O', 'U', 'D', 'I', 'N', 'A', 'R', 'Y']; - BrowserUtils.sendKeys(strArray); + BrowserUtils.keys(strArray); assert.equal($(TEXT_INPUT).getValue(), strArray.join('')); }); it('send string twice', () => { - BrowserUtils.sendKeys(text); - BrowserUtils.sendKeys(text); + BrowserUtils.keys(text); + BrowserUtils.keys(text); assert.equal($(TEXT_INPUT).getValue(), `${text}${text}`); }); it('Add text after sending enter for new line', () => { - BrowserUtils.sendKeys(text); - BrowserUtils.sendKeys(SpecialKeys.ENTER); - BrowserUtils.sendKeys(text); + BrowserUtils.keys(text); + BrowserUtils.keys(SpecialKeys.ENTER); + BrowserUtils.keys(text); assert.equal($(TEXT_INPUT).getValue(), `${text}\n${text}`); }); it('Array of Special Keys', () => { const specialKeysArray: Array = [SpecialKeys.ENTER, SpecialKeys.ENTER, SpecialKeys.ENTER]; - BrowserUtils.sendKeys(specialKeysArray); + BrowserUtils.keys(specialKeysArray); assert.equal($(TEXT_INPUT).getValue(), '\n\n\n'); }); it('Special Key Emoji', () => { - BrowserUtils.sendKeys(SpecialKeys.EMOJI_HEART); + BrowserUtils.keys(SpecialKeys.EMOJI_HEART); assert.equal($(TEXT_INPUT).getValue(), SpecialKeys.EMOJI_HEART); }); }); diff --git a/src/test/specs/SetCookieSpec.ts b/src/test/specs/SetCookieSpec.ts index 4eac3f2d3..4dbe2f56f 100644 --- a/src/test/specs/SetCookieSpec.ts +++ b/src/test/specs/SetCookieSpec.ts @@ -1,3 +1,4 @@ +import { Cookie } from '@wdio/protocols/build/types'; import { assert } from 'chai'; import { BrowserUtils, TestUtils } from '../..'; import { describeCommon } from '../TestHelper'; @@ -5,15 +6,15 @@ import { describeCommon } from '../TestHelper'; /** * wdio-allure-ts setCookie tests */ -let retrievedCookiesArray: Array; -let cookie: WebDriver.Cookie; +let retrievedCookiesArray: Array; +let cookie: Cookie; const TEST_PAGE_DOMAIN: string = '127.0.0.1'; -describeCommon('Set Cookie', () => { +describeCommon('setCookies', () => { beforeEach(() => { cookie = { name: TestUtils.randomString(5), value: TestUtils.randomString(5) }; - BrowserUtils.setCookie(cookie, null); + BrowserUtils.setCookies(cookie, null); retrievedCookiesArray = browser.getCookies([cookie.name]); }); @@ -33,9 +34,9 @@ describeCommon('Set Cookie', () => { it('validate cookie with domain value', () => { const url: string = BrowserUtils.getUrl(); - BrowserUtils.setCookie(cookie, 'https://cloudinary.com/'); + BrowserUtils.setCookies(cookie, 'https://cloudinary.com/'); retrievedCookiesArray = browser.getCookies([cookie.name]); assert.equal(retrievedCookiesArray[0].domain, TEST_PAGE_DOMAIN, 'Incorrect cookie domain'); - BrowserUtils.expectCurrentUrl(url); + BrowserUtils.waitForUrl(url); }); }); diff --git a/src/test/specs/SwitchToFrameSpec.ts b/src/test/specs/SwitchToFrameSpec.ts index 380bb3e11..6bc7106da 100644 --- a/src/test/specs/SwitchToFrameSpec.ts +++ b/src/test/specs/SwitchToFrameSpec.ts @@ -12,13 +12,13 @@ const FRAME_DONT_EXISTS: string = "//*[@id='iframeDontExists']"; */ describeCommon('switchToIframe', () => { it('Switch to iframe, header text at iFrame 2', () => { - BrowserUtils.notVisible(FRAME_2_HEADER_1); + BrowserUtils.waitForDisplayed(FRAME_2_HEADER_1, { reverse: true }); BrowserUtils.switchToFrame(FRAME_TWO); assert.equal($(FRAME_2_HEADER_1).getText(), 'Frame 2 Heading 1'); }); it('iframe 2 not available after switch to iframe 1', () => { - BrowserUtils.notVisible(FRAME_2_HEADER_1); + BrowserUtils.waitForDisplayed(FRAME_2_HEADER_1, { reverse: true }); BrowserUtils.switchToFrame(FRAME_ONE); expect(() => $(FRAME_2_HEADER_1).getText()).to.throw(Error); }); diff --git a/src/test/specs/TabsSpec.ts b/src/test/specs/TabsSpec.ts index be3494cad..fea6926e7 100644 --- a/src/test/specs/TabsSpec.ts +++ b/src/test/specs/TabsSpec.ts @@ -8,29 +8,29 @@ const OPEN_TAB_BUTTON: string = "//button[@data-test='open-tab-btn']"; */ describeCommon('tab actions', () => { it('get tab ids', () => { - let tabIds: Array = BrowserUtils.getTabIds(); + let tabIds: Array = BrowserUtils.getWindowHandles(); assert.equal(tabIds.length, 1, 'Incorrect number of tab ids'); BrowserUtils.click(OPEN_TAB_BUTTON); - tabIds = BrowserUtils.getTabIds(); + tabIds = BrowserUtils.getWindowHandles(); assert.equal(tabIds.length, 2, 'Incorrect number of tab ids'); }); it('switch to tab', () => { - BrowserUtils.navigateToUrl(sampleAppUrl); + BrowserUtils.url(sampleAppUrl); BrowserUtils.click(OPEN_TAB_BUTTON); - const tabIds: Array = BrowserUtils.getTabIds(); + const tabIds: Array = BrowserUtils.getWindowHandles(); - BrowserUtils.switchTab(tabIds[1]); + BrowserUtils.switchToWindow(tabIds[1]); assert.equal(tabIds[1], browser.getWindowHandle(), 'Failed to switch tabs'); }); - it('switch to incorrect tab id', () => { + it('switch to incorrect window id', () => { const badTabId: string = 'notExistingTabId'; - expect(() => BrowserUtils.switchTab(badTabId)) + expect(() => BrowserUtils.switchToWindow(badTabId)) .to.throw(Error) .with.property('message') - .contains(`Failed switch to tab by id: '${badTabId}'`); + .contains(`Failed switch to window by id: '${badTabId}'`); }); }); diff --git a/src/test/specs/WaitForDisplayedSpec.ts b/src/test/specs/WaitForDisplayedSpec.ts index 099f7222b..441098c17 100644 --- a/src/test/specs/WaitForDisplayedSpec.ts +++ b/src/test/specs/WaitForDisplayedSpec.ts @@ -17,16 +17,10 @@ describeCommon('waitForDisplayed', () => { }); it('not existing element', () => { - expect(() => BrowserUtils.waitForDisplayed(NOT_EXISTING_ELEMENT_SELECTOR)) - .to.throw(Error) - .with.property('message') - .contains('Element not exist '); + expect(() => BrowserUtils.waitForDisplayed(NOT_EXISTING_ELEMENT_SELECTOR)).to.throw(Error); }); it('hidden element', () => { - expect(() => BrowserUtils.waitForDisplayed(HIDDEN_ELEMENT_SELECTOR)) - .to.throw(Error) - .with.property('message') - .contains(`Element not visible '${HIDDEN_ELEMENT_SELECTOR}'`); + expect(() => BrowserUtils.waitForDisplayed(HIDDEN_ELEMENT_SELECTOR)).to.throw(Error); }); }); diff --git a/src/test/specs/WaitForEnabledSpec.ts b/src/test/specs/WaitForEnabledSpec.ts index d7342d587..4bae40263 100644 --- a/src/test/specs/WaitForEnabledSpec.ts +++ b/src/test/specs/WaitForEnabledSpec.ts @@ -17,9 +17,6 @@ describeCommon('waitForEnabled', () => { .contains(`Element not enabled`); }); it('element not exists', () => { - expect(() => BrowserUtils.waitForEnabled(NOT_EXISTS_ELEMENT_SELECTOR)) - .to.throw(Error) - .with.property('message') - .contains(`Element not exist`); + expect(() => BrowserUtils.waitForEnabled(NOT_EXISTS_ELEMENT_SELECTOR)).to.throw(Error); }); }); diff --git a/src/test/specs/WaitUntilSpec.ts b/src/test/specs/WaitUntilSpec.ts index 20e2fe7e2..ac2831d9a 100644 --- a/src/test/specs/WaitUntilSpec.ts +++ b/src/test/specs/WaitUntilSpec.ts @@ -16,22 +16,20 @@ describeCommon('WaitUntilSpec of BrowserUtils Tests', () => { it('Validate text found within given timeout ', () => { BrowserUtils.waitForDisplayed(TEXT_ELEMENT_SELECTOR); assert.isTrue( - BrowserUtils.waitUntil( - () => BrowserUtils.getText(TEXT_ELEMENT_SELECTOR) === TEXT_ELEMENT_VALUE, - 'Some Error', - TIMEOUT - ) + BrowserUtils.waitUntil(() => BrowserUtils.getText(TEXT_ELEMENT_SELECTOR) === TEXT_ELEMENT_VALUE, { + timeout: TIMEOUT, + timeoutMsg: 'Some Error', + }) ); }); it('Validate text not found withing timeout and error message shown ', () => { BrowserUtils.scrollIntoView(HEADER_TEXT_H1); expect(() => - BrowserUtils.waitUntil( - () => BrowserUtils.getText(HEADER_TEXT_H1) === INCORRECT_TEXT_ELEMENT_VALUE, - `Didn't find '${INCORRECT_TEXT_ELEMENT_VALUE}' text in given timeout`, - TIMEOUT - ) + BrowserUtils.waitUntil(() => BrowserUtils.getText(HEADER_TEXT_H1) === INCORRECT_TEXT_ELEMENT_VALUE, { + timeoutMsg: `Didn't find '${INCORRECT_TEXT_ELEMENT_VALUE}' text in given timeout`, + timeout: TIMEOUT, + }) ) .to.throw(Error) .with.property('message') diff --git a/src/test/specs/getElementLocationSpec.ts b/src/test/specs/getElementLocationSpec.ts index 7a9bb3b1f..73a5e8cf2 100644 --- a/src/test/specs/getElementLocationSpec.ts +++ b/src/test/specs/getElementLocationSpec.ts @@ -9,12 +9,12 @@ let location: { x?: number; y?: number }; /** * wdio-allure-ts get element location */ -describeCommon('getElementLocation', () => { +describeCommon('getLocation', () => { it('get element Location', () => { const expectedX: number = 22; const expectedY: number = 8; - location = BrowserUtils.getElementLocation(ELEMENT); + location = BrowserUtils.getLocation(ELEMENT); assert.equal(location.x, expectedX, 'Element X position'); assert.equal(location.y, expectedY, 'Element Y position'); }); diff --git a/src/test/specs/startNetworkAuditSpec.ts b/src/test/specs/startNetworkAuditSpec.ts index c3150896a..c4db14214 100644 --- a/src/test/specs/startNetworkAuditSpec.ts +++ b/src/test/specs/startNetworkAuditSpec.ts @@ -22,7 +22,7 @@ describeCommon('startNetworkAudit', () => { }); }); - BrowserUtils.navigateToUrl(sampleAppUrl); + BrowserUtils.url(sampleAppUrl); BrowserUtils.waitUntil( () => {