无法通过ANT运行测试 [英] Not able to run test through ANT

查看:150
本文介绍了无法通过ANT运行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个测试类,如果我在eclipse中运行,这个类的所有测试运行良好。 (右键单击文件,以jUnit身份运行),但是当我尝试使用Ant脚本运行时,它失败。

实际上这个测试是针对2个浏览器运行的。这项测试对IE浏览器运行良好。它对IE运行良好。但是测试无法针对Chrome运行。我不确定发生了什么。
我已将所有驱动程序相关信息置于项目路径的所有资源/驱动程序下。和浏览器配置文件,我保存在项目的browserProfiles文件夹下。



我不确定为什么测试无法在Chrome中找到。



我附加了测试代码和代码,我试图在源代码中创建webdriver和seldriver。

  package com.mytests; 

公共类MyParamTest {
私人MyWrapperForBrowser浏览器;

@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));
//更多商业逻辑..


code $ pre

和源代码

  package com.mysrc; 

import java.util。*;
import org.openqa.selenium。*;

public class MyWrapperForBrowser {

private final WebDriver webDriver;
私人WebDriverBackedSelenium selDriver;

$ b public MyWrapperForBrowser(String driver){
if(driver.equalsIgnoreCase(IE)
{
//创建webDriver,selDriver

$ {b
$ b 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.g等(使用getURL());
selDriver.windowMaximize();


运行ANT时获得的堆栈跟踪构建是:

$ $ p $ [junit] java.util.zip.ZipException:打开zip文件时出错
[junit]在java.util.zip.ZipFile.open(本地方法)
[junit]在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 =MyProjectdefault =build-projbasedir =。> 

< property file =./ build.properties/>

<路径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 =cleanupdescription =清理>
< 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 =compiledescription =编译所有代码>
< 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 =falseprintsummary =truefork =trueforkmode =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>


解决方案

可能您的classpath不仅包含.jar文件。 / p>

蚂蚁任务junit只喜欢.jar文件(或者让我们更好地说类似于结构的路径,以使用Ant术语)。



您可以尝试使用

p>

 < include name =*。jar/> 

而不是

 < include name =*。*/> 

存放在您的project.classpath文件集中。


I have a test class, all the tests of this class runs fine if I run in eclipse. (right click on the file , run as jUnit) but when I am trying to run using Ant Script it fails.

Actually this test is to be run against 2 browsers. This test runs fine against IE Chrome. It runs fine against IE. But test is not able to run against Chrome. I am not sure what's happening. All the driver related information I have placed under allresources/drivers/ of the project path. And browser profiles i have kept under browserProfiles folder of the project.

I am not sure why tests are not able to be picked up for Chrome.

I have attached test code and the code where I am trying to create webdriver and seldriver in the source code.

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..
}
}

And source code

    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();
 }
 }

The stack trace which I am getting while running the ANT build is :

[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>

Here is the build script :

<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>

解决方案

Probably your classpath contains not only .jar files.

The ant task "junit" only likes .jar files (or let's better say Path like structure, to use an Ant term) in the classpath element.

You could try to use

<include name="*.jar" />

instead of

<include name="*.*" />

in your "project.classpath"-fileset.

这篇关于无法通过ANT运行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