From 0a829413b022d6a1b7cbf34705f574178acb6ce4 Mon Sep 17 00:00:00 2001 From: kobenguyent <7845001+kobenguyent@users.noreply.github.com> Date: Fri, 3 Jan 2025 06:59:18 +0100 Subject: [PATCH] fix: error thrown when element text is an empty string (#4702) --- bin/codecept.js | 4 +- docs/helpers/Nightmare.md | 536 ++-- docs/helpers/Playwright.md | 1196 +++++---- docs/helpers/Protractor.md | 730 +++--- docs/helpers/Puppeteer.md | 1085 ++++----- docs/helpers/TestCafe.md | 514 ++-- docs/helpers/WebDriver.md | 965 ++++---- lib/assert/empty.js | 8 +- lib/assert/equal.js | 11 +- lib/assert/include.js | 10 +- lib/assert/throws.js | 6 +- lib/assert/truth.js | 4 +- lib/command/configMigrate.js | 6 +- lib/command/definitions.js | 30 +- lib/command/generate.js | 24 +- lib/command/info.js | 4 +- lib/command/init.js | 20 +- lib/command/interactive.js | 2 +- lib/command/list.js | 2 +- lib/command/run-multiple.js | 47 +- lib/command/run-workers.js | 20 +- lib/command/utils.js | 11 +- lib/data/context.js | 23 +- lib/data/dataScenarioConfig.js | 16 +- lib/data/dataTableArgument.js | 12 +- lib/data/table.js | 16 +- lib/helper/ApiDataFactory.js | 9 +- lib/helper/Appium.js | 45 +- lib/helper/FileSystem.js | 6 +- lib/helper/GraphQLDataFactory.js | 6 +- lib/helper/JSONResponse.js | 124 +- lib/helper/Nightmare.js | 88 +- lib/helper/Playwright.js | 318 +-- lib/helper/Protractor.js | 131 +- lib/helper/Puppeteer.js | 353 +-- lib/helper/REST.js | 22 +- lib/helper/TestCafe.js | 62 +- lib/helper/WebDriver.js | 230 +- lib/interfaces/bdd.js | 6 +- lib/interfaces/gherkin.js | 29 +- lib/interfaces/inject.js | 26 +- lib/interfaces/scenarioConfig.js | 2 +- lib/listener/artifacts.js | 4 +- lib/listener/exit.js | 8 +- lib/listener/helpers.js | 30 +- lib/listener/mocha.js | 2 +- lib/listener/retry.js | 10 +- lib/listener/steps.js | 18 +- lib/listener/timeout.js | 16 +- lib/plugin/autoDelay.js | 8 +- lib/plugin/autoLogin.js | 13 +- lib/plugin/commentStep.js | 2 +- lib/plugin/coverage.js | 29 +- lib/plugin/customLocator.js | 6 +- lib/plugin/debugErrors.js | 4 +- lib/plugin/eachElement.js | 2 +- lib/plugin/fakerTransform.js | 2 +- lib/plugin/heal.js | 15 +- lib/plugin/retryFailedStep.js | 8 +- lib/plugin/retryTo.js | 4 +- lib/plugin/screenshotOnFail.js | 45 +- lib/plugin/selenoid.js | 50 +- lib/plugin/stepByStepReport.js | 21 +- lib/plugin/stepTimeout.js | 15 +- lib/plugin/subtitles.js | 8 +- lib/plugin/tryTo.js | 2 +- lib/plugin/wdio.js | 18 +- lib/template/heal.js | 13 +- prettier.config.js | 4 +- runok.js | 138 +- .../codecept.Playwright.coverage.js | 4 +- test/acceptance/codecept.Playwright.js | 4 +- .../acceptance/codecept.Playwright.retryTo.js | 4 +- test/acceptance/codecept.Puppeteer.js | 4 +- test/acceptance/codecept.Testcafe.js | 4 +- test/acceptance/codecept.WebDriver.js | 6 +- test/acceptance/config_test.js | 4 +- test/acceptance/retryTo_test.js | 8 +- test/acceptance/session_test.js | 10 +- test/acceptance/within_test.js | 46 +- test/data/app/view/info.php | 9 +- test/graphql/GraphQLDataFactory_test.js | 12 +- test/graphql/GraphQL_test.js | 4 +- test/helper/AppiumV2_ios_test.js | 217 +- test/helper/AppiumV2_test.js | 782 +++--- test/helper/Appium_test.js | 786 +++--- test/helper/JSONResponse_test.js | 180 +- test/helper/Playwright_test.js | 1515 ++++++------ test/helper/Puppeteer_test.js | 1138 ++++----- test/helper/TestCafe_test.js | 2 +- .../helper/WebDriver.noSeleniumServer_test.js | 1452 +++++------ test/helper/WebDriver_test.js | 1472 +++++------ test/helper/webapi.js | 2150 +++++++++-------- test/plugin/plugin_test.js | 34 +- test/rest/ApiDataFactory_test.js | 12 +- test/rest/REST_test.js | 6 +- test/runner/bdd_test.js | 149 +- test/runner/before_failure_test.js | 6 +- test/runner/bootstrap_test.js | 28 +- test/runner/codecept_test.js | 71 +- test/runner/comment_step_test.js | 7 +- test/runner/definitions_test.js | 46 +- test/runner/dry_run_test.js | 262 +- test/runner/gherkin_test.js | 12 +- test/runner/help_test.js | 6 +- test/runner/init_test.js | 10 +- test/runner/interface_test.js | 32 +- test/runner/list_test.js | 2 +- test/runner/pageobject_test.js | 190 +- test/runner/retry_hooks_test.js | 17 +- test/runner/run_multiple_test.js | 376 +-- test/runner/run_rerun_test.js | 128 +- test/runner/run_workers_test.js | 2 +- test/runner/scenario_stale_test.js | 4 +- test/runner/session_test.js | 31 +- test/runner/skip_test.js | 4 +- test/runner/step_timeout_test.js | 15 +- test/runner/timeout_test.js | 21 +- test/runner/todo_test.js | 6 +- test/runner/translation_test.js | 4 +- test/runner/within_test.js | 34 +- test/support/setup.js | 2 +- test/unit/actor_test.js | 182 +- test/unit/ai_test.js | 2 +- test/unit/assert_test.js | 2 +- test/unit/bdd_test.js | 452 ++-- test/unit/config_test.js | 6 +- test/unit/container_test.js | 306 +-- test/unit/heal_test.js | 4 +- test/unit/html_test.js | 19 +- test/unit/locator_test.js | 2 +- test/unit/output_test.js | 2 +- test/unit/parser_test.js | 18 +- test/unit/recorder_test.js | 10 +- test/unit/scenario_test.js | 2 +- test/unit/steps_test.js | 12 +- test/unit/ui_test.js | 4 +- test/unit/utils_test.js | 24 +- test/unit/worker_test.js | 220 +- 139 files changed, 9445 insertions(+), 10406 deletions(-) diff --git a/bin/codecept.js b/bin/codecept.js index 9a0ff7db0..06b116e65 100755 --- a/bin/codecept.js +++ b/bin/codecept.js @@ -32,7 +32,7 @@ const commandFlags = { } const errorHandler = - (fn) => + fn => async (...args) => { try { await fn(...args) @@ -286,7 +286,7 @@ program .action(require('../lib/command/run-rerun')) -program.on('command:*', (cmd) => { +program.on('command:*', cmd => { console.log(`\nUnknown command ${cmd}\n`) program.outputHelp() }) diff --git a/docs/helpers/Nightmare.md b/docs/helpers/Nightmare.md index 12727861e..43f6d013f 100644 --- a/docs/helpers/Nightmare.md +++ b/docs/helpers/Nightmare.md @@ -22,28 +22,28 @@ Requires `nightmare` package to be installed. This helper should be configured in codecept.conf.ts or codecept.conf.js -* `url` - base url of website to be tested -* `restart` - restart browser between tests. -* `disableScreenshots` - don't save screenshot on failure. -* `uniqueScreenshotNames` - option to prevent screenshot override if you have scenarios with the same name in different suites. -* `fullPageScreenshots` - make full page screenshots on failure. -* `keepBrowserState` - keep browser state between tests when `restart` set to false. -* `keepCookies` - keep cookies between tests when `restart` set to false. -* `waitForAction`: (optional) how long to wait after click, doubleClick or PressKey actions in ms. Default: 500. -* `waitForTimeout`: (optional) default wait* timeout in ms. Default: 1000. -* `windowSize`: (optional) default window size. Set a dimension like `640x480`. +- `url` - base url of website to be tested +- `restart` - restart browser between tests. +- `disableScreenshots` - don't save screenshot on failure. +- `uniqueScreenshotNames` - option to prevent screenshot override if you have scenarios with the same name in different suites. +- `fullPageScreenshots` - make full page screenshots on failure. +- `keepBrowserState` - keep browser state between tests when `restart` set to false. +- `keepCookies` - keep cookies between tests when `restart` set to false. +- `waitForAction`: (optional) how long to wait after click, doubleClick or PressKey actions in ms. Default: 500. +- `waitForTimeout`: (optional) default wait\* timeout in ms. Default: 1000. +- `windowSize`: (optional) default window size. Set a dimension like `640x480`. -* options from [Nightmare configuration][2] +- options from [Nightmare configuration][2] ## Methods ### Parameters -* `config` +- `config` -### _locate +### \_locate Locate elements by different locator types, including strict locator. Should be used in custom helpers. @@ -55,17 +55,17 @@ client-side function: ```js // get an inner text of an element -let browser = this.helpers['Nightmare'].browser; -let value = this.helpers['Nightmare']._locate({name: 'password'}).then(function(els) { - return browser.evaluate(function(el) { - return codeceptjs.fetchElement(el).value; - }, els[0]); -}); +let browser = this.helpers['Nightmare'].browser +let value = this.helpers['Nightmare']._locate({ name: 'password' }).then(function (els) { + return browser.evaluate(function (el) { + return codeceptjs.fetchElement(el).value + }, els[0]) +}) ``` #### Parameters -* `locator` +- `locator` ### amOnPage @@ -73,15 +73,15 @@ 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 +I.amOnPage('/') // opens main page of website +I.amOnPage('https://github.com') // opens github +I.amOnPage('/login') // opens a login page ``` #### Parameters -* `url` **[string][3]** url path or global url. -* `headers` **[object][4]?** list of request headers can be passed +- `url` **[string][3]** url path or global url. +- `headers` **[object][4]?** list of request headers can be passed Returns **void** automatically synchronized promise through #recorder @@ -91,15 +91,15 @@ Appends text to a input field or textarea. Field is located by name, label, CSS or XPath ```js -I.appendField('#myTextField', 'appended'); +I.appendField('#myTextField', 'appended') // typing secret -I.appendField('password', secret('123456')); +I.appendField('password', secret('123456')) ``` #### Parameters -* `field` **([string][3] | [object][4])** located by label|name|CSS|XPath|strict locator -* `value` **[string][3]** text value to append. +- `field` **([string][3] | [object][4])** located by label|name|CSS|XPath|strict locator +- `value` **[string][3]** text value to append. Returns **void** automatically synchronized promise through #recorder @@ -110,14 +110,14 @@ Path to file is relative current codecept directory (where codecept.conf.ts or c 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'); +I.attachFile('Avatar', 'data/avatar.jpg') +I.attachFile('form input[name=avatar]', 'data/avatar.jpg') ``` #### Parameters -* `locator` **([string][3] | [object][4])** field located by label|name|CSS|XPath|strict locator. -* `pathToFile` **[string][3]** local file path relative to codecept.conf.ts or codecept.conf.js config file. +- `locator` **([string][3] | [object][4])** field located by label|name|CSS|XPath|strict locator. +- `pathToFile` **[string][3]** local file path relative to codecept.conf.ts or codecept.conf.js config file. Returns **void** automatically synchronized promise through #recorderDoesn't work if the Chromium DevTools panel is open (as Chromium allows only one attachment to the debugger at a time. [See more][5]) @@ -129,15 +129,15 @@ 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'); +I.checkOption('#agree') +I.checkOption('I Agree to Terms and Conditions') +I.checkOption('agree', '//form') ``` #### Parameters -* `field` **([string][3] | [object][4])** checkbox located by label | name | CSS | XPath | strict locator. -* `context` **([string][3]? | [object][4])** (optional, `null` by default) element located by CSS | XPath | strict locator. +- `field` **([string][3] | [object][4])** checkbox located by label | name | CSS | XPath | strict locator. +- `context` **([string][3]? | [object][4])** (optional, `null` by default) element located by CSS | XPath | strict locator. Returns **void** automatically synchronized promise through #recorder @@ -147,28 +147,28 @@ Clears a cookie by name, if none provided clears all cookies. ```js -I.clearCookie(); -I.clearCookie('test'); +I.clearCookie() +I.clearCookie('test') ``` #### Parameters -* `cookie` **[string][3]?** (optional, `null` by default) cookie name +- `cookie` **[string][3]?** (optional, `null` by default) cookie name ### clearField Clears a `