Initializing test environment with nightwatch

936 views
Skip to first unread message

Riku Rouvila

unread,
Mar 18, 2014, 5:44:43 AM3/18/14
to nightw...@googlegroups.com
Is it somehow possible to initialize the test environment with nightwatch before running tests? Also closing it after tests would be necessary. 

This feature seems so basic that I'm having a hard time to understand whether there's no such feature in nightwatch or I'm I just missing something.
Is there a way to run asynchronous tasks in setUp and tearDown methods? 

My use case is basically just that I want to run my server, drop database and create fixture data before tests are run and close the server when nightwatch is finished with the tests. Can you give me an example how this is done?

Andrei Rusu

unread,
Mar 18, 2014, 6:20:33 AM3/18/14
to nightw...@googlegroups.com
Currently setUp/tearDown are synchronous but you can create an async fixture as a custom command. More about this here: http://nightwatchjs.org/guide#custom-commands.

You can get an idea of how your command should look like by checking the pause command which is fairly simple:

Remember to emit a 'complete' event when your async stuff is finished (as seen in the pause command).

Here's a more complex example:

It is a custom assertion, but custom commands are declared similarly. 

Riku Rouvila

unread,
Mar 18, 2014, 6:27:58 AM3/18/14
to nightw...@googlegroups.com
Thanks! Ill try that and hopefully it will help me to implement my tests. 

Andrei Rusu

unread,
Mar 18, 2014, 6:30:03 AM3/18/14
to Riku Rouvila, nightw...@googlegroups.com
No problem, let me know if you have any more questions.
> --
> You received this message because you are subscribed to the Google Groups
> "NightwatchJs" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nightwatchjs...@googlegroups.com.
> To post to this group, send email to nightw...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/nightwatchjs/439f89da-c128-4007-810e-f7e2a762b647%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

Jonathan Haggarty

unread,
Mar 18, 2014, 10:25:06 AM3/18/14
to nightw...@googlegroups.com, Riku Rouvila
Is this a workaround or the suggested solution to solving these sorts of problems? Coupling commands on the browser object to things that have nothing to do with it feels a little strange to me but I might be missing something in my translation.

For example, one thing that would be quite nice in our world would be to start a small emulation server which returns fake, well-known, data to the browser before we execute any of our tests and then tearing it down after. This process itself has plenty of asynchronous points in it...

Jonathan Haggarty

unread,
Mar 18, 2014, 10:31:20 AM3/18/14
to nightw...@googlegroups.com, Riku Rouvila
Of course, it might be the only solution just now which is fine :)

Just trying to guage where your thoughts are in terms of incorporating this functionality into the framework generally...
Reply all
Reply to author
Forward
0 new messages