java.lang.NoSuchMethodError:'java.util.stream.Collector com.google.common.collect.ImmutableMap.toImmutableMap(java.util.function.Function

问题描述 投票:0回答:1

我是使用 Java 自动化的 Appium 新手,在添加 Maven 依赖项 org.openqa.selenium.interactions.internal 和 org.openqa.selenium.interactions.touch 后,我的测试似乎开始失败。这是代码的一部分https://imgur.com/Juy8e

我正在使用 Selenium 4.1.3

   <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>4.1.3</version>
    </dependency>

这是堆栈跟踪:

java.lang.NoSuchMethodError: 'java.util.stream.Collector com.google.common.collect.ImmutableMap.toImmutableMap(java.util.function.Function, java.util.function.Function)'

    at io.appium.java_client.remote.AppiumNewSessionCommandPayload.makeW3CSafe(AppiumNewSessionCommandPayload.java:40)
    at io.appium.java_client.remote.AppiumNewSessionCommandPayload.<init>(AppiumNewSessionCommandPayload.java:54)
    at io.appium.java_client.AppiumDriver.startSession(AppiumDriver.java:224)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:157)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:79)
    at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:87)
    at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:116)
    at com.example.Tests.BaseClass.setup(BaseClass.java:48)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:135)
    at org.testng.internal.invokers.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:65)
    at org.testng.internal.invokers.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:381)
    at org.testng.internal.invokers.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:319)
    at org.testng.TestRunner.invokeTestConfigurations(TestRunner.java:645)
    at org.testng.TestRunner.beforeRun(TestRunner.java:634)
    at org.testng.TestRunner.run(TestRunner.java:596)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:429)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:423)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:383)
    at org.testng.SuiteRunner.run(SuiteRunner.java:326)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:95)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1249)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1169)
    at org.testng.TestNG.runSuites(TestNG.java:1092)
    at org.testng.TestNG.run(TestNG.java:1060)
    at com.intellij.rt.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:66)
    at com.intellij.rt.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:109)

Test ignored.

我将错误追溯到 AppiunNewSessionCommandPayload。这是代码片段Rahttps://imgur.com/a/2QWgMRC

java maven mobile appium
1个回答
0
投票

我也有类似的问题。我发现需要添加一个依赖项:

implementation("org.seleniumhq.selenium:selenium-remote-driver:4.21.0")

之后问题就消失了。

在我的 Android 应用程序中初始化 Appium 的依赖项的完整列表:

dependencies {

    // core
    implementation("androidx.core:core-ktx:1.13.1")
    implementation("androidx.appcompat:appcompat:1.7.0")
    implementation("com.google.android.material:material:1.12.0")

    // testing
    testImplementation("junit:junit:4.13.2")
    androidTestImplementation("androidx.test.ext:junit:1.1.5")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

    // jUnit 5 (optional)
    testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.1")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.1")

    // appium setup
    testImplementation("io.appium:java-client:9.2.3")
    testImplementation("org.seleniumhq.selenium:selenium-java:4.21.0")
    testImplementation("org.seleniumhq.selenium:selenium-remote-driver:4.21.0")
}

请记住,我在现有 Android 项目中使用单独的模块通过 Kotlin DSL 进行 appium 测试。

© www.soinside.com 2019 - 2024. All rights reserved.