我有一个配置文件夹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中运行程序时,测试正常运行,但在创建超级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文件并获取个人资料文件夹?
答案 0 :(得分:0)
它在IDE中工作的原因是因为您可能仍在解析文件系统中配置文件的实际路径,而当您将其打包为超级jar然后尝试运行它时,您的文件路径网址是现在包括罐子所在的罐子的位置,以及罐子内的型材的相对路径。我不认为硒很好理解。
所以为了解决这个问题,你应该将你的个人资料提取到一个目录[它可以是一次性活动,因为webdriver基本上会在生成新浏览器时复制该个人资料],然后通过引用构建你的FirefoxProfile对象到您解压缩的目录。
简而言之
firefoxProfileFolder
应指向本地文件系统上的有效路径。