How can I pass arguments to the command line to run tests on a specific site?

2,764 views
Skip to first unread message

Mitchell Pyrtle

unread,
Oct 9, 2015, 1:37:37 PM10/9/15
to NightwatchJs
I have found a lot of similar topics, but none quite explained fully how to go about passing a command line argument for tests.


Example) [In a command prompt window] (Using Win7 64bit)
node nightwatch -t tests/mysite/smoketests/thistest.js


I read that you can create a global.js file to execute specific commands into the command line and I have created one with the following properties:
module.exports = {
 
 
"default" : {
    siteURL
: ""
 
},
 
"envURL" : {
    site1
: "https://site1.com",
    site2 : "https://site2.com",
    prod : "https://prodsite.com"
 
}


};

I also read when executing on the command line, you could toss in the flag "--env" and set it equal to an environment you want to launch on.


So my question, let's say that I want to launch my tests against site2 for e2e testing; What would be passed to have that happen, or am I missing something?

node nightwatch --env=site2 -t tests/mysite/smoketests/thistest.js

I am definitely new to nightwatch, automation testing and using node + command line (I do have experience in javascript and scripting languages)

MG D

unread,
Oct 9, 2015, 3:39:31 PM10/9/15
to NightwatchJs
You can use "process.env", search for it on google.

Andrei Rusu

unread,
Oct 10, 2015, 5:13:22 AM10/10/15
to nightw...@googlegroups.com
You should create a separate environment for each url in your
nightwatch.json, and define the "lauch_url" property. E.g.:

{
"default" : {
launch_url : "http://defaulturl"
},

"site1" : {
launch_url : "http://site2"
},

"prod" : {
launch_url : "http://prod"
}
}

See http://nightwatchjs.org/guide#test-settings for more details.
> --
> 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/d708bdb4-cf37-4f77-b016-2498bd78e9e8%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
Message has been deleted

MG D

unread,
Oct 12, 2015, 12:16:06 PM10/12/15
to NightwatchJs
Try this: node nightwatch --e testSite1

On Monday, 12 October 2015 10:43:46 UTC-5, Mitchell Pyrtle wrote:
I added the following to my nightwatch.json:
  "test_settings" : {
   
"default" : {
     
"launch_url" : "http://localhost",
     
"selenium_port"  : 4444,
     
"selenium_host"  : "localhost",
     
"silent": true,
     
"screenshots" : {
       
"enabled" : true,
           
"on_failure" : true,
           
"on_error" : false,
       
"path" : "tests/screenshots"
     
},
   
"testSite1" : {
     
"launch_url" : "https://testSite1.com",
     
"silent": true,
     
"screenshots" : {
       
"enabled" : true,
       
"on_failure" : true,
       
"on_error" : false,
       
"path" : "tests/testSite1/screenshots"
     
},

     
"desiredCapabilities": {
       
"browserName": "firefox",
       
"javascriptEnabled": true,
       
"acceptSslCerts": true,
           
"handlesAlerts" : true
     
}
   
},

I went to a command window and tried executing: >node nightwatch --env testSite1


And got an error saying no testing environment was specified. Trying to make sense of all of this (apologies! :))

Mitchell Pyrtle

unread,
Oct 12, 2015, 1:17:02 PM10/12/15
to NightwatchJs
Figured out the issue; put the new object inside of another causing the json to fail. Everything is working correctly now! :)
Reply all
Reply to author
Forward
0 new messages