From 26dd0e9b62930594fef5e1424f3c23f102bbc3ef Mon Sep 17 00:00:00 2001 From: kobenguyent Date: Tue, 30 May 2023 17:21:00 +0200 Subject: [PATCH 1/2] feat: highlight the interacting elements --- docs/helpers/Appium.md | 2 + docs/helpers/Nightmare.md | 2 + docs/helpers/Playwright.md | 6 + docs/helpers/Puppeteer.md | 2040 +----------------- docs/helpers/TestCafe.md | 2 + docs/helpers/WebDriver.md | 5 + lib/helper/Playwright.js | 20 + lib/helper/Puppeteer.js | 2710 ++++++++++++++++++++++++ lib/helper/scripts/highlightElement.js | 7 + 9 files changed, 2755 insertions(+), 2039 deletions(-) create mode 100644 lib/helper/scripts/highlightElement.js diff --git a/docs/helpers/Appium.md b/docs/helpers/Appium.md index a6fd268a4..134cd93f9 100644 --- a/docs/helpers/Appium.md +++ b/docs/helpers/Appium.md @@ -841,6 +841,8 @@ Field is located by name, label, CSS or XPath ```js I.appendField('#myTextField', 'appended'); +// typing secret +I.appendField('password', secret('123456')); ``` #### Parameters diff --git a/docs/helpers/Nightmare.md b/docs/helpers/Nightmare.md index feacd009e..2c0cd7197 100644 --- a/docs/helpers/Nightmare.md +++ b/docs/helpers/Nightmare.md @@ -91,6 +91,8 @@ Field is located by name, label, CSS or XPath ```js I.appendField('#myTextField', 'appended'); +// typing secret +I.appendField('password', secret('123456')); ``` #### Parameters diff --git a/docs/helpers/Playwright.md b/docs/helpers/Playwright.md index 45aeec26b..20cc6a474 100644 --- a/docs/helpers/Playwright.md +++ b/docs/helpers/Playwright.md @@ -74,6 +74,7 @@ Type: [object][5] - `ignoreLog` **[Array][15]<[string][8]>?** An array with console message types that are not logged to debug log. Default value is `['warning', 'log']`. E.g. you can set `[]` to log all messages. See all possible [values][38]. - `ignoreHTTPSErrors` **[boolean][26]?** Allows access to untrustworthy pages, e.g. to a page with an expired certificate. Default value is `false` - `bypassCSP` **[boolean][26]?** bypass Content Security Policy or CSP +- `highlightElement` **[boolean][26]?** highlight the interacting elements @@ -378,6 +379,8 @@ Field is located by name, label, CSS or XPath ```js I.appendField('#myTextField', 'appended'); +// typing secret +I.appendField('password', secret('123456')); ``` #### Parameters @@ -1826,6 +1829,9 @@ I.type('4141555311111111', 100); // passing in an array I.type(['T', 'E', 'X', 'T']); + +// passing a secret +I.type(secret('123456')); ``` #### Parameters diff --git a/docs/helpers/Puppeteer.md b/docs/helpers/Puppeteer.md index 37628f28d..1dba1f05a 100644 --- a/docs/helpers/Puppeteer.md +++ b/docs/helpers/Puppeteer.md @@ -56,2045 +56,7 @@ Type: [object][4] - `manualStart` **[boolean][17]?** do not start browser before a test, start it manually inside a helper with `this.helpers["Puppeteer"]._startBrowser()`. - `browser` **[string][6]?** can be changed to `firefox` when using [puppeteer-firefox][2]. - `chrome` **[object][4]?** pass additional [Puppeteer run options][22]. - - - -#### Example #1: Wait for 0 network connections. - -```js -{ - helpers: { - Puppeteer : { - url: "http://localhost", - restart: false, - waitForNavigation: "networkidle0", - waitForAction: 500 - } - } -} -``` - -#### Example #2: Wait for DOMContentLoaded event and 0 network connections - -```js -{ - helpers: { - Puppeteer : { - url: "http://localhost", - restart: false, - waitForNavigation: [ "domcontentloaded", "networkidle0" ], - waitForAction: 500 - } - } -} -``` - -#### Example #3: Debug in window mode - -```js -{ - helpers: { - Puppeteer : { - url: "http://localhost", - show: true - } - } -} -``` - -#### Example #4: Connect to remote browser by specifying [websocket endpoint][3] - -```js -{ - helpers: { - Puppeteer: { - url: "http://localhost", - chrome: { - browserWSEndpoint: "ws://localhost:9222/devtools/browser/c5aa6160-b5bc-4d53-bb49-6ecb36cd2e0a" - } - } - } -} -``` - -> Note: When connecting to remote browser `show` and specific `chrome` options (e.g. `headless` or `devtools`) are ignored. - -#### Example #5: Target URL with provided basic authentication - -```js -{ - helpers: { - Puppeteer : { - url: 'http://localhost', - basicAuth: {username: 'username', password: 'password'}, - show: true - } - } -} -``` - -#### Troubleshooting - -Error Message: `No usable sandbox!` - -When running Puppeteer on CI try to disable sandbox if you see that message - - helpers: { - Puppeteer: { - url: 'http://localhost', - show: false, - chrome: { - args: ['--no-sandbox', '--disable-setuid-sandbox'] - } - }, - } - -## Access From Helpers - -Receive Puppeteer client from a custom helper by accessing `browser` for the Browser object or `page` for the current Page object: - -```js -const { browser } = this.helpers.Puppeteer; -await browser.pages(); // List of pages in the browser - -const { page } = this.helpers.Puppeteer; -await page.url(); // Get the url of the current page -``` - -## Methods - -### Parameters - -- `config` - -### _addPopupListener - -Add the 'dialog' event listener to a page - -#### Parameters - -- `page` - -### _getPageUrl - -Gets page URL including hash. - -### _locate - -Get elements by different locator types, including strict locator -Should be used in custom helpers: - -```js -const elements = await this.helpers['Puppeteer']._locate({name: 'password'}); -``` - - - - -This action supports [React locators](https://codecept.io/react#locators) - - -#### Parameters - -- `locator` - -### _locateCheckable - -Find a checkbox by providing human readable text: -NOTE: Assumes the checkable element exists - -```js -this.helpers['Puppeteer']._locateCheckable('I agree with terms and conditions').then // ... -``` - -#### Parameters - -- `locator` -- `providedContext` - -### _locateClickable - -Find a clickable element by providing human readable text: - -```js -this.helpers['Puppeteer']._locateClickable('Next page').then // ... -``` - -#### Parameters - -- `locator` - -### _locateFields - -Find field elements by providing human readable text: - -```js -this.helpers['Puppeteer']._locateFields('Your email').then // ... -``` - -#### Parameters - -- `locator` - -### _setPage - -Set current page - -#### Parameters - -- `page` **[object][4]** page to set - -### acceptPopup - -Accepts the active JavaScript native popup window, as created by window.alert|window.confirm|window.prompt. -Don't confuse popups with modal windows, as created by [various -libraries][5]. - -### amAcceptingPopups - -Set the automatic popup response to Accept. -This must be set before a popup is triggered. - -```js -I.amAcceptingPopups(); -I.click('#triggerPopup'); -I.acceptPopup(); -``` - -### amCancellingPopups - -Set the automatic popup response to Cancel/Dismiss. -This must be set before a popup is triggered. - -```js -I.amCancellingPopups(); -I.click('#triggerPopup'); -I.cancelPopup(); -``` - -### amOnPage - -Opens a web page in a browser. Requires relative or absolute url. -If url starts with `/`, opens a web page of a site defined in `url` config parameter. - -```js -I.amOnPage('/'); // opens main page of website -I.amOnPage('https://github.com'); // opens github -I.amOnPage('/login'); // opens a login page -``` - -#### Parameters - -- `url` **[string][6]** url path or global url. - -Returns **void** automatically synchronized promise with recorder #! - -### appendField - -Appends text to a input field or textarea. -Field is located by name, label, CSS or XPath - -```js -I.appendField('#myTextField', 'appended'); -``` - -#### Parameters - -- `field` **([string][6] | [object][4])** located by label|name|CSS|XPath|strict locator -- `value` **[string][6]** text value to append. - ⚠️ returns a _promise_ which is synchronized internally by recorder - - -This action supports [React locators](https://codecept.io/react#locators) - - -### attachFile - -Attaches a file to element located by label, name, CSS or XPath -Path to file is relative current codecept directory (where codecept.conf.ts or codecept.conf.js is located). -File will be uploaded to remote system (if tests are running remotely). - -```js -I.attachFile('Avatar', 'data/avatar.jpg'); -I.attachFile('form input[name=avatar]', 'data/avatar.jpg'); -``` - -#### Parameters - -- `locator` **([string][6] | [object][4])** field located by label|name|CSS|XPath|strict locator. -- `pathToFile` **[string][6]** local file path relative to codecept.conf.ts or codecept.conf.js config file. - ⚠️ returns a _promise_ which is synchronized internally by recorder> ⚠ There is an [issue with file upload in Puppeteer 2.1.0 & 2.1.1][7], downgrade to 2.0.0 if you face it. - -### cancelPopup - -Dismisses the active JavaScript popup, as created by window.alert|window.confirm|window.prompt. - -### checkOption - -Selects a checkbox or radio button. -Element is located by label or name or CSS or XPath. - -The second parameter is a context (CSS or XPath locator) to narrow the search. - -```js -I.checkOption('#agree'); -I.checkOption('I Agree to Terms and Conditions'); -I.checkOption('agree', '//form'); -``` - -#### Parameters - -- `field` **([string][6] | [object][4])** checkbox located by label | name | CSS | XPath | strict locator. -- `context` **([string][6]? | [object][4])** (optional, `null` by default) element located by CSS | XPath | strict locator. - ⚠️ returns a _promise_ which is synchronized internally by recorder - -### clearCookie - -Clears a cookie by name, -if none provided clears all cookies. - -```js -I.clearCookie(); -I.clearCookie('test'); -``` - -#### Parameters - -- `name` -- `cookie` **[string][6]?** (optional, `null` by default) cookie name - ⚠️ returns a _promise_ which is synchronized internally by recorder - -### clearField - -Clears a `