找不到我为 DesiredCapabilities 创建的对象 class

Not able to find my object created for DesiredCapabilities class

我已经开始在 Android 构建我的第一个 Appium 测试,为此,我开始编写我的代码。

我实例化了我的 DesiredCapabilities 对象,但是当我尝试使用该引用时,我看不到该引用。

Link 问题图片:

以下是为我的项目添加的依赖项:

  <dependencies>
    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.13.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/io.appium/java-client -->
    <dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>6.1.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.testng/testng -->
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.14.3</version>
        <scope>test</scope>
    </dependency>

  </dependencies>

请帮助我了解缺少的内容,以便继续进行编码。 是否遗漏了任何我需要关联的罐子?

在class中不能直接使用引用访问方法,因为没有执行入口点。您必须在 methodconstructorblock(static/non-static) 中编写代码。请参考以下示例:

方式一

    DesiredCapabilities capabilities =DesiredCapabilities.android();

    public FirstDemoClass() {
        // TODO Auto-generated constructor stub
        capabilities.setCapability("deviceName", "emulator-5554");
    }

方式二

    DesiredCapabilities capabilities =DesiredCapabilities.android();

   // method
    public void setCapabilities() {

        capabilities.setCapability("deviceName", "emulator-5554");
    }

方式三

    static DesiredCapabilities capabilities = DesiredCapabilities.android();

    // block
    static {
        capabilities.setCapability("deviceName", "emulator-5554");
    }

    public static void main(String[] args) {

    }

这应该有效。如果有任何事情请告诉我。

初始化您的设备功能,例如

public class FirstDemoClass{

  public static void main(String[] args){

    AppiumDriver<WebElement> driver;   
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("deviceName", "Android phone");
    caps.setCapability("udid", "your device unique id");
    caps.setCapability("platformName", "Android");
    caps.setCapability("platformVersion", "phone version");
    caps.setCapability("appPackage", appPackage);
    caps.setCapability("appActivity", appActivity);
    driver=new AndroidDriver<WebElement>(new URL(
        "http://127.0.0.1:4723/wd/hub"), caps);
  }
}