【问题标题】:Appium throws an error because of the driverAppium 因驱动报错
【发布时间】:2020-04-02 17:28:47
【问题描述】:

我正在尝试使用 appium 运行自动化测试,但我总是收到以下错误:

FAILED: f
java.lang.NoSuchMethodError: org.openqa.selenium.remote.http.HttpClient$Factory.createDefault()Lorg/openqa/selenium/remote/http/HttpClient$Factory;

我注意到,如果我删除了从驱动程序声明到底部的所有内容,则测试成功。这是我的代码:

package test;
import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.BrowserType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class FirstTest {
  @Test
  public void f() throws MalformedURLException, InterruptedException {

        new DesiredCapabilities();
        //Set the Desired Capabilities
        DesiredCapabilities caps = new DesiredCapabilities();

        caps.setCapability(MobileCapabilityType.BROWSER_NAME, BrowserType.CHROME);
        caps.setCapability(MobileCapabilityType.PLATFORM_NAME , Platform.ANDROID);
        caps.setCapability(MobileCapabilityType.DEVICE_NAME, "My Phone");
        caps.setCapability("udid", "K6T6R16C01001259"); //Give Device ID of your mobile phone
        caps.setCapability("platformName", "Android");
        caps.setCapability(MobileCapabilityType.VERSION, "7.0");
        caps.setCapability("appPackage", "com.android.chrome");
        caps.setCapability("appActivity", "com.google.android.apps.chrome.Main");
        caps.setCapability("noReset", "true");


        //Instantiate Appium Driver
        AppiumDriver<MobileElement> driver = null;
        try {
            driver = new AndroidDriver<MobileElement>(new URL("http://0.0.0.0:4723/wd/hub"), caps);

        } catch (MalformedURLException e) {
            System.out.println(e.getMessage());
        }
        driver.get("http://www.google.com");
  }
}

【问题讨论】:

  • 我很确定您不需要 appPackage 和 appActivity 来使用 appium 进行浏览器测试。为什么要指定 platformName 2 次?
  • 可能是错误的。我是新来的。
  • 你的测试怎么样?
  • 你给browser.type && appPackage,launchable activity都给了,应该只有一个可以用
  • @SameerArora 我正在使用 TestNG。我已启用 USB 调试,并且设备已连接并解锁,没有正在运行的应用程序。

标签: java selenium appium


【解决方案1】:

我自己解决了。我将项目转换为 maven 项目,现在它就像一个魅力。

【讨论】:

    【解决方案2】:

    我在双 appium + selenium 项目中遇到了同样的问题,该项目运行良好。 在我升级intellij的那天,它停止工作,但出现同样的异常...... 不知何故,一个重复的依赖项被插入到 pom.xml 中。 (现有 org.seleniumhq.selenium 在 3.141.59 和 3.6. 版本中),我不知道,我怀疑它是由安装引入的,而不是我错过的一些动作。 所以错误的根源来自这个重复的 org.seleniumhq.selenium 3.6。 (与 Appium 7.0.2 或 com.squareup.okhttp3 或两者都不兼容...)。

    总结:

    1. 移除 org.seleniumhq.selenium 3.6 重复依赖,

    2. 清空“目标”目录

    3. 运行“maven clean”任务。

    然后一切恢复正常。 这样 appium 7.0.2、selenium 3.141.59 和 com.squareup.okhttp3 3.11.0 又一起正常运行了。

    【讨论】:

      猜你喜欢
      • 2017-04-04
      • 2014-08-22
      • 2020-05-15
      • 2017-01-30
      • 1970-01-01
      • 1970-01-01
      • 2021-06-27
      • 1970-01-01
      • 2022-12-19
      相关资源
      最近更新 更多