我正在尝试对一个应用程序进行网络自动化,如果从移动设备访问该应用程序,该应用程序的行为会有所不同。有谁知道使用 Selenium 2 实现这一目标的最佳方法吗?
在理想的世界中,我希望找到一种仅配置用户代理的方法,以便我们可以轻松测试大量排列。
最佳答案
寻找here ,它显示了在 Firefox 中设置用户代理字符串的代码:
FirefoxProfile profile = new FirefoxProfile();
profile.addAdditionalPreference("general.useragent.override", "some UA string");
WebDriver driver = new FirefoxDriver(profile);
转换为 Ruby,它看起来像这样:
require 'selenium-webdriver'
profile = Selenium::WebDriver::Firefox::Profile.new
profile['general.useragent.override'] = 'some UA string'
driver = Selenium::WebDriver.for :firefox, :profile => profile
在其末尾添加一行以导航至 http://whatsmyuseragent.com表明它按预期工作。
但是,Selenium 2 附带了适用于 iPhone 和 Android 应用程序的驱动程序。我还没有尝试过它们,但看起来它们都可以在模拟器或真实设备中运行。这些对你不起作用有什么原因吗?它们可以让您更好地了解设备上的实际情况。
关于ruby - 使用 Selenium 2 设置用户代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4750433/