【问题标题】:Remote Webdriver Capabilities - user agent for Mobile远程 Webdriver 功能 - 移动用户代理
【发布时间】:2015-07-07 19:43:36
【问题描述】:

我正在使用 Selenium Webdriver 和 Ruby 进行一些移动 Web 自动化测试。现在我需要传递用户代理以及我已经传递的远程 Webdriver 功能。有什么办法可以为 Mobile Web 设置用户代理?我将功能设置为 iphone 并使用 iPhone 模拟器运行我的测试。

【问题讨论】:

  • 因为 user_agent 是请求对象的一部分,所以这个帖子和回复可能对你有帮助stackoverflow.com/questions/22850898/…
  • 这对我帮助不大。我正在寻找一种将用户代理与远程 Webdriver API 一起传递的方法。我知道如何通过用户代理进行 Web 浏览器测试,但不确定移动设备。
  • 对不起,如果我遗漏了什么,但用户代理是用于浏览器(网络或移动)而不是设备本身。因此,如果您使用的是模拟器,则不需要覆盖用户代理。如果你确实想传递一个用户代理,那么你可以将它传递给你在设备上使用的网络浏览器,而不是使用模拟器。另外,您使用的是 ios-driver 还是(已弃用)iPhone 驱动程序?
  • 我同时使用 Android 和 IOS 驱动程序。但这里的问题是我的应用程序需要在访问 URL 时设置自定义标头。有什么办法可以使用这些驱动程序修改标题?
  • 你做不到。在这里 stackoverflow.com/questions/6478672/… 你可以从 selenium 开发人员那里找到一个 naswer。

标签: ruby selenium user-agent remotewebdriver


【解决方案1】:

这是不可能的,因为 WebDriver 当前缺少 HTTP 响应头和状态码方法。
本期链接:https://code.google.com/p/selenium/issues/detail?id=141

【讨论】:

    【解决方案2】:

    试试这样的

    capabilities = Selenium::WebDriver::Remote::Capabilities.send(:firefox, :firefox_profile => build_mobile_profile)
    profile = Selenium::WebDriver::Firefox::Profile.new
    profile['general.useragent.override'] = "Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"
    
    client = Selenium::WebDriver::Remote::Http::Default.new
    client.timeout = 30 # for example
    
    browser = Watir::Browser.new(:remote,
      :url                  => "https://selenium.yourdomain.com:4445/wd/hub",
      :http_client          => client,
      :desired_capabilities => capabilities
    )
    

    【讨论】:

    • 感谢您的评论。这基本上适用于 Firefox 浏览器。该问题是针对移动设备提出的。
    猜你喜欢
    • 2014-07-23
    • 1970-01-01
    • 1970-01-01
    • 2012-12-17
    • 1970-01-01
    • 1970-01-01
    • 2011-11-11
    • 2016-12-20
    • 2023-04-05
    相关资源
    最近更新 更多