问题
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");
}
}
回答1:
Solved it on my own. I converted the project into maven one and it works like a charm now.
回答2:
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...).
When I removed the org.seleniumhq.selenium 3.6 duplicate dependency, I emptied the target directory, and run a maven clean build. 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.
来源:https://stackoverflow.com/questions/55235272/appium-throws-an-error-because-of-the-driver