【问题标题】:Given model profile directory does not exist (FirefoxProfile)给定模型配置文件目录不存在 (FirefoxProfile)
【发布时间】:2016-05-24 17:32:25
【问题描述】:

我在src/main/resources/firefox/profile/selenium 下有一个配置文件文件夹src/main/resources/firefox/extensions/ 下有一个扩展文件夹我正在使用maven shade 插件将其打包为一个超级jar,以便我们可以在我们的服务器上运行测试套件。

        <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.2</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.handlers</resource>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.schemas</resource>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <manifestEntries>
                                    <Main-Class>com.erac.automation.automationCommon.test.gui.TestGui</Main-Class>
                                    <X-Compile-Source-JDK>${maven.compile.source}</X-Compile-Source-JDK>
                                    <X-Compile-Target-JDK>${maven.compile.target}</X-Compile-Target-JDK>
                                </manifestEntries>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>

以及我如何访问配置文件和扩展文件夹

try{
        firefoxProfileDirectory = getExtension("/firefox/profiles/selenium/", "");
        System.out.println("the file for the firefoxProfileDirectory - " + firefoxProfileDirectory.exists());
    }catch(Exception e){

    }
    FirefoxProfile profile = new FirefoxProfile(firefoxProfileDirectory);
try{
    profile.addExtension(getExtension("/firefox/extensions/", FIREBUG_XPI));
    profile.addExtension(getExtension("/firefox/extensions/", FIREPATH_XPI));
    }catch(Exception e){

    }

 public static File getExtension(String path, String file) throws IOException {
    URL url = AutomationProfileFactory.class.getResource(path + file);
    File firefoxProfileFolder = new File("");
    if(url == null) {
        //nothing
    }
    else{
        firefoxProfileFolder = new File(url.getPath());
        System.out.println(firefoxProfileFolder.exists());
        return firefoxProfileFolder;
    }
    return new File(""); 
}

在 MyEclipse 中运行程序时,测试正常运行,但在创建 uber jar 并在命令行中运行后出现此错误

Caused by: org.openqa.selenium.firefox.UnableToCreateProfileException: Given model profile directory does not exist: file:\C:\rmqa\rmqa\target\rmqa-0.0.1-SNAPSHOT.jar!\firefox\profiles\selenium
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'XD-DW764-676', ip: '10.23.14.55', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_72'
Driver info: driver.version: EventFiringFirefoxDriver
        at org.openqa.selenium.firefox.FirefoxProfile.verifyModel(FirefoxProfile.java:180)
        at org.openqa.selenium.firefox.FirefoxProfile.<init>(FirefoxProfile.java:91)
        at org.openqa.selenium.firefox.FirefoxProfile.<init>(FirefoxProfile.java:78)
        at com.erac.automation.automationCommon.driver.AutomationProfileFactory.getFirefoxProfile(AutomationProfileFactory.java:27)
        at com.erac.automation.automationCommon.driver.EventFiringFirefoxDriver.<init>(EventFiringFirefoxDriver.java:11)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)

我应该如何访问这些 .xpi 文件并获取配置文件文件夹?

【问题讨论】:

  • 我不认为这个问题是另一个问题的重复,因为另一个问题是关于如何添加资源,而这个问题似乎是关于如何使 selenium 与嵌入的配置文件一起工作在一个罐子里。

标签: java maven selenium maven-shade-plugin


【解决方案1】:

它在您的 IDE 中工作的原因是因为您可能仍在解析文件系统中配置文件的实际路径,而当您将其打包为 uber jar 然后尝试运行它时,您的文件路径 url 是现在包括配置文件所在的罐子的位置,以及罐子内配置文件的相对路径。我认为 selenium 不太了解。

所以要解决这个问题,您应该将您的个人资料提取到一个目录中[这可能是一次性活动,因为 webdriver 在生成新浏览器时基本上会复制一份个人资料],然后通过引用构造您的 FirefoxProfile 对象到您提取的目录。

简而言之

firefoxProfileFolder

应指向本地文件系统上的有效路径。

【讨论】:

    猜你喜欢
    • 2011-10-28
    • 2013-09-02
    • 2018-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-24
    相关资源
    最近更新 更多