Appium由于驱动程序而引发错误

时间:2019-03-19 07:02:30

标签: java selenium appium

我正在尝试使用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");
  }
}

1 个答案:

答案 0 :(得分:0)

Solved it on my own. I converted the project into maven one and it works like a charm now.