给定的模型配置文件目录不存在 (FirefoxProfile)
Given model profile directory does not exist (FirefoxProfile)
我有一个配置文件夹 src/main/resources/firefox/profile/selenium
和 src/main/resources/firefox/extensions/
下的一个扩展文件夹 我正在使用 maven shade 插件将其打包为 uber 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 并在命令行中 运行ning 之后我得到这个错误
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 文件并获取配置文件文件夹?
它在您的 IDE 中起作用的原因是因为您可能仍在解析文件系统中配置文件的实际路径,而当您将其打包为 uber jar 然后尝试 运行 它,您的文件路径 url 现在由配置文件所在的 jar 的位置以及配置文件在 jar 中的相对路径组成。我不认为 selenium 理解得很好。
因此,为了解决这个问题,您应该将您的配置文件提取到一个目录中[它可以是一次性的 activity 因为 webdriver 在生成新浏览器时基本上会复制一份配置文件],然后通过引用您提取的目录来构造您的 FirefoxProfile 对象。
简而言之
firefoxProfileFolder
应指向本地文件系统上的有效路径。
我有一个配置文件夹 src/main/resources/firefox/profile/selenium
和 src/main/resources/firefox/extensions/
下的一个扩展文件夹 我正在使用 maven shade 插件将其打包为 uber 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 并在命令行中 运行ning 之后我得到这个错误
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 文件并获取配置文件文件夹?
它在您的 IDE 中起作用的原因是因为您可能仍在解析文件系统中配置文件的实际路径,而当您将其打包为 uber jar 然后尝试 运行 它,您的文件路径 url 现在由配置文件所在的 jar 的位置以及配置文件在 jar 中的相对路径组成。我不认为 selenium 理解得很好。
因此,为了解决这个问题,您应该将您的配置文件提取到一个目录中[它可以是一次性的 activity 因为 webdriver 在生成新浏览器时基本上会复制一份配置文件],然后通过引用您提取的目录来构造您的 FirefoxProfile 对象。
简而言之
firefoxProfileFolder
应指向本地文件系统上的有效路径。