nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.78k stars 1.31k forks source link

[2.0.8] It worked with 2.0.7, it doesn't work anymore #3077

Closed alv131 closed 2 years ago

alv131 commented 2 years ago

Hi. The following piece of code worked with 2.0.7 but doesn't work anymore

let loginForm = {
    loginAsSystemUser({ globals }) {
        return this.navigate()
            .waitForElementPresent('@username', 20000)
            .waitForElementVisible('@username', 20000)
            .setValue('@username', globals.systemUsername)
            .setValue('@password', globals.password)
            .click('@submit');
    }
};
module.exports = {
    url: function() {
        return `https://prefix-${this.api.globals.site}.website.com`;
    },
    elements: {
        body: 'body',
        username: 'input[name="username"]',
        password: 'input[name="password"]',
        submit: 'button[name="submit"]'
    },
    commands: [loginForm]
};

The error:

✖ Error while running "url" command: [TypeError] Cannot read properties of undefined (reading 'globals')
TypeError: Error while running "url" command: [TypeError] Cannot read properties of undefined (reading 'globals')
    at Object.url (/home/gitlab-runner/builds/hTy-dxNX/xxx/tests_release/ver/e2e/page_objects/website/loginForm.js:13:42) // line that starts with "return" in "url"
    at /home/gitlab-runner/builds/hTy-dxNX/xxx/tests_release/ver/node_modules/nightwatch/lib/api/protocol/url.js:50:25
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
beatfactor commented 2 years ago

what is the context? can you provide a sample test on how is this being used?

alv131 commented 2 years ago

s4yh5.zip Here's a sample that you can use.

beatfactor commented 2 years ago

We have a process for submitting bug reports. Can you please follow this template?

alv131 commented 2 years ago

Describe the bug

Existing code that works with Nightwatch-2.0.7 doesn't work anymore with Nightwatch-2.0.8 (the latest version at the moment). The only change done to the existing code was just the Nightwatch's version.

Sample test

e2e/globals.js

```js module.exports = { get site() { return "https://slashdot.org"; } } ```

e2e/page_objects/helper.js

```js let loginForm = { openUrl({ globals }) { return this.navigate().waitForElementVisible('body', 2000); } }; module.exports = { url: function () { return this.api.globals.site; // Works with 2.0.7, doesn't work with 2.0.8 }, commands: [loginForm] }; ```

e2e/tests/homepage.js

```js module.exports = { before: browser => { console.log('--->'); }, after: browser => { console.log('<---'); }, 'Demo test /.': async function (browser) { browser.page.helper() .openUrl(browser) .assert.title('Slashdot: News for nerds, stuff that matters') .waitForElementVisible({ locateStrategy: 'xpath', selector: '//span[normalize-space(text())="I ACCEPT"]' }, 1000) .click('a.cmpboxbtnyes') .pause(1000) .end(); } } ```

Run with command

$ ./node_modules/nightwatch/bin/nightwatch --verbose --test e2e/tests/homepage.js

Verbose output

debug.log

