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.79k stars 1.31k forks source link

this.selector cannot be found with page object commands in Nightwatch 1.3.2 #2285

Closed Eriusik closed 4 years ago

Eriusik commented 4 years ago

I try to find selector of section on the Page with command this.waitForElementVisible(this.selector) It worked in Nightwatch 1.2.4 but after upgrade It looks like trying to find this.selector inside this.selector.

Running code

module.exports = {
    elements: {
    },
    sections: {
        addDevicesSection: {
            selector: "div[role='document']",
            elements: {...}
            commands: [
                {
                    waitForLoadDevice: function () {
                        this.waitForElementVisible(this.selector);
                }
           ]
     }
}

Verbose output

Request POST  /wd/hub/session/49d99403fb2370be30a8ed075a207efa/elements
   { using: 'css selector', value: "div[role='document']" }
Response 200 POST /wd/hub/session/49d99403fb2370be30a8ed075a207efa/elements (14ms)
{
     sessionId: '49d99403fb2370be30a8ed075a207efa',
     status: 0,
     value: [ { ELEMENT: '0.7704674834526781-3' } ]
}
Request POST  /wd/hub/session/49d99403fb2370be30a8ed075a207efa/element/0.7704674834526781-3/elements
   { using: 'css selector', value: "div[role='document']" }
   Response 200 POST /wd/hub/session/49d99403fb2370be30a8ed075a207efa/element/0.7704674834526781-3/elements (9ms)
   { sessionId: '49d99403fb2370be30a8ed075a207efa', status: 0, value: [] }
Request POST  /wd/hub/session/49d99403fb2370be30a8ed075a207efa/elements
   { using: 'css selector', value: "div[role='document']" }
Response 200 POST /wd/hub/session/49d99403fb2370be30a8ed075a207efa/elements (16ms)
   {
     sessionId: '49d99403fb2370be30a8ed075a207efa',
     status: 0,
     value: [ { ELEMENT: '0.7704674834526781-3' } ]
}
Request POST  /wd/hub/session/49d99403fb2370be30a8ed075a207efa/element/0.7704674834526781-3/elements
   { using: 'css selector', value: "div[role='document']" }
   Response 200 POST /wd/hub/session/49d99403fb2370be30a8ed075a207efa/element/0.7704674834526781-3/elements (13ms)
   { sessionId: '49d99403fb2370be30a8ed075a207efa', status: 0, value: [] }
   Request POST  /wd/hub/session/49d99403fb2370be30a8ed075a207efa/elements
   { using: 'css selector', value: "div[role='document']" }
   Response 200 POST /wd/hub/session/49d99403fb2370be30a8ed075a207efa/elements (15ms)
   {
     sessionId: '49d99403fb2370be30a8ed075a207efa',
     status: 0,
     value: [ { ELEMENT: '0.7704674834526781-3' } ]
}
   Request POST  /wd/hub/session/49d99403fb2370be30a8ed075a207efa/element/0.7704674834526781-3/elements
   { using: 'css selector', value: "div[role='document']" }
   Response 200 POST /wd/hub/session/49d99403fb2370be30a8ed075a207efa/element/0.7704674834526781-3/elements (13ms)
   { sessionId: '49d99403fb2370be30a8ed075a207efa', status: 0, value: [] }
   Request POST  /wd/hub/session/49d99403fb2370be30a8ed075a207efa/elements
   { using: 'css selector', value: "div[role='document']" }
   Response 200 POST /wd/hub/session/49d99403fb2370be30a8ed075a207efa/elements (21ms)
   {
     sessionId: '49d99403fb2370be30a8ed075a207efa',
     status: 0,
     value: [ { ELEMENT: '0.7704674834526781-3' } ]
}
   Request POST  /wd/hub/session/49d99403fb2370be30a8ed075a207efa/element/0.7704674834526781-3/elements
   { using: 'css selector', value: "div[role='document']" }
   Response 200 POST /wd/hub/session/49d99403fb2370be30a8ed075a207efa/element/0.7704674834526781-3/elements (9ms)
   { sessionId: '49d99403fb2370be30a8ed075a207efa', status: 0, value: [] }
✖ Timed out while waiting for element <Section [name=addDevicesSection],div[role='document']> to be present for 7000 milliseconds. - expected "visible" but got: "not found" (7476ms)

Environment:

Nightwatch 1.3.2 chromedriverVersion: 79.0.3945.36

lloiser commented 4 years ago

I have a feeling that the changes from https://github.com/nightwatchjs/nightwatch/issues/2219 broke this...

beatfactor commented 4 years ago

@Eriusik can you share your config and a sample test?

Eriusik commented 4 years ago
module.exports = {
    tags: ['device'],
    '@disabled': false,
    browserInstance: process.env.__NIGHTWATCH_ENV_KEY,
    'Open Devices page': function (browser) {
        const headerMenu = browser.page.WmsInterface.HeaderMenuPage();
        const devicesPage = browser.page.WmsInterface.DevicesPage();
        const addDevice = browser.page.WmsInterface.Modals.AddDevicePage().section.addDevicesSection;

        headerMenu.clickDevicesMenu();
        devicesPage.openAddDevices();
        addDevice.waitForLoadDevice();
    },
};

nightwatch.conf.js

const globalCfg = require('../config/config');
const path = require('path');

module.exports = {
    'src_folders' : ['tests/e2e/tests'],
    'output_folder' : false,
    'custom_commands_path' : [
        path.resolve('./tests/lib/custom/commands'),
        './node_modules/nightwatch-xhr/es5/commands',
        './tests/e2e/commands'
    ],
    'custom_assertions_path' : [
        path.resolve('./tests/lib/custom/assertions'),
        './node_modules/nightwatch-xhr/es5/assertions',
        './tests/e2e/assertions'
    ],
    'page_objects_path' : 'tests/e2e/pages/',
    'globals_path' : path.resolve('tests/e2e/globals.js'),
    'selenium' : {
        'start_process' : globalCfg.seleniumSettings.startProcess,
        'server_path' : 'tests/utils/selenium-server-standalone-3.141.59.jar',
        'log_path' : '',
        'port' : globalCfg.seleniumSettings.port,
        'cli_args' : {
            'webdriver.chrome.driver' : 'tests/utils/chromedriver',
            'webdriver.gecko.driver' : 'tests/utils/geckodriver',
        }
    },
    'live_output' : true,
    'disable_colors' : false,
    'test_settings' : {
        'default' : {
            'launch_url' : globalCfg.launchEnvironment.pbx.url,
            'selenium_port'  : globalCfg.seleniumSettings.port,
            'selenium_host'  : globalCfg.seleniumSettings.host,
            'username': globalCfg.seleniumSettings.user,
            'access_key': globalCfg.seleniumSettings.pass,
            'silent': true,
            'screenshots' : {
                'enabled' : true,
                'on_failure' : true,
                'on_error' : true,
                'path' : 'tests/reports/e2e/screenshots'
            },
            'desiredCapabilities': {
                'marionette': true,
                'enableVNC': true,
            }
        },
        'chrome_col': {
            'desiredCapabilities': {
                'browserName': 'chrome',
                'version': globalCfg.chromeVersion,
                'acceptInsecureCerts': true,
                'enableVideo': true,
                'videoFrameRate': 24,
                'chromeOptions': {
                    w3c:false,
                    'args': [
                        'use-fake-ui-for-media-stream',
                        'use-fake-device-for-media-stream',
                        'load-extension=/opt/test_data/wildix-interceptor',
                        'disable-notifications',
                        'window-size=1280,800',
                        //'auto-open-devtools-for-tabs',
                    ],
                    'prefs': {
                        'download.default_directory': globalCfg.downloadPath,
                        'download.prompt_for_download': false
                    }
                },
                'loggingPrefs': {
                    'driver': 'INFO', 'server': 'INFO', 'browser': 'INFO', 'performance': 'INFO'
                }
            }
        }
    }
};
beatfactor commented 4 years ago

@Eriusik have you tried with removing chromeOptions.w3c : false? I think it's because Chrome is not using JsonWire anymore since 78 or 79. You can also try with the nightwatch generated config in v1.3. You can rename your current config file, since Nightwatch doesn't create it if one already exists.

Eriusik commented 4 years ago

It is checked with nightwatch generated config (without w3c:false). The problem is still present. Timed out while waiting for element <Section [name=addDevicesSection],div[role='document']> to be present for 7000 milliseconds. - expected "visible" but got: "not found" (7480ms)

Eriusik commented 4 years ago

@beatfactor We are waiting for it. Will this be done in version 1.3?

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had any recent activity. If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.

Eriusik commented 4 years ago

This is still not fixed in the latest version.

Pieras2 commented 4 years ago

Can anyone reopen the issue? this.api.elements doesn't work in sections (NW v1.3.4)

srathibandlarp commented 4 years ago

@beatfactor this is still not working on 1.4.3 I am using browser.elements as follows and I got the below error (below my code)

'Validate right rail recommended listings': browser => {
const pdp = browser.page.large.pdp()
    pdp.elements('xpath', '@firstRightRailRecommendation', result => {
      // If no element found it will be -1
      if (result.status !== -1) {
        pdp.expect.element('@firstRightRailRecommendationCTA').to.be.present
      }
    })
}

ERROR log:

TEST FAILURE: 1 error during execution; 0 assertions failed, 16 passed (25.159s)

 ✖ large/pdp/isBasic/isInactiveMain
 – Validate right rail recommended listings (237ms)

  TypeError: pdp.elements is not a function
   - writing an ES6 async test case? - keep in mind that commands return a Promise; 
   - writing unit tests? - make sure to specify "unit_tests_mode=true" in your config.
       at Object.Validate right rail recommended listings (/Users/srathibandla/workspace/ag.js/tests/large/pdp/isBasic/isInactiveMain.js:50:9)
       at processTicksAndRejections (internal/process/task_queues.js:93:5)
beatfactor commented 3 years ago

@srathibandlarp if you're selecting the element using the '@' identifier, then you need to remove the first argument, as in: pdp.api.elements('@firstRightRailRecommendation') and NOT pdp.elements('xpath', '@firstRightRailRecommendation').

srathibandlarp commented 3 years ago

@beatfactor I get the same result after removing that xpath also, I should've mentioned that already. But here is the code and error:

 'Validate right rail recommended listings': browser => {
    const pdp = browser.page.large.pdp()
    pdp.elements('@firstRightRailRecommendation', result => {
      if (result.status !== -1) {
        pdp.expect.element('@firstRightRailRecommendation').to.be.present
        pdp.expect.element('@firstRightRailRecommendationCTA').to.be.present
      }
    })
  }

Error:

TEST FAILURE: 1 error during execution; 0 assertions failed, 16 passed (51.198s)

 ✖ large/pdp/isBasic/isInactiveMain
 – Validate right rail recommended listings (206ms)

  TypeError: pdp.elements is not a function
   - writing an ES6 async test case? - keep in mind that commands return a Promise; 
   - writing unit tests? - make sure to specify "unit_tests_mode=true" in your config.
       at Object.Validate right rail recommended listings (/Users/srathibandla/workspace/ag.js/tests/large/pdp/isBasic/isInactiveMain.js:50:9)
       at processTicksAndRejections (internal/process/task_queues.js:93:5)
beatfactor commented 3 years ago

@srathibandlarp use pdp.api.elements

srathibandlarp commented 3 years ago

@beatfactor - adding .api worked. Thanks a lot!