jav*_*thu 2 ant junit selenium google-chrome webdriver
我有一个测试类,如果我在eclipse中运行,这个类的所有测试都运行正常.(右键单击该文件,以jUnit身份运行)但是当我尝试使用Ant脚本运行时,它会失败.
实际上这个测试是针对2个浏览器运行的.此测试对IE Chrome运行良好.它对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..
}
}
Run Code Online (Sandbox Code Playgroud)
和源代码
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();
}
}
Run Code Online (Sandbox Code Playgroud)
我在运行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>
Run Code Online (Sandbox Code Playgroud)
这是构建脚本:
<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>
Run Code Online (Sandbox Code Playgroud)
您的类路径可能不仅包含.jar文件.
ant任务"junit"只在classpath元素中喜欢.jar文件(或者更好地说使用类似路径的结构,使用Ant术语).
你可以尝试使用
<include name="*.jar" />
Run Code Online (Sandbox Code Playgroud)
代替
<include name="*.*" />
Run Code Online (Sandbox Code Playgroud)
在你的"project.classpath" - 文件集中.
| 归档时间: |
|
| 查看次数: |
2719 次 |
| 最近记录: |