nothing happens after .url() calling

跟風遠走 提交于 2019-12-10 15:19:23

问题


I have the following nightwatch test:

module.exports = {

    'Set Initial Dataset' : function (browser) {

        browser
          .url('http://localhost/nightwatch/load-initial-dataset')
          .end()

    }

}

When I execute it the browser is opened and the url is loaded, but when the loading is ended it doesn't close the browser to begin the next test.

The test worked 1 month ago... I updated nightwatch to the nigthwatch latest version (v0.9.8), downloaded selenium-server-standalone-3.0.1.jar, chromedriver 2.25 and Chrome 54.0.2840.87

My Nigthwatch.js is

module.exports = {

src_folders: ['./tests'],
output_folder: './results',

selenium: {

    start_process: true,
    server_path: './selenium-server-standalone-3.0.1.jar',
    log_path: './results',
    host: '127.0.0.1',
    port: 4444,
    "cli_args" : {
        "webdriver.chrome.driver" : "./osx/chromedriver"
    }

},

test_settings: {

    default: {

        waitForConditionPollInterval: 1,
        selenium_host: '127.0.0.1',
        selenium_port: 4444,
        screenshots: {

            enabled: true,
            path: './results/screenshots'

        },
        desiredCapabilities: {

            browserName: 'chrome',
            javascriptEnabled: true,
            acceptSslCerts: true

        }

    }

}

};

I tried to launch this test and I have the same problem: https://github.com/nightwatchjs/nightwatch/blob/master/examples/tests/google.js (the browser stay opened at the url and nothing from the terminal)

I have no particular problem when I ran my test with safari.

Thx


回答1:


From a first glance it looks like your test doesn't actually perform any assertions and thus doesn't actually 'test' for anything. This might be confusing the test runner.

My other theory is that the waitForConditionPollInterval setting is too low. 1 millisecond seems a bit overkill.

Two things to do from here:

  1. Perform an actual assertion inside your test. For example, after navigating to the page try this...

Example:

module.exports = {
    'Set Initial Dataset' : function (browser) {
    browser
       .url('http://localhost/nightwatch/load-initial-dataset')
       .assert.title('Some Title')
       .end()
    }
}
  1. Remove the waitForConditionPollInterval setting and see if that helps. If it does, try setting it to something a little more sane, like 100ms, and check if the test still hangs.



回答2:


My experience has been that selenium hangs when a verification isn't performed. You're not getting any output because navigating isn't a "verification" step.

While you can check for the page title to confirm that you've hit the correct url, I would consider that a bit brittle. If the page title changes for any reason it would fail your test, even if the URL you navigated to was correct. To test that you're hitting the correct url, try using .urlContains(); instead.

Example:

module.exports = {

    'Set Initial Dataset' : function (browser) {

        browser
          .url('http://localhost/nightwatch/load-initial-dataset')
          .verify.urlContains('/load-initial-dataset')
          .end();

    }

}

You're also missing the semi-colon after .end(); which might not be telling nightwatch the test case is actually complete.

Maybe try that, too.



来源:https://stackoverflow.com/questions/40392128/nothing-happens-after-url-calling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!