我有一個測試類,如果我在eclipse中運行,該類的所有測試運行良好。 (右鍵單擊文件,以jUnit身份運行),但是當我嘗試使用Ant腳本運行時,它失敗。無法通過ANT運行測試
實際上這個測試是針對2個瀏覽器運行的。這項測試對IE瀏覽器運行良好。它對IE運行良好。但是測試無法針對Chrome運行。我不確定發生了什麼。 我已將所有與驅動程序有關的信息放在項目路徑的所有資源/驅動程序下。瀏覽器配置文件保存在項目的browserProfiles文件夾下。
我不確定爲什麼測試無法在Chrome中找到。
我附加了測試代碼和代碼,我嘗試在源代碼中創建webdriver和seldriver。
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>
這裏是構建腳本:
<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>
我不知道如何當您不顯示ANT構建文件時期待ANT錯誤的幫助!該錯誤顯示嘗試打開一個zip文件時出現問題,但根本沒有足夠的信息繼續。 – SteveD 2011-12-28 11:40:29
@SteveD對不起,我錯過了。我用buildscript更新了Q. – 2011-12-28 11:59:34