[英]Selenium webdriver throws exception when trying to run via ANT
I am running my UI automation test cases using selenium via Eclipse, it goes through fine with no problem. 我正在使用Eclipse运行我的UI自动化测试用例,它没有任何问题。 Browsers are launched, test cases are executed, results are updated when I do it in Eclipse.
启动浏览器,执行测试用例,在Eclipse中执行时更新结果。 Whereas, when I tried to run it via ANT, it started giving me exception,
然而,当我试图通过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;
See the attached structure of my project, 查看我项目的附件结构,
My ANT file(build.xml) for reference, 我的ANT文件(build.xml)供参考,
<?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. 令人惊讶的是:即使有重复的jar并且能够运行测试脚本,Eclipse也会自动理解。 However, ANT could not do that.
但是,ANT无法做到这一点。 So, I removed the jar com.google.common, which made me to run the test scripts from command line.
所以,我删除了jar com.google.common,这使我从命令行运行测试脚本。
Lesson learnt: Do not have duplicate .jar files. 获得的经验:没有重复的.jar文件。
Even i got Similar issue with Maven build : 即使我有与Maven构建类似的问题:
I have written a utility to generate PDF using Itext library for this i have used one of the available maven repository 我已经编写了一个使用Itext库生成PDF的实用程序,我使用了一个可用的maven存储库
<dependency>
<groupId>org.technbolts</groupId>
<artifactId>cucumber-contrib</artifactId>
<version>0.0.3</version>
</dependency>
Which was causing the above issue 这导致了上述问题
Then i have used dependency 然后我使用了依赖
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.0.6</version>
</dependency>
Now its working correctly ... So Lesson learnt choose correct dependency . 现在它正常工作......所以课程学习选择正确的依赖。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.