由于找不到对象属性文件,测试失败

时间:2018-08-08 09:40:39

标签: selenium batch-file testng

我有用Selenium,Appium和TestNG编写的移动自动化测试用例。

从Eclipse运行时,调用测试用例工作正常,但是当我通过调用testng.xml来运行批处理脚本时,测试失败,因为它找不到对象属性文件。

并由于以下错误堆栈而失败

java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.toImmutableSet()Ljava/util/stream/Collector;
    at org.openqa.selenium.remote.ProtocolHandshake.streamW3CProtocolParameters(ProtocolHandshake.java:284)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:149)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:142)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:174)
    at com.xyz.xya.LeadTest.Launchapplication(RetailKeywords.java:47)
    at com.xyz.xya.LeadTest.readData(RetailExecuteLead.java:111)
    Suppressed: java.io.IOException: Incomplete document
        at com.google.gson.stream.JsonWriter.close(JsonWriter.java:527)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:167)
        ... 35 more
... Removed 27 stack 

2 个答案:

答案 0 :(得分:0)

如果要从终端模式或批处理模式运行测试,请使用Maven Surefire插件。另外,请确保像这样在pom.xml的build标记内提及测试资源。

<build>
  <testResources>
    <testResource>
      <directory>src/test/resources</directory>
      <filtering>false</filtering>
    </testResource>
  </testResources>
</build>

现在,每当必须加载属性文件时,都可以使用某种InputStream进行加载。或者只是使用File类。

InputStream is = getClass().getResourceAsStream("/object.properties");

以上内容的作用是,在构建期间,maven知道从何处选择资源文件。而且,由于您已经在pom中提到了资源,因此可以直接使用classpath获取文件,而无需直接使用文件系统。

答案 1 :(得分:0)

@ SteroidKing666非常感谢您的指导。 您怀疑这是由于番石榴的多个版本冲突造成的,我有17.0和21.0

我删除了17.0并保留了21.0版本,然后才可以使用。

相关问题