```txt [Homepage] Test Suite ────────────────────────────────────────── ⠋ Starting ChromeDriver on port 9515... Starting ChromeDriver with server_path=/home/nelu/tmp/s4yh5/node_modules/chromedriver/lib/chromedriver/chromedriver... Request POST /session { desiredCapabilities: { browserName: 'chrome', name: 'Homepage', 'goog:chromeOptions': {} }, capabilities: { alwaysMatch: { browserName: 'chrome', 'goog:chromeOptions': {} } } ⠹ Starting ChromeDriver on port 9515... Response 200 POST /session (938ms) { value: { capabilities: { acceptInsecureCerts: false, browserName: 'chrome', browserVersion: '98.0.4758.102', chrome: { chromedriverVersion: '98.0.4758.102 (273bf7ac8c909cde36982d27f66f3c70846a3718-refs/branch-heads/4758@{#1151})', userDataDir: '/tmp/.com.google.Chrome.cPcPIv' }, 'goog:chromeOptions': { debuggerAddress: 'localhost:38221' }, networkConnectionEnabled: false, pageLoadStrategy: 'normal', platformName: 'linux', proxy: {}, setWindowRect: true, strictFileInteractability: false, timeouts: { implicit: 0, pageLoad: 300000, script: 30000 }, unhandledPromptBehavior: 'dismiss and notify', 'webauthn:extension:credBlob': true, 'webauthn:extension:largeBlob': true, 'webauthn:virtualAuthenticators': true }, sessionId: 'eaad8585f682209fdaf358789e284595' } ℹ Connected to ChromeDriver on port 9515 (988ms). Using: chrome (98.0.4758.102) on LINUX. Received session with ID: eaad8585f682209fdaf358789e284595 → Running [before]: ---> → Completed [before]. Running Demo test /.: ─────────────────────────────────────────────────────────────────────────────────────────────────── → Running [beforeEach]: → Completed [beforeEach]. → Running [afterEach]: → Running command: url ('https://slashdot.org', [Function]) ⠋ Loading url: https://slashdot.org Request POST /session/eaad8585f682209fdaf358789e284595/url ⠦ Loading url: https://slashdot.org Response 200 POST /session/eaad8585f682209fdaf358789e284595/url (2956ms) ℹ Loaded url https://slashdot.org in 2959ms → Completed command: url ('https://slashdot.org', [Function]) (2961ms) ✖ Error while running "url" command: [TypeError] Cannot read properties of undefined (reading 'globals') TypeError: Error while running "url" command: [TypeError] Cannot read properties of undefined (reading 'globals') at Object.url (/home/nelu/tmp/s4yh5/e2e/page_objects/helper.js:8:25) at /home/nelu/tmp/s4yh5/node_modules/nightwatch/lib/api/protocol/url.js:50:25 at processTicksAndRejections (node:internal/process/task_queues:96:5) → Completed [afterEach]. FAILED: 1 assertions failed (3.009s) → Running [after]: <--- → Completed [after]. → Running command: end () → Running command: session ('delete', [Function]) Request DELETE /session/eaad8585f682209fdaf358789e284595 Response 200 DELETE /session/eaad8585f682209fdaf358789e284595 (53ms) { value: null } → Completed command: session ('delete', [Function]) (56ms) Wrote log file to: /home/nelu/tmp/s4yh5/logs/homepage_chromedriver.log. → Completed command: end () (63ms) ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── TEST FAILURE (4.22s): - 1 assertions failed; 0 passed ✖ 1) homepage – Demo test /. (3.009s) Error while running "url" command: [TypeError] Cannot read properties of undefined (reading 'globals') TypeError: Error while running "url" command: [TypeError] Cannot read properties of undefined (reading 'globals') at Object.url (/home/nelu/tmp/s4yh5/e2e/page_objects/helper.js:8:25) at processTicksAndRejections (node:internal/process/task_queues:96:5) ChromeDriver process closed. Wrote report file to: reports/CHROME_98.0.4758.102__homepage.xml. ```

Configuration

nightwatch.json

```js module.exports = { "src_folders": ["tests"], "output_folder": "reports", "globals_path": "e2e/globals", "page_objects_path": "e2e/page_objects", "selenium": { "start_process": false, }, "test_settings": { "default": { "selenium_port": 9515, "selenium_host": "localhost", "default_path_prefix": "", "desiredCapabilities": { "browserName": "chrome" }, webdriver: { start_process: true, server_path: '' } }, chrome: { desiredCapabilities: { browserName: 'chrome', 'goog:chromeOptions': { // More info on Chromedriver: https://sites.google.com/a/chromium.org/chromedriver/ // // w3c:false tells Chromedriver to run using the legacy JSONWire protocol (not required in Chrome 78) w3c: true, args: [ //'--no-sandbox', //'--ignore-certificate-errors', //'--allow-insecure-localhost', //'--headless' ] } }, webdriver: { start_process: true, server_path: '', cli_args: [ // --verbose ] } } } } ```

Your Environment

Executable Version
nightwatch --version 2.0.8
npm --version 8.3.1
yarn --version 1.22.17
node --version v16.14.0
Browser driver Version
chromedriver 98.0.1
OS Version
Ubuntu 20.04.4 LTS