【问题标题】:NoSuchMethodError in appiumappium中的NoSuchMethodError
【发布时间】:2014-12-17 22:47:32
【问题描述】:

在设置我的第一个 appium 项目后,我得到了java.lang.NoSuchMethodError 代码很简单,在这一行失败了:

  driver = new AppiumDriver(new URL("http://x.x.x.x:4723/wd/hub"), capabilities);   

轨迹是:

java.lang.NoSuchMethodError: com.google.common.base.Joiner$MapJoiner.appendTo(Ljava/lang/StringBuilder;Ljava/lang/Iterable;)Ljava/lang/StringBuilder;
    at com.google.common.net.MediaType.toString(MediaType.java:674)
    at org.openqa.selenium.remote.http.JsonHttpCommandCodec.encode(JsonHttpCommandCodec.java:197)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:152)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:572)

我的 pom.xml 是:

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>LATEST</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>1.2.1</version>
    </dependency>
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.6</version>
        <scope>test</scope>
    </dependency>
    <!-- Includes the Sauce JUnit helper libraries 
    <dependency>
        <groupId>com.saucelabs</groupId>
        <artifactId>sauce_junit</artifactId>
        <version>1.0.18</version>
        <scope>test</scope>
    </dependency>-->
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.2.4</version>
    </dependency>
</dependencies>

我google了一下,有人说我用的是旧的guava.jar,但是我反编译guava-15.0.jar,发现存在Joiner.appendTo(StringBuilder, Iterable),为什么总是显示这个错误?

@Before
  public void setUp() throws Exception {
    // set up appium
    final File classpathRoot = new File(System.getProperty("user.dir"));
    final File appDir = new File(classpathRoot, "../../../apps/ContactManager");
    final File app = new File(appDir, "ContactManager.apk");
    final DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("deviceName", "Android Emulator");
    capabilities.setCapability("platformVersion", "4.4");
    capabilities.setCapability("app", app.getAbsolutePath());
    capabilities.setCapability("appPackage",
        "com.example.android.contactmanager");
    capabilities.setCapability("appActivity", ".ContactManager");
    driver = new AndroidDriver(new URL("http://x.x.x.x:4723/wd/hub"),
        capabilities);
  }

同样在运行命令“mvn -U clean test”后,我可以看到这个错误

Tests in error:        
addContact(com.saucelabs.appium.AndroidContactsTest):com.google.common.base.Joiner$MapJoiner.appendTo(Ljava/lang/StringBuilder;Ljava/lang/Iterable;)Ljava/lang/StringBuilder;
addContact(com.saucelabs.appium.AndroidContactsTest)
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0

只有一个名为 addContact 的测试用例,为什么它一直显示 Test run: 2?通过调试,发现是在运行“driver.quit()”这句话的时候出现的,去掉这个方法后,显示Test run: 1

依赖树在下面列出,除了 guava-17.0,我没有看到任何关于 MapJoiner 的信息,实际上我可以在这个 jar 文件中找到 MapJoiner.appendTo(Stringbuilder, iterate)

