【问题标题】:How to run Selenium WebDriver test cases in Chrome for mobile site如何在移动版 Chrome 中运行 Selenium WebDriver 测试用例
【发布时间】:2016-04-26 06:46:40
【问题描述】:

如何使用 google chrome for mobile 网站运行我的 selenium 'webdriver',却没有任何线索来运行我的脚本,

我有类似 firefox 的用户代理,并且可以在 firefox for mobile 网站中轻松运行我的测试用例

FirefoxProfile ffProfile = new FirefoxProfile();
ffProfile.addExtension(new File(CONFIG.getProperty("agentswitcher")));
String samsung3 = "Mozilla/5.0 (Linux; U; Android 4.0.3; de-de; Galaxy S II Build/GRJ22) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30";
ffProfile.setPreference("general.useragent.override", samsung3);

这里的代理切换器是user_agent_switcher-0.7.3-fx+sm.xpi文件从网上下载

【问题讨论】:

    标签: google-chrome selenium webdriver


    【解决方案1】:

    这很简单。

    您需要将ChromeOptions 的参数传递给ChromeDriver 的构造函数

    代码如下:

    string device = "Samsung Galaxy S4";
    ChromeOptions options = new ChromeOptions();
    options.EnableMobileEmulation(device);
    IWebDriver driver = new ChromeDriver(options);//this will open Chrome in mobile mode
    

    您可以从 Chrome 移动模拟器获得的可用设备列表。

    其中一些是:“Apple iPhone 4”、“Apple iPhone 6”、“Samsung Galaxy S4”

    【讨论】:

      猜你喜欢
      • 2012-11-23
      • 2023-03-15
      • 1970-01-01
      • 2020-02-29
      • 2017-02-10
      • 1970-01-01
      • 2018-11-25
      • 2017-01-11
      • 2012-02-23
      相关资源
      最近更新 更多