我正在使用nightwatch来测试一个网站。下面是我的配置文件。我想使用phantomjs作为浏览器,这样它就可以在不打开浏览器的情况下运行。但是当我使用nightwatch -c integration-tests/nightwatch.json命令运行测试时,它总是打开我的chrome浏览器。我尝试修改browserName的值,结果发现我放入的任何内容都没有任何效果。我的配置有什么问题吗?
{
"src_folders": [
"./integration-tests/tests"
],
"output_folder": "./integration-tests/reports",
"custom_commands_path": "",
"custom_assertions_path": "",
"page_objects_path": "",
"globals_path": "",
"selenium": {
"start_process": false
},
"test_settings": {
"default": {
"launch_url": "http://localhost:9091",
"selenium_port": 9515,
"selenium_host": "localhost",
"default_path_prefix": "",
"silent": true,
"screenshots": {
"enabled": false,
"path": ""
},
"desiredCapabilities": {
"browserName": "phantomjs",
"javascriptEnabled" : true,
"phantomjs.binary.path" :"node_modules/phantomjs",
"phantomjs.cli.args" : []
}
}
}
}发布于 2017-01-09 18:30:11
您需要更改PhantomJS报告的userAgent。
{
"src_folders": [
"./integration-tests/tests"
],
"output_folder": "./integration-tests/reports",
"custom_commands_path": "",
"custom_assertions_path": "",
"page_objects_path": "",
"globals_path": "",
"selenium": {
"start_process": false
},
"test_settings": {
"default": {
"launch_url": "http://localhost:9091",
"selenium_port": 9515,
"selenium_host": "localhost",
"default_path_prefix": "",
"silent": true,
"screenshots": {
"enabled": false,
"path": ""
},
"desiredCapabilities": {
"browserName": "phantomjs",
"javascriptEnabled" : true,
"phantomjs.binary.path" :"node_modules/phantomjs",
"phantomjs.cli.args" : [],
"phantomjs.page.settings.userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36"
}
}
}
}对象设置{}
userAgent定义了当网页请求资源时发送到服务器的用户代理。
来源:http://phantomjs.org/api/webpage/property/settings.html
如果您需要更多示例:
// Mac Chrome 46
"phantomjs.page.settings.userAgent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36"
// Windows Chrome 46
"phantomjs.page.settings.userAgent" : "Mozilla/5.0 (Windows NT 6.3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36"
// Mac Firefox 42.0
"phantomjs.page.settings.userAgent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:42.0) Gecko/20100101 Firefox/42.0"
// Windows Firefox 42.0
"phantomjs.page.settings.userAgent" : "Mozilla/5.0 (Windows NT 6.3; rv:42.0) Gecko/20100101 Firefox/42.0"
// PhantomJS 2.0
"phantomjs.page.settings.userAgent" : "Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.0.0 Safari/538.1"https://stackoverflow.com/questions/41528607
复制相似问题