[INFO] com.lvntest.appium:sauce_appium_junit:jar:0.0.1-SNAPSHOT
[INFO] +- junit:junit:jar:4.11:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.seleniumhq.selenium:selenium-java:jar:2.43.1:test
[INFO] |  +- org.seleniumhq.selenium:selenium-chrome-driver:jar:2.43.1:test
[INFO] |  |  \- org.seleniumhq.selenium:selenium-remote-driver:jar:2.43.1:test
[INFO] |  |     +- cglib:cglib-nodep:jar:2.1_3:test
[INFO] |  |     \- org.seleniumhq.selenium:selenium-api:jar:2.43.1:test
[INFO] |  +- org.seleniumhq.selenium:selenium-htmlunit-driver:jar:2.43.1:test
[INFO] |  |  \- net.sourceforge.htmlunit:htmlunit:jar:2.15:test
[INFO] |  |     +- xalan:xalan:jar:2.7.1:test
[INFO] |  |     |  \- xalan:serializer:jar:2.7.1:test
[INFO] |  |     +- commons-collections:commons-collections:jar:3.2.1:test
[INFO] |  |     +- org.apache.commons:commons-lang3:jar:3.3.2:test
[INFO] |  |     +- org.apache.httpcomponents:httpmime:jar:4.3.3:test
[INFO] |  |     +- net.sourceforge.htmlunit:htmlunit-core-js:jar:2.15:test
[INFO] |  |     +- xerces:xercesImpl:jar:2.11.0:test
[INFO] |  |     |  \- xml-apis:xml-apis:jar:1.4.01:test
[INFO] |  |     +- net.sourceforge.nekohtml:nekohtml:jar:1.9.21:test
[INFO] |  |     +- net.sourceforge.cssparser:cssparser:jar:0.9.14:test
[INFO] |  |     |  \- org.w3c.css:sac:jar:1.3:test
[INFO] |  |     \- org.eclipse.jetty:jetty-websocket:jar:8.1.15.v20140411:test
[INFO] |  |        +- org.eclipse.jetty:jetty-util:jar:8.1.15.v20140411:test
[INFO] |  |        +- org.eclipse.jetty:jetty-io:jar:8.1.15.v20140411:test
[INFO] |  |        \- org.eclipse.jetty:jetty-http:jar:8.1.15.v20140411:test
[INFO] |  +- org.seleniumhq.selenium:selenium-firefox-driver:jar:2.43.1:test
[INFO] |  |  +- commons-io:commons-io:jar:2.4:test
[INFO] |  |  \- org.apache.commons:commons-exec:jar:1.1:test
[INFO] |  +- org.seleniumhq.selenium:selenium-ie-driver:jar:2.43.1:test
[INFO] |  |  +- net.java.dev.jna:jna:jar:3.4.0:test
[INFO] |  |  \- net.java.dev.jna:platform:jar:3.4.0:test
[INFO] |  +- org.seleniumhq.selenium:selenium-safari-driver:jar:2.43.1:test
[INFO] |  +- org.seleniumhq.selenium:selenium-support:jar:2.43.1:test
[INFO] |  \- org.webbitserver:webbit:jar:0.4.15:test
[INFO] |     \- io.netty:netty:jar:3.5.5.Final:test
[INFO] +- io.appium:java-client:jar:2.0.0:compile
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.3.3:compile
[INFO] |  |  +- org.apache.httpcomponents:httpcore:jar:4.3.2:compile
[INFO] |  |  +- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] |  |  \- commons-codec:commons-codec:jar:1.6:compile
[INFO] |  +- com.google.guava:guava:jar:17.0:compile
[INFO] |  +- cglib:cglib:jar:3.1:compile
[INFO] |  |  \- org.ow2.asm:asm:jar:4.2:compile
[INFO] |  \- org.reflections:reflections:jar:0.9.8:compile
[INFO] |     +- javassist:javassist:jar:3.12.1.GA:compile
[INFO] |     \- dom4j:dom4j:jar:1.6.1:compile
[INFO] +- com.googlecode.json-simple:json-simple:jar:1.1.1:test
[INFO] +- commons-lang:commons-lang:jar:2.6:test
[INFO] +- com.saucelabs:sauce_junit:jar:2.1.10:compile
[INFO] |  +- com.saucelabs:sauce_java_common:jar:2.1.10:compile
[INFO] |  \- com.saucelabs:saucerest:jar:1.0.22:compile
[INFO] |     \- org.json:json:jar:20090211:compile
[INFO] \- com.google.code.gson:gson:jar:2.3:compile

【问题讨论】:

  • 堆栈跟踪表明问题不在Joiner.appendTo 中,而是在Joiner 的'Joiner$MapJoiner.appendTo, that is a MapJoiner` 嵌套类中。你验证了吗?
  • 是的,该方法存在,我很困惑...有人请帮助 com.google.common.base.Joiner$MapJoiner.appendTo(java.lang.StringBuilder, java.lang.Iterable ) : java.lang.StringBuilder [9]

标签: java maven appium


【解决方案1】:

您使用的是哪个版本的硒?

通过以下方式之一编辑您的 pom.xml..

    <dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>2.0.0</version>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>LATEST</version>
    </dependency>

对于上述依赖项,使用 AndroidDriver() 代替 AppiumDriver() 或将以下内容与 AppiumDriver() 一起使用

    <dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>1.5.0</version>
    </dependency>

    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.42.2</version>
    </dependency>

干杯

【讨论】:

  • 我使用 2.0.0 java-client 和最新的 selenium,关闭其他项目,只保持这个项目打开,然后运行测试,但仍然得到这个错误......可能是一些依赖使用旧版本的番石榴,但我无法一一检查,因为大约有 20 个 jar 文件需要检查。我该怎么解决?
  • 感谢您的重播。我已经添加了设置代码。实际上,我只是把所有的示例代码都git了,然后在eclipse上导入这个maven项目,然后就出现了错误。
  • java-client 版本为:2.0.0 ,selenium-java 版本为:2.43.1
【解决方案2】:

这是 selenium 和 appium 版本不匹配的问题。即使两者的最新版本也可能导致此类错误。您可以在下面找到最新的匹配版本:

'io.appium:java-client:5.0.1'
'org.seleniumhq.selenium:selenium-java:3.4.0'

随时使用最新的匹配版本编辑此答案。

【讨论】:

    猜你喜欢
    • 2018-09-23
    • 2016-02-09
    • 2019-12-11
    • 2017-03-11
    • 1970-01-01
    • 1970-01-01
    • 2012-09-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多