Appium Java 客户端中的 NullPointerException

NullPointerException in Appium Java Client

我在尝试设置简单的 AndroidDriver 时遇到 NullPointerException

所需的代码如下 -

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.MobileElement;

import io.appium.java_client.android.AndroidElement;

import java.net.URL;
import java.net.MalformedURLException;

import org.openqa.selenium.remote.DesiredCapabilities;

public class TestAutomation {
    protected AndroidDriver<MobileElement>  driver;

    public void setup() throws MalformedURLException, InterruptedException {
        URL u = new URL("http://127.0.0.1:4723/wd/hub");

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("device", "Android");
        capabilities.setCapability("deviceName","Android");
        capabilities.setCapability("platformName","Android");

        driver = new AndroidDriver<MobileElement>(u, capabilities);
    }

    public static void main(String[] args) throws Exception {
        TestAutomation object = new TestAutomation();
        System.out.println(object);
        object.setup();
    }
}

Appium Java客户端版本为6.1.0。

已验证 Appium 服务器 运行 在本地主机上的端口 4723。

有没有我遗漏的东西?

我得到的异常如下所示 -

Exception in thread "main" java.lang.NullPointerException at io.appium.java_client.android.AndroidDriver.getCapabilities(AndroidDriver.java:209) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:669) at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42) at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1) at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:144) at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:38) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:84) at io.appium.java_client.AppiumDriver.(AppiumDriver.java:94) at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:93) at TestAutomation.setup(TestAutomation.java:22) at TestAutomation.main(TestAutomation.java:28)

您对所需功能有疑问。

appActivity and appPackage must be included.

device from your desired capabilities must be removed.

DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "My Phone");
caps.setCapability("platformName", "Android");
caps.setCapability("appPackage", "your app Package");
caps.setCapability("appActivity",
            "your app activity");;

Also update your selenium-java version to latest stable version.