Google chrome 无法通过ANT运行测试
我有一个测试类,如果我在eclipse中运行,这个类的所有测试都可以正常运行。(右键单击文件,作为jUnit运行)但是当我尝试使用Ant脚本运行时,它失败了 实际上,这个测试是针对两个浏览器运行的。该测试在IE Chrome上运行良好。它在IE上运行良好,但无法在Chrome上运行。我不知道发生了什么事。 我在项目路径的所有资源/驱动程序/下放置的所有驱动程序相关信息。以及我保存在项目browserProfiles文件夹下的浏览器配置文件 我不知道为什么测试不能被用于Chrome 我已经附上了测试代码和我试图在源代码中创建webdriver和seldriver的代码Google chrome 无法通过ANT运行测试,google-chrome,ant,selenium,junit,webdriver,Google Chrome,Ant,Selenium,Junit,Webdriver,我有一个测试类,如果我在eclipse中运行,这个类的所有测试都可以正常运行。(右键单击文件,作为jUnit运行)但是当我尝试使用Ant脚本运行时,它失败了 实际上,这个测试是针对两个浏览器运行的。该测试在IE Chrome上运行良好。它在IE上运行良好,但无法在Chrome上运行。我不知道发生了什么事。 我在项目路径的所有资源/驱动程序/下放置的所有驱动程序相关信息。以及我保存在项目browserProfiles文件夹下的浏览器配置文件 我不知道为什么测试不能被用于Chrome 我已经附上了测
package com.mytests;
public class MyParamTest {
private MyWrapperForBrowser browser;
@Before
public void setup(){
b = new MyWrapperForBrowser("chrome");
b.start();
}
@Test
public void testCURDOnEntity() {
MyEntity e = new MyEntity(browser);
Assert.assertTrue(e.createMessage("message", "text"));
// more business logic..
}
}
和源代码
package com.mysrc;
import java.util.*;
import org.openqa.selenium.*;
public class MyWrapperForBrowser {
private final WebDriver webDriver;
private WebDriverBackedSelenium selDriver;
public MyWrapperForBrowser(String driver) {
if (driver.equalsIgnoreCase("IE")
{
// create webDriver , selDriver
}
else{
System.setProperty("webdriver.chrome.driver",
"allresources/drivers/chromedriver.exe");
DesiredCapabilities broserCapabilities = DesiredCapabilities.chrome();
broserCapabilities.setCapability("chrome.switches", Arrays.asList("--start-minimized"));
String url = this.getClass().getClassLoader().getResource("browserProfiles/ChromeProfile").getPath()
.substring(1);
broserCapabilities.setCapability("chrome.switches",
Arrays.asList("--user-data-dir=" + url));
webDriver = new ChromeDriver(broserCapabilities);
selDriver = new WebDriverBackedSelenium(webDriver, "");
}
}
public void start() {
webDriver.get(getURL());
selDriver.windowMaximize();
}
}
我在运行ANT构建时得到的堆栈跟踪是:
[junit] java.util.zip.ZipException: error in opening zip file
[junit] at java.util.zip.ZipFile.open(Native Method)
[junit] at java.util.zip.ZipFile.<init>(ZipFile.java:114)
[junit] at java.util.zip.ZipFile.<init>(ZipFile.java:131)
[junit] at org.apache.tools.ant.AntClassLoader.getResourceURL(AntClassLoader.java:1028)
[junit] at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.findNextResource(AntClassLoader.java:147)
[junit] at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.<init>
[junit]java.util.zip.ZipException:打开zip文件时出错
[junit]位于java.util.zip.ZipFile.open(本机方法)
[junit]位于java.util.zip.ZipFile(ZipFile.java:114)
[junit]位于java.util.zip.ZipFile(ZipFile.java:131)
[junit]位于org.apache.tools.ant.AntClassLoader.getResourceURL(AntClassLoader.java:1028)
[junit]位于org.apache.tools.ant.AntClassLoader$ResourceEnumeration.findNextResource(AntClassLoader.java:147)
[junit]位于org.apache.tools.ant.AntClassLoader$ResourceEnumeration。
以下是构建脚本:
<project name="MyProject" default="build-proj" basedir=".">
<property file="./build.properties" />
<path id="project.classpath">
<fileset dir="resources/drivers">
<include name="*.*" />
</fileset>
</path>
<taskdef resource="emma_ant.properties">
<classpath>
<pathelement path="${lib.dir}/emma_ant-2.1.5320.jar" />
<pathelement path="${lib.dir}/emma-2.1.5320.jar" />
</classpath>
</taskdef>
<target name="build-proj">
<antcall target="cleanup" />
<antcall target="compile" />
<antcall target="test" />
</target>
<target name="cleanup" description="clean up">
<delete dir="${build.dir}" />
<delete dir="${dist.dir}" />
<delete dir="${test.report.dir}" />
<mkdir dir="${build.dir}" />
<mkdir dir="${build.src.dir}" />
<mkdir dir="${build.test.dir}" />
</target>
<target name="compile" description="compiling all the code">
<javac srcdir="${src.dir}" destdir="${build.src.dir}" debug="true">
<classpath>
<path refid="project.classpath" />
</classpath>
</javac>
<javac srcdir="${test.dir}" destdir="${build.test.dir}" debug="true">
<classpath>
<path refid="project.classpath" />
<path path="${build.src.dir}" />
</classpath>
</javac>
</target>
<target name="test">
<junit haltonfailure="false" printsummary="true" fork="true" forkmode="once" >
<classpath>
<pathelement path="${src.dir}" />
<pathelement path="${build.src.dir}" />
<pathelement path="${build.test.dir}" />
<pathelement path="${test.data.dir}" />
<path refid="project.classpath" />
</classpath>
<formatter type="xml"/>
<batchtest todir="${test.report.dir}">
<fileset dir="${build.test.dir}">
<include name="**/*Test.class" />
</fileset>
</batchtest>
</junit>
</target>
</project>
您的类路径可能不仅包含.jar文件 ant任务“junit”只喜欢类路径元素中的.jar文件(或者更好地说,使用ant术语) 你可以尝试使用
<include name="*.jar" />
而不是
<include name="*.*" />
在您的“project.classpath”-文件集中。我不知道当您没有显示ANT构建文件时,您如何能期望得到帮助来处理ANT错误!错误显示尝试打开zip文件时出现问题,但信息不足。@SteveD抱歉,我错过了它。我已经用buildscript更新了Q。我也试过了,我保留了。因为我希望所有驱动程序信息都作为运行测试的构建的一部分保留。当我在控制台上检查时,它说:无法从E:\myProject\allResources\drivers\chromedriver.exe获取资源:java.util.zip.ZipException:打开zip文件时出错。啊,我看到您将Ant版本更新为1.8.x,对吗?已修复,您现在可以看到导致错误的文件名。而这个.exe文件正是问题所在:它不是一个jar文件,不是一个zip文件,也不是一个目录,所以它不是一个Ant“类似路径的结构”。这就是为什么会出现这个错误。