守夜人中的自定义用户代理 [英] Custom useragent in nightwatch

查看:68
本文介绍了守夜人中的自定义用户代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以为夜视中的一项测试设置自定义用户代理?

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.

我尝试将其设置为cookie,但是没有用:

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

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

推荐答案

您的测试套件必须独立于目标浏览器.

Your test suite must be independent of the browser targeted.

您应该直接在NightWatch配置json文件中设置用户代理:

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

如有必要,您可以在此处找到主要的用户代理列表: http://www.useragentstring .com/pages/Safari/

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

这篇关于守夜人中的自定义用户代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