在Saucelabs中使用Selenium远程Firefox webdriver安装扩展程序 [英] Issue installing extension with Selenium remote Firefox webdriver in Saucelabs

查看:158
本文介绍了在Saucelabs中使用Selenium远程Firefox webdriver安装扩展程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

尝试在Saucelabs上远程执行Selenium测试期间安装Firefox浏览器扩展。在本地执行测试时,扩展程序在Firefox中安装并处于活动状态,但在Saucelabs上的远程执行中,扩展名不会出现在已安装的扩展名列表中。按照此Saucelabs中列出的步骤支持文章

设置

Selenium.Support v2.48.2或v2.49.0

Selenium.WebDriver v2.48.2或v2.49.0

Windows 10或7

Firefox 43

Setup
Selenium.Support v2.48.2 or v2.49.0
Selenium.WebDriver v2.48.2 or v2.49.0
Windows 10 or 7
Firefox 43

C#测试设置

private static FirefoxProfile CreateFirefoxProfile()
    {
        FirefoxProfile profile = new FirefoxProfile();
        profile.AddExtension("Tools/modify_headers-0.7.1.1-fx.xpi");
        profile.SetPreference("general.useragent.override", "UA-STRING");
        profile.SetPreference("extensions.modify_headers.currentVersion", "0.7.1.1-signed");
        profile.SetPreference("modifyheaders.headers.count", 1);
        profile.SetPreference("modifyheaders.headers.action0", "Add");
        profile.SetPreference("modifyheaders.headers.name0", "SampleHeader");
        profile.SetPreference("modifyheaders.headers.value0", "test1234");
        profile.SetPreference("modifyheaders.headers.enabled0", true);
        profile.SetPreference("modifyheaders.config.active", true);
        profile.SetPreference("modifyheaders.config.alwaysOn", true);
        profile.SetPreference("modifyheaders.config.start", true);

        return profile;
    }

private static IWebDriver GetRemoteDriver()
    {
        var capabilities = new DesiredCapabilities();

        var profile = CreateFirefoxProfile();

        capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, profile);

        capabilities.SetCapability("name", buildContext);
        capabilities.SetCapability(CapabilityType.BrowserName,"firefox");
        capabilities.SetCapability(CapabilityType.Version,"");
        capabilities.SetCapability(CapabilityType.Platform, "Windows 10");
        capabilities.SetCapability("screen-resolution", "1280x1024");
        capabilities.SetCapability("username", "SaucelabsUserName");
        capabilities.SetCapability("accessKey", "SaucelabsAccessKey");
        capabilities.SetCapability("build", "BuildNumber");

        return new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com/wd/hub"), capabilities);
    }

Firefox设置

在本地执行期间查看:支持Firefox并打开user.js文件时,它包含以下与Web驱动程序配置匹配的扩展设置。检查Saucelabs远程实例上的user.js不包含该内容。这是远程user.js文件内容的粘贴bin

user_pref("general.useragent.override", "UA-STRING");
user_pref("extensions.modify_headers.currentVersion", "0.7.1.1-signed");
user_pref("modifyheaders.headers.count", 1);
user_pref("modifyheaders.headers.action0", "Add");
user_pref("modifyheaders.headers.name0", "SampleHeader");
user_pref("modifyheaders.headers.value0", "test1234");
user_pref("modifyheaders.headers.enabled0", true);
user_pref("modifyheaders.config.active", true);
user_pref("modifyheaders.config.alwaysOn", true);
user_pref("modifyheaders.config.start", true);

我也尝试过引用xpi的外部版本,结果相同。
https://addons.mozilla.org /firefox/downloads/latest/967/addon-967-latest.xpi

I've also tried referencing an external version of the xpi with same result. https://addons.mozilla.org/firefox/downloads/latest/967/addon-967-latest.xpi

推荐答案

发表了错误报告到SeleniumHQ并收到此回复,修复了上述代码。

Posted a bug report to SeleniumHQ and received this response, which fixed the above code.


在.NET的RemoteWebDriver情况下,您需要使用
ToBase64String()方法。这应该可以解决问题。请注意,这个
是其他驱动程序具有类型安全选项
类而不是传递原始功能的原因之一。
.NET绑定的未来版本也应该将此模式扩展到Firefox,将此作为一个问题删除

In the RemoteWebDriver case for .NET, you need to use the ToBase64String() method. This should resolve the issue. Note that this is one of the reasons that other drivers have type-safe options classes instead of passing raw capabilities. Future versions of the .NET bindings should extend this pattern to Firefox as well, removing this as an issue in the future.

上面的GetRemoteDriver方法应该更新为。

The GetRemoteDriver method from above should be updated to this.

private static IWebDriver GetRemoteDriver()
{
    var capabilities = new DesiredCapabilities();

    var profile = CreateFirefoxProfile();

    // Note the change here, calling .ToBase64String()
    capabilities.SetCapability(FirefoxDriver.ProfileCapabilityName, profile.ToBase64String());

    capabilities.SetCapability("name", buildContext);
    capabilities.SetCapability(CapabilityType.BrowserName,"firefox");
    capabilities.SetCapability(CapabilityType.Version,"");
    capabilities.SetCapability(CapabilityType.Platform, "Windows 10");
    capabilities.SetCapability("screen-resolution", "1280x1024");
    capabilities.SetCapability("username", "SaucelabsUserName");
    capabilities.SetCapability("accessKey", "SaucelabsAccessKey");
    capabilities.SetCapability("build", "BuildNumber");

    return new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com/wd/hub"), capabilities);
}

在看到修复程序后,我能够找到提到的其他资源这种变化。

After seeing what the fix is, I was able to find additional resources that mentioned this change.

https://stackoverflow.com/a/14285902/276681

https:// code .google.com / p / selenium / issues / detail?id = 2696#c4

这篇关于在Saucelabs中使用Selenium远程Firefox webdriver安装扩展程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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