首页 > 解决方案 > Selenium 远程 Web 驱动程序未从给定的 Firefox 配置文件开始

问题描述

测试用例

我想在 Firefox 远程 Web 驱动程序中安装自定义扩展。为此,我创建了一个 FirefoxProfile 并通过 setExtension 添加了自定义扩展。问题是我刚刚创建的配置文件没有添加到 Driver 实例中。这是我使用的一段代码:

            File firefoxExtension = new File("src\\main\\resources\\browser-extensions\\firefox-extension.xpi");
            FirefoxProfile profile = new FirefoxProfile();
            profile.addExtension(firefoxExtension);
            FirefoxOptions options = new FirefoxOptions();
            options.setProfile(profile);
            capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS,options);

        try {
            return new RemoteWebDriver(new URL("https://" + username + ":" + accessKey + "@"
                    + environmentVariables.getProperty("browserstack.server") + "/wd/hub"), capabilities);
        } catch (Exception e) {
            System.out.println(e);
            return null;
        }

系统

远程平台:Windows 10
Firefox 版本:68
Selenium:3.141.59
Selenium Hub:浏览器堆栈

预期结果

  1. 浏览器打开
  2. 加载了扩展的配置文件
  3. 浏览器可以使用 RemoteWebDriver 进行交互

标签: javaseleniumfirefoxbrowserstackfirefox-profile

解决方案


推荐阅读