nothing happens after .url() calling

2019-06-23 17:56发布

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

2条回答
趁早两清
2楼-- · 2019-06-23 18:46

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.
查看更多
Viruses.
3楼-- · 2019-06-23 18:56

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.

查看更多
登录 后发表回答