【问题标题】:Selenium webdriver throws exception when trying to run via ANTSelenium webdriver 在尝试通过 ANT 运行时抛出异常
【发布时间】:2014-08-01 21:25:01
【问题描述】:

我正在通过 Eclipse 使用 selenium 运行我的 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 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>

【问题讨论】:

  • Stackoverflow 是一个问答网站。因此,将问题和答案放在一篇文章中是无效的。因此,请使用 Answer your own question 发布您的答案,如stackoverflow.com/help/self-answer 所述。
  • @SebastianZartner 以问答形式发布。

标签: java eclipse ant selenium-webdriver


【解决方案1】:

惊喜:Eclipse,即使有重复的 jars 也会自动理解,并且能够运行测试脚本。然而,ANT 无法做到这一点。所以,我删除了 jar com.google.common,这让我可以从命令行运行测试脚本。

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

【讨论】:

  • 谢谢@ASANT 我也有类似的问题。有时 java -verbose:class 有助于解决此类问题。
【解决方案2】:

即使我遇到了与 Maven 构建类似的问题:

我为此编写了一个使用 Itext 库生成 PDF 的实用程序,我使用了一个可用的 maven 存储库

<dependency>
    <groupId>org.technbolts</groupId>
    <artifactId>cucumber-contrib</artifactId>
    <version>0.0.3</version>
</dependency>

导致上述问题的原因

然后我使用了依赖项

<dependency>
    <groupId>com.itextpdf</groupId>
    <artifactId>itextpdf</artifactId>
    <version>5.0.6</version>
</dependency>

现在它可以正常工作了......所以吸取的教训选择正确的依赖关系。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-16
    • 2012-02-23
    • 2013-02-22
    • 2018-07-14
    • 2017-07-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多