如何在saucelabs上的firefox浏览器中覆盖useragent

时间:2015-01-23 12:58:12

标签: java firefox override user-agent saucelabs

Saucelabs: -

https://saucelabs.com/

使用以下方法在saucelabs上创建firefox驱动程序: -

DesiredCapabilities capabilities = DesiredCapabilities.firefox();
        capabilities.setCapability("version", "5");
        capabilities.setCapability("platform", Platform.XP);
        // Create the connection to Sauce Labs to run the tests
        this.driver = new RemoteWebDriver(
                new URL("http://YOUR_USERNAME:YOUR_ACCESS_KEY@ondemand.saucelabs.com:80/wd/hub"),
                capabilities);
    }

我想使用firefox驱动程序使用移动用户代理。我怎么能这样做。

1 个答案:

答案 0 :(得分:1)

您是否尝试过创建新配置文件并在配置文件中设置用户代理字符串?

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("general.useragent.override", "UA-STRING");

DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);