实例化对象时出现 Appium 错误

Appium error while instantiating the object

这是我创建的 BeforeClass(Java、Appium、TestNG)

私有AndroidDriver驱动;

@BeforeClass
public void setUp() throws MalformedURLException{
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    desiredCapabilities.setCapability(MobileCapabilityType.APPIUM_VERSION, "1.7.1");
    desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");
    desiredCapabilities.setCapability("deviceName", "9NLJA17619012618");
    desiredCapabilities.setCapability("appActivity", ".activity.LaunchActivity");
    desiredCapabilities.setCapability("appPackage", "com.aaa.app");     
    desiredCapabilities.setCapability("platformVersion", "7.1.2");
    URL url = new URL("http://localhost:4723/wd/hub");
    driver = new AndroidDriver(url,desiredCapabilities);
}

(我知道混合了 MobileCapabilityType 和其他没有这种格式的类型,但我认为这不是重点)

然后是一堆@Test

出现此错误:

Failed tests:   setUp(tests.TestShop): 
class io.appium.java_client.android.AndroidDriver has interface io.appium.java_client.AppiumDriver as super class

有什么线索吗?

在初始化 appium 驱动程序时添加 MobileElementWebElement

driver = new AndroidDriver<MobileElement>(url,desiredCapabilities);

同时将您的 deviceName 更改为 udid。还要确保您的 appActivity 正确。

您的代码必须如下所示:

@BeforeClass
public void setUp() throws MalformedURLException{
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    desiredCapabilities.setCapability("platformName","Android");
    desiredCapabilities.setCapability("deviceName", "Any name");
    desiredCapabilities.setCapability("udid", "9NLJA17619012618");
    desiredCapabilities.setCapability("appActivity", ".activity.LaunchActivity");
    desiredCapabilities.setCapability("appPackage", "com.aaa.app");     
    desiredCapabilities.setCapability("platformVersion", "7.1.2");
    URL url = new URL("http://localhost:4723/wd/hub");
    driver = new AndroidDriver<MobileElement>(url,desiredCapabilities);
}