实例化对象时出现Appium错误

时间:2018-08-23 22:48:57

标签: java appium appium-android

这是我正在创建的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

任何线索?

1 个答案:

答案 0 :(得分:2)

在初始化appium驱动程序时

添加 MobileElement WebElement

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

还要将您的 deviceName 更改为已拒绝。另外,请确保您的 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);
}