Running nightwatch tests in headless Chrome (Windows)

1,645 views
Skip to first unread message

Alice G

unread,
May 16, 2018, 7:21:33 AM5/16/18
to NightwatchJs
Is this possible? If so, does anyone have a working nightwatch.conf ?
Mine looks like this at the moment, and it's not working:


{
 
"src_folders" : ["tests"],
 
"output_folder" : "reports",
 
"custom_commands_path" : "./custom-commands",


 
"selenium" : {
   
"start_process" : true,
   
"server_path" : "./bin/selenium-server-standalone-3.9.1.jar",
   
"log_path" : "/logs",
   
"port" : 4444,
   
"cli_args" : {
     
"webdriver.chrome.driver" : "./bin/chromedriver.exe",
   
"webdriver.firefox.driver" : "./bin/firefox.exe"
   
}
 
},


 
"test_settings" : {
   
"default" : {
     
"launch_url" : "http://localhost",
     
"selenium_port"  : 4444,
     
"selenium_host"  : "localhost",
     
"desiredCapabilities": {
       
"browserName": "chrome",
       
"javascriptEnabled": true,
       
"acceptSslCerts": true,
 
"chromeOptions" : {
 
"args" : [ "--headless", "--disable-gpu=true", "--remote-debugging-port=9222"],
 
"binary" : "./bin/chromium.exe"
 
}
     
}
   
}
 
}
}

Simon Correia

unread,
May 16, 2018, 7:29:59 AM5/16/18
to nightw...@googlegroups.com
Hi Alice,

Find attached copy of my config file which works perfectly fine. Just do the necessary path changes as per your project needs.

Thanks & Regards,

Simon

--
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+unsubscribe@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/92be48f9-a623-4276-a0fd-899b8a58c20e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

nightwatch.json

Alice G

unread,
May 16, 2018, 7:47:33 AM5/16/18
to NightwatchJs
Thanks! I tried it with your config file, the tests are running now, but all of them are failing on the first step already. For example:
" × Testing if the page title equals "Register".  - expected "Register" but got: "" "  or "  × Timed out while waiting for element <input[name=Login_0TextBoxId]> to be present for 3000 milliseconds.  - expected "visible" but got: "not found" ".

Seems like there is still no browser. . .? Did anyone have this problem?

Thanks & Regards,

Simon

To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs...@googlegroups.com.

Simon Correia

unread,
May 16, 2018, 8:00:40 AM5/16/18
to nightw...@googlegroups.com
Hey,

Glad that my config file worked. But can you tell me if you have added your launch url? As what i can see from your first config file content the launch url is localhost. Which actually should be the url you are running the scripts on. In my given file it is google. Change it to your site.

Also if you have done it already, are you calling the url anywhere in your page file or test file?

Thanks & Regards,

Simon

To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs+unsubscribe@googlegroups.com.

To post to this group, send email to nightw...@googlegroups.com.

Alice G

unread,
May 16, 2018, 8:16:19 AM5/16/18
to NightwatchJs
Hi,

changed it to localhost, like in my config file that I posted. The tests where running in Chrome before (but not headless), with localhost as the launch url. I just tried to change my config so it would work headless, which is not working.
I'm fairly new to Nightwatch, so I'm not sure, what the launch url is for. I just used a working example I found... In my tests I'm actually calling a different url, for a login test, if that is what your question was . . .really no idea what else I could do... thanks for your patience!! 

Thanks & Regards,

Simon

Simon Correia

unread,
May 16, 2018, 8:27:11 AM5/16/18
to nightw...@googlegroups.com
Hey,

If you are using other url in your test than it is fine. Launch url is used to set a default url for that particular project.

Neways coming back to your issue, can you try to add more wait time for the methods you are using? For e.g you got a timeout error. Increase the timeout. If my config file is fine than there is some issue with your page or test file.

Does your browser open? And url is passed in it?

Thanks & Regards,

Simon

To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs+unsubscribe@googlegroups.com.

To post to this group, send email to nightw...@googlegroups.com.

