Custom useragent in nightwatch

﹥>﹥吖頭↗ 提交于 2019-12-11 11:31:43

问题


Is there a way to set a custom useragent for just one test in nightwatch?

I want to test a page using both mobile and non-mobile useragents to ensure the proper experience is shown.

I tried setting it as a cookie but it didn't work:

browser
  .setCookie({
    name     : "User_Agent",
    value    : "iphone",
  })
  .url('...')
  // etc

回答1:


Your test suite must be independent of the browser targeted.

You should set the user agent directly in the NightWatch configuration json file :

"test_settings" : {
  "default" : {
    "launch_url" : "http://localhost",
    "port"  : 4444
    "selenium_host"  : "localhost",
    "silent": true,
    "screenshots" : {
      "enabled" : true,
      "path" : "screenshots"
    },
    "desiredCapabilities": {
      "browserName": "chrome",
      "chromeOptions": {
        "args": [
          "--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A",
          "--window-size=320,640"
        ]
      },
      "javascriptEnabled": true,
      "acceptSslCerts": true
    }
  }

If necessary, you can find a major list of user agents here : http://www.useragentstring.com/pages/Safari/



来源:https://stackoverflow.com/questions/29522757/custom-useragent-in-nightwatch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!