Appium因为驱动报错 [英] Appium throws an error because of the driver

查看:31
本文介绍了Appium因为驱动报错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to run automated test with appium, but I always get the following error :

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

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

I've noticed that if I delete everything from the driver declaration to the bottom, the test is successful. Here is my code :

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");
  }
}

推荐答案

我在双 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 或两者都不兼容......).

I had the the same problem on a dual appium + selenium project, which had been working fine. It stopped to work with the same exception the day I upgraded intellij... Somehow a duplicate dependency was inserted into the pom.xml. (existing org.seleniumhq.selenium in 3.141.59 and 3.6. version), of which I was not aware, which I suspect was introduced by the install and not by some missed move of me. So the source of the error was coming from this duplicate org.seleniumhq.selenium 3.6. (not compatible with either Appium 7.0.2 or com.squareup.okhttp3 or both...).

总结:

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

  1. remove the org.seleniumhq.selenium 3.6 duplicate dependency,

清空目标"目录

运行maven clean"任务.

run a "maven clean" task.

然后一切都恢复正常了.所以 appium 7.0.2、selenium 3.141.59 和 com.squareup.okhttp3 3.11.0 再次一起运行良好.

Then all was back up to work. so that appium 7.0.2, selenium 3.141.59 and com.squareup.okhttp3 3.11.0 were all doing fine together again.

这篇关于Appium因为驱动报错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