Alice G

unread,
May 16, 2018, 8:53:41 AM5/16/18
to NightwatchJs
Hey,

I increased the wait time from 3000 to 30000. Still, it's not finding the elements. I don't think the wait time is the problem, since the tests were running before in Chrome, but not in headless Chrome now.

My browser does not open at the moment, since that's what it's supposed to do in headless Chrome? When I was running my tests in a normal Chrome Browser, it opened the Browser and the url was passed just fine.

(I need the tests to run headless, because they're supposed to run on a windows slave through Jenkins later...)



Thanks & Regards,

Simon

Simon Correia

unread,
May 16, 2018, 9:03:47 AM5/16/18
to nightw...@googlegroups.com
Hey,

Sorry I meant try running the script removing the headless argument and see if browser is opening. See if it opens and passes then url and see the behavior.

Sabin Manandhar

unread,
May 16, 2018, 9:40:55 AM5/16/18
to nightw...@googlegroups.com
This worked for me . Try this.

 "desiredCapabilities": {
        "browserName": "chrome",
        "chromeOptions": {
          "args": ["--window-size=1920,1080", "--headless"]
        },
        "nativeEvents": false,
        "enablePersistentHover": false,
        "requireWindowFocus": true,
        "unexpectedAlertBehaviour": "accept",
        "ignoreProtectedModeSettings": true,
        "disable-popup-blocking": true,
        "elementScrollBehavior": 1,
        "javascriptEnabled": true,
        "acceptSslCerts": true,
        "loggingPrefs": {
          "browser": "ALL"
        }
      }
    },

    "chrome": {

      "desiredCapabilities": {
        "browserName": "chrome",
        "javascriptEnabled": true,
        "acceptSslCerts": true
      },
      "chromeOptions": {
        "args": ["--window-size=1024,768", "--headless"]
      }
    },



To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs+unsubscribe@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/6c06f1bd-9afa-492c-805b-a52b2b13f32e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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+unsubscribe@googlegroups.com.

To post to this group, send email to nightw...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Thank you.

Sabin Manandhar

Alice G

unread,
May 16, 2018, 10:08:51 AM5/16/18
to NightwatchJs
Hi Simon, 

the tests are running in the Browser, when I remove the headless argument, without any problem. This is really weird...maybe I have the wrong chrome version and headless mode is not working there..?

Alice G

unread,
May 16, 2018, 10:23:21 AM5/16/18
to NightwatchJs
Hi Sabin,

thank you, but there is the same problem with your config. Tests start, but fail, because elements are not found.

--
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.

Simon Correia

unread,
May 16, 2018, 10:36:27 AM5/16/18
to nightw...@googlegroups.com
Try running your old config file by removing the binary options below args. You don't need it neway.

Alice G

unread,
May 16, 2018, 10:45:44 AM5/16/18
to NightwatchJs
When I run my config without the binary options, the first test just hangs, without doing anything. With your config, they are at least running, but failing. But thank you for your help, somehow I will figure it out...
Message has been deleted

Simon Correia

unread,
May 16, 2018, 11:28:32 AM5/16/18
to nightw...@googlegroups.com
You are welcome. Just try. Even I struggled initially but now I write for any and every project. It works like a charm. If in case you want me to email you a sample of my test project than I can. Just give me your email.

Kathy Ding

unread,
May 23, 2018, 3:45:32 AM5/23/18
to NightwatchJs
I have the same problem, and I tried the config file above but also failed with similar error. It seems the Chrome browser was not opened, all the elements could not be found. I already sent out an email before finding this email ...Will take a look on whats' going on...

Kathy Ding

unread,
May 23, 2018, 8:52:07 PM5/23/18
to NightwatchJs
I updated my config file with chromeOptions "binary" but the result is same. nightwatch still can not find the elements. Here is my nightwatch.config (windows10, nightwatch 0.9.21, nonde:8.9, selenium:3.12, chrome: v66)



const seleniumServer = require("selenium-server");
const chromedriver = require("chromedriver");
const SCREENSHOT_PATH = "./screenshots/";


