尝试通过ANT运行时硒的webdriver抛出异常 [英] Selenium webdriver throws exception when trying to run via ANT

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

问题描述

我是通过Eclipse运行使用硒我的UI自动化测试案例,它通过罚款没有问题。浏览器启动,测试用例的执行,当我在Eclipse中做的结果被更新。然而,当我试图通过Ant来运行它,它开始给我的异常,

java.lang.NoSuchMethodError: com.google.common.collect.Multimaps.transformValues(Lcom/google/common/collect/ListMultimap;Lcom/google/common/base/Function;)Lcom/google/common/collect/ListMultimap;

请参阅我的项目的连接结构,

参考我的Ant文件(build.xml文件),

 <?XML版本=1.0编码=UTF-8独立=无&GT?;
<,项目名称=uiAutomation默认为所有BASEDIR =><属性名=EXAMPLE.DIR值= />
<属性名=test.output值=$ {} EXAMPLE.DIR /建造/测试输出/>
<属性名=test.report值=$ {} EXAMPLE.DIR /建造/测试报告/>
<属性名=lib.dir值=$ {} EXAMPLE.DIR / lib目录/ dependentJars //><目标名称=所有取决于=prepare,编译,运行/>&所述;! - ============================================= ======================= - >
<! - 编译测试code - >
&所述;! - ============================================= ======================= - >
&所述;路径ID =compile.cp>
    <文件集DIR =$ {} lib.dir包括=*罐子。/>
    <文件集DIR =$ {} EXAMPLE.DIR / SRC /包括=log4j.properties/>
< /路径><目标NAME =prepare>
    < MKDIR DIR =$ {} EXAMPLE.DIR /建筑/班/>
    < MKDIR DIR =$ {} test.output/>
    < MKDIR DIR =$ {} test.report/>
< /目标与GT;<目标名称=编译描述=编译测试code取决于=prepare>
    <回声消息= - TestNG的编译-例子 - />
    < javac的includeantruntime =假调试=真正的叉=真实来源=1.6classpathref =compile.cpSRCDIR =$ {} EXAMPLE.DIR / SRCDESTDIR =$ {EXAMPLE.DIR } /建造/班/>
< /目标与GT;&所述;! - ============================================= ======================= - >
<! - 运行测试 - >
&所述;! - ============================================= ======================= - >&所述;路径ID =run.cp>
    <路径REFID =compile.cp/>
    < pathelement位置=$ {} EXAMPLE.DIR/>
    < pathelement位置=$ {} EXAMPLE.DIR /建筑/班/>
< /路径><目标名称=跑取决于=编译描述=运行使用TestNG任务只有-testclass并没有XML实例>
    <的taskdef classpathref =run.cpNAME =TestNG的类名=org.testng.TestNGAntTask/>
    <回声>开始测试...< /回声>
    < TestNG的classpathref =run.cpoutputdir =$ {} test.output>
        <! - < classfileset DIR =$ {} EXAMPLE.DIR /建筑/班/测试/> - >        < xmlfileset文件=$ {} EXAMPLE.DIR /src/testng.xml/>
        < sysproperty键=org.uncommons.reportng.titleVALUE =故障管理功能端到端测试/>
    < / TestNG的>
    <回声>的一些测试应该都失败了,请参阅详细信息及LT文件test.out; /回声>
< /目标与GT;
< /项目>


解决方案

的惊喜:Eclipse中,自动明白即使有重复的罐子,并能够运行测试脚本。然而,ANT不能这样做。所以,我删除了罐子com.google.common,这让我从从命令行运行测试脚本。

教训:不要有重复的.jar文件

I am running my UI automation test cases using selenium via Eclipse, it goes through fine with no problem. Browsers are launched, test cases are executed, results are updated when I do it in Eclipse. Whereas, when I tried to run it via ANT, it started giving me exception,

java.lang.NoSuchMethodError: com.google.common.collect.Multimaps.transformValues(Lcom/google/common/collect/ListMultimap;Lcom/google/common/base/Function;)Lcom/google/common/collect/ListMultimap;

See the attached structure of my project,

My ANT file(build.xml) for reference,

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="uiAutomation" default="all" basedir=".">

<property name="example.dir" value="."/>
<property name="test.output" value="${example.dir}/build/test-output"/>
<property name="test.report" value="${example.dir}/build/test-report"/>
<property name="lib.dir" value="${example.dir}/lib/dependentJars/"/>

<target name="all" depends="prepare,compile,run" />

<!-- ==================================================================== -->
<!-- Compile Test Code                                                    -->
<!-- ==================================================================== -->
<path id="compile.cp">
    <fileset dir="${lib.dir}" includes="*.jar" />
    <fileset dir="${example.dir}/src/" includes="log4j.properties"/>
</path>

<target name="prepare">
    <mkdir dir="${example.dir}/build/classes" />
    <mkdir dir="${test.output}" />
    <mkdir dir="${test.report}" />
</target>

<target name="compile" description="compile the test code" depends="prepare">
    <echo message=" -- testng-compile-examples --" />
    <javac includeantruntime="false" debug="true" fork="true" source="1.6" classpathref="compile.cp" srcdir="${example.dir}/src" destdir="${example.dir}/build/classes" />
</target>

<!-- ==================================================================== -->
<!-- Run Tests                                                            -->
<!-- ==================================================================== -->

<path id="run.cp">
    <path refid="compile.cp" />
    <pathelement location="${example.dir}" />
    <pathelement location="${example.dir}/build/classes" />
</path>

<target name="run" depends="compile" description="Run examples using testng task with just -testclass and no xml">
    <taskdef classpathref="run.cp" name="testng" classname="org.testng.TestNGAntTask" />
    <echo>Starting tests...</echo>
    <testng classpathref="run.cp" outputdir="${test.output}">
        <!-- <classfileset dir="${example.dir}/build/classes/test" /> -->

        <xmlfileset file="${example.dir}/src/testng.xml" />
        <sysproperty key="org.uncommons.reportng.title" value="Fault Management Functional End to End Test" />
    </testng>
    <echo>Some of these tests should have failed, see the file test.out for the details</echo>
</target>
</project>

解决方案

The surprise: Eclipse, understood automatically even if there are duplicate jars and was able to run the test scripts. However, ANT could not do that. So, I removed the jar com.google.common, which made me to run the test scripts from command line.

Lesson learnt: Do not have duplicate .jar files.

这篇关于尝试通过ANT运行时硒的webdriver抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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