首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么nightwatch不获取我的浏览器配置

为什么nightwatch不获取我的浏览器配置
EN

Stack Overflow用户
提问于 2017-01-08 09:45:19
回答 1查看 511关注 0票数 0

我正在使用nightwatch来测试一个网站。下面是我的配置文件。我想使用phantomjs作为浏览器,这样它就可以在不打开浏览器的情况下运行。但是当我使用nightwatch -c integration-tests/nightwatch.json命令运行测试时,它总是打开我的chrome浏览器。我尝试修改browserName的值,结果发现我放入的任何内容都没有任何效果。我的配置有什么问题吗?

代码语言:javascript
复制
{
  "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" : []
      }
    }
  }
}
EN

回答 1

Stack Overflow用户

发布于 2017-01-09 18:30:11

您需要更改PhantomJS报告的userAgent。

代码语言:javascript
复制
{
  "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

如果您需要更多示例:

代码语言:javascript
复制
// 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"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41528607

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档