module.exports = {
"src_folders": [
"test"
],
"custom_commands_path": "./commands",
"output_folder": "./reports",
"selenium": {
"start_process": true,
"server_path": seleniumServer.path,
"host": "127.0.0.1",
"port": 4444,
"cli_args": {
"webdriver.chrome.driver" : chromedriver.path
}
},
"test_settings": {
"default": {
"screenshots": {
"enabled": true,
"path": './screenshots'
},
"launch_url": "https://127.0.0.1:10443/",
"globals": {
"waitForConditionTimeout": 5000 ,
before: function(cb){
cb();
},
// note : this will be covered if there is command line option like $ npm run e2e --scanweb='123.xxx'
},
"desiredCapabilities": {
"browserName": "chrome",
"javascriptEnabled": true,
"acceptSslCerts": false,
"chromeOptions" : {
"args" : [
"--headless",
"--disable-gpu",
],
"binary" : "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",

}
},

},
"integration" : {
"globals": {
"scannedWebsites": "${ENV_SCANWEB}",
}
},
"chrome": {
"desiredCapabilities": {
"browserName": "chrome",
}
},
}
}

Simon Correia

unread,
May 24, 2018, 2:05:29 AM5/24/18
to nightw...@googlegroups.com
Hey,

I am attaching a working config file. Add the launch url, change the selenium and drivers path (Where dot signifies the root folder, than bin is the primary folder, than drivers folder which includes the drivers. Same implies to selenium) as how i have mentioned and not like the way you have added in your file. Ok. And give a try.

Thanks & Regards,

Simon

To unsubscribe from this group and stop receiving emails from it, send an email to nightwatchjs+unsubscribe@googlegroups.com.

To post to this group, send email to nightw...@googlegroups.com.
nightwatch.json

jacky huang

unread,
May 24, 2018, 9:28:09 PM5/24/18
to nightw...@googlegroups.com
Hi, Simon,

Thanks a lot for your reply.

I tried your nightwatch.json file, however all the elements still can not be found. With the same config, if only without "headless", all the cases could pass.
May I know what's your version of selenium , chromedriver and chrome , also the nightwatch? So that I could switch to that environment to try again. Thank you.

Error msg:
===========

 × Timed out while waiting for element <#name> to be present for 2000 milliseconds.  - expected "visible" but got: "not found"

Verbose msg from nightwatch:
============
Running:  Verify Component View
INFO Request: POST /wd/hub/session
 - data:  {"desiredCapabilities":{"browserName":"chrome","javascriptEnabled":true,"acceptSslCerts":true,"platform":"ANY","chromeOptions":{"args":["headless","disable-gpu"]},"name":"E2e\\scans Status Verify"}}
 - headers:  {"Content-Type":"application/json; charset=utf-8","Content-Length":198}

Simon Correia

unread,
May 25, 2018, 12:46:04 AM5/25/18
to nightw...@googlegroups.com
Hey,

I can see you have added disable gpu in chromeoptions. Can you try removing it run the tests. Might make a difference.


Thanks & Regards,

Simon

Kathy Ding

unread,
May 25, 2018, 1:19:12 AM5/25/18
to NightwatchJs

I found the problem now. It is because of the lanuch url is insecure SSL link. I added  "acceptInsecureCerts" in config file, it works well now. All the elements could be found now.
Simon, many thanks for the help.
"desiredCapabilities": {
"browserName": "chrome",
"acceptSslCerts": true,
"acceptInsecureCerts": true,
"chromeOptions" : {
"args": [
"headless",
"no-sandbox",
"disable-gpu",
"ignore-certificate-errors"
],
"binary" : "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
}
},

Simon Correia

unread,
May 25, 2018, 1:30:37 AM5/25/18
to nightw...@googlegroups.com
Well,

Nice to know it was a simple issue. And mine url's have been prefixed with https so i did not come across the issue.

Good to see atlast it is working for you.

Thanks & Regards,

Simon

Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages