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

Async Unit Test Callback issue #437

Closed jsajnani79 closed 9 years ago

jsajnani79 commented 9 years ago

Can you clarify how to inform nightwatch that a unit test is complete? I have a chain of promises, and would like to add a callback to the last async call before nightwatch moves on to my next unit test.

I've seen the below on the documentation online, but could use clarification. How is the done callback defined? I've inserted exactly the below into my tests without success.

module.exports = { 'demo UnitTest' : function (client, done) { client.assert.ok('TEST');

setTimeout(function() {
  done();
}, 500);

} };

beatfactor commented 9 years ago

What is the output?

On Thursday, May 7, 2015, Jai Sajnani notifications@github.com wrote:

Can you clarify how to inform nightwatch that a unit test is complete? I have a chain of promises, and would like to add a callback to the last async call before nightwatch moves on to my next unit test.

I've seen the below on the documentation online, but could use clarification. How is the done callback defined? I've inserted exactly the below into my tests without success.

module.exports = { 'demo UnitTest' : function (client, done) { client.assert.ok('TEST');

setTimeout(function() { done(); }, 500);

} };

— Reply to this email directly or view it on GitHub https://github.com/beatfactor/nightwatch/issues/437.

jsajnani79 commented 9 years ago

errors because demo() is an undefined function.

On Wed, May 6, 2015 at 10:38 PM, Andrei Rusu notifications@github.com wrote:

What is the output?

On Thursday, May 7, 2015, Jai Sajnani notifications@github.com wrote:

Can you clarify how to inform nightwatch that a unit test is complete? I have a chain of promises, and would like to add a callback to the last async call before nightwatch moves on to my next unit test.

I've seen the below on the documentation online, but could use clarification. How is the done callback defined? I've inserted exactly the below into my tests without success.

module.exports = { 'demo UnitTest' : function (client, done) { client.assert.ok('TEST');

setTimeout(function() { done(); }, 500);

} };

— Reply to this email directly or view it on GitHub https://github.com/beatfactor/nightwatch/issues/437.

— Reply to this email directly or view it on GitHub https://github.com/beatfactor/nightwatch/issues/437#issuecomment-99727252 .

Jai Sajnani M.S. Candidate in Electrical Engineering and Computer Science Stanford University Class of 2016 Email jsajnani79@gmail.com | LinkedIn https://www.linkedin.com/pub/jai-sajnani/3b/180/402 | Twitter http://www.twitter.com/jaisajnani (516) 808-9183 (C)

beatfactor commented 9 years ago

Did you set start_session to false?

On Thursday, May 7, 2015, Jai Sajnani notifications@github.com wrote:

errors because demo() is an undefined function.

On Wed, May 6, 2015 at 10:38 PM, Andrei Rusu <notifications@github.com javascript:_e(%7B%7D,'cvml','notifications@github.com');> wrote:

What is the output?

On Thursday, May 7, 2015, Jai Sajnani <notifications@github.com javascript:_e(%7B%7D,'cvml','notifications@github.com');> wrote:

Can you clarify how to inform nightwatch that a unit test is complete? I have a chain of promises, and would like to add a callback to the last async call before nightwatch moves on to my next unit test.

I've seen the below on the documentation online, but could use clarification. How is the done callback defined? I've inserted exactly the below into my tests without success.

module.exports = { 'demo UnitTest' : function (client, done) { client.assert.ok('TEST');

setTimeout(function() { done(); }, 500);

} };

— Reply to this email directly or view it on GitHub https://github.com/beatfactor/nightwatch/issues/437.

— Reply to this email directly or view it on GitHub < https://github.com/beatfactor/nightwatch/issues/437#issuecomment-99727252> .

Jai Sajnani M.S. Candidate in Electrical Engineering and Computer Science Stanford University Class of 2016 Email <jsajnani79@gmail.com javascript:_e(%7B%7D,'cvml','jsajnani79@gmail.com');> | LinkedIn https://www.linkedin.com/pub/jai-sajnani/3b/180/402 | Twitter http://www.twitter.com/jaisajnani (516) 808-9183 (C)

— Reply to this email directly or view it on GitHub https://github.com/beatfactor/nightwatch/issues/437#issuecomment-99727383 .

jsajnani79 commented 9 years ago

yes, my nightwatch.json and test file are as below:

nightwatch.json:

{ "src_folders" : ["tests"], "output_folder" : "reports", "custom_commands_path" : "commands", "custom_assertions_path" : "", "page_objects_path" : "page_objects", "globals_path" : "",

"selenium" : { "start_process" : true, "server_path" : "node_modules/selenium-standalone/.selenium/selenium-server/2.45.0-server.jar", "log_path" : "reports/logs", "host" : "127.0.0.1", "port" : 4444, "cli_args" : { "webdriver.chrome.driver" : "../../../../build/test/bin/chromedriver.exe" } },

"test_settings" : { "default" : { "launch_url" : "http://localhost", "selenium_port" : 4444, "selenium_host" : "localhost", "silent": true, "screenshots" : { "enabled" : false, "path" : "" }, "desiredCapabilities": { "browserName": "chrome", "javascriptEnabled": true, "acceptSslCerts": true }, "exclude": "tests/unittests/*" },

"unittests" : {
  "selenium" : {
    "start_process" : false,
    "start_session" : false
  },
  "filter" : "tests/unittests/*",
  "exclude" : ""
}

} }

tests/unittests/unit.js

module.exports = { 'demo UnitTest' : function (client, done) { client.assert.ok('TEST');

setTimeout(function() {
  done();
}, 500);

} };

beatfactor commented 9 years ago

And you are specifying --env unittests when running?

jsajnani79 commented 9 years ago

I was not - assuming these would start as soon as the e2e tests completed, thank you.

I am using Node Webkit, and my main issue is with async commands. I have a promise chain that helps a user login (get login window, then input credentials, then switch back to first window), and must complete before my tests start. However, I have not found a better way than using browser.pause() statements to ensure completion. I tried using the async Before() command, but my webkit instance will not start until the first test function and no browser.X commands will run in the before hook (sync or async).

Do you know of any better ways to solve this? Apologies for posting here, I will try the mailing list as well.

On Thu, May 7, 2015 at 10:54 AM, Andrei Rusu notifications@github.com wrote:

And you are specifying --env unittests when running?

— Reply to this email directly or view it on GitHub https://github.com/beatfactor/nightwatch/issues/437#issuecomment-99960228 .

Jai Sajnani M.S. Candidate in Electrical Engineering and Computer Science Stanford University Class of 2016 Email jsajnani79@gmail.com | LinkedIn https://www.linkedin.com/pub/jai-sajnani/3b/180/402 | Twitter http://www.twitter.com/jaisajnani (516) 808-9183 (C)

beatfactor commented 9 years ago

Not really, that's normal behavior I would say. Maybe you can open another issue with more details about your issue and the desired change in behavior?