Global Setup + Teardown

455 views
Skip to first unread message

Jonathan Haggarty

unread,
May 20, 2014, 8:45:33 AM5/20/14
to nightw...@googlegroups.com
Howdy,

I've been looking at the Github issues + Nightwatch docs and I've seen a few mentions of this but I couldn't actually figure out if it was ever actually implemented or not. Can someone confirm either way and if so perhaps provide an example?

Thanks!

Andrei Rusu

unread,
May 20, 2014, 9:23:11 AM5/20/14
to nightw...@googlegroups.com
Hi there,

You can define tearDown or setUp methods as globals but they won't automatically be made available inside the test specs, yet. I think I intended to do this but it got lost. So for now you can define them like this in your nightwatch.json:

Per each environment:
globals.js
module.exports = {

  setUp
: function(client) {
   
...
 
},
 
  tearDown
: function() {
   
...
 
}
};

nightwatch.json
{
 
"default" : {
   
"globals" : "./lib/globals.js"
 
}
}

Per all environments:
globals.js
module.exports = {
 
'default' : {
    setUp
: function(client) {
     
...
   
},
 
    tearDown
: function() {
     
...
   
}
 
}
};

nightwatch.json
{
 
"globals_path" : "./lib/globals.js"
}


And then inside your test spec you're have them available as this.client.globals.setUp and tearDown respectively. I'm afraid that's all you can do for now, I'll try to add the automatic loading as well in a next version.

Michael Valentine

unread,
Aug 1, 2014, 6:11:06 PM8/1/14
to nightw...@googlegroups.com
Question, is there a way to access the client or json information in tearDown?


Scott Thompson

unread,
May 26, 2016, 10:06:25 AM5/26/16
to NightwatchJs
tearDown : function() {
     console.log(this.client)
Reply all
Reply to author
Forward
0 new messages