我无法初始化appium驱动程序。请帮忙。
初始化时出现以下错误消息:
Exception in thread "main" java.lang.NoSuchMethodError: org.openqa.selenium.remote.http.HttpClient$Factory.createDefault()Lorg/openqa/selenium/remote/http/HttpClient$Factory;
at io.appium.java_client.remote.AppiumCommandExecutor.<init>(AppiumCommandExecutor.java:93)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:93)
at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:95)
at com.xceedance.framework.Hybrid.AppiumWebsite.main(AppiumWebsite.java:53)
我使用了以下代码-
AppiumDriver driver;
DesiredCapabilities capability = new DesiredCapabilities();
capability.setCapability("deviceName","emulator-5554");
capability.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
capability.setCapability("browserName","Chrome");
capability.setCapability("platformName","Android");
capability.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1.1");
capability.setCapability("appPackage","com.android.chrome");
capability.setCapability("appActivity", "com.google.android.apps.chrome.Main");
driver=new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capability);
答案 0 :(得分:0)
看起来像鸦片/硒的兼容性问题。寻找最新版本并尝试。
答案 1 :(得分:0)
您创建的会话不正确,可以阅读Appium official docs进行网络测试设置。
首先,请确保:
按照以下方式创建会话:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1.1");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator-5554");
capabilities.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
AppiumDriver driver=new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capability);
如果您收到类似以下的错误消息:
An unknown server-side error occurred while processing the command.
Original error: unknown error: Chrome version must be >= 55.0.2883.0
然后使用正确版本的chromedriver重新安装appium:
npm install appium --chromedriver_version="your_version"
答案 2 :(得分:0)
尝试以下代码:
import org.openqa.selenium.remote.DesiredCapabilities;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
File fs = new File("src"); //Assume your aap is inside src folder.
File appPath = new File(fs, "YourAppAPK.apk");
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "RealDeviceNameOrEmulatorName");
caps.setCapability("app",appPath.getAbsolutePath());
caps.setCapability("automationName","uiautomator2");
caps.setCapability("platformName", "android");
AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"), caps);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
// Test Actions Here
System.out.println("Android Driver Started: "+driver);
答案 3 :(得分:0)
根本原因是,与运行该方法时所使用的方法不同,您很可能已经针对缺少该方法的该方法的不同版本编译了一个类。
在堆栈跟踪中明确提到该方法不存在。如果在库中的对象上调用方法时出现异常,则很可能在编译和运行时使用库的不同版本。确保两个地方的版本都正确。
因此存在兼容性问题,并且HttpClient.Factory类属于 selenium 库,因此请检查selenium版本是否兼容