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

时间:2018-07-26 03:06:31

标签: selenium automation appium desiredcapabilities

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

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

问题链接到图像:

enter image description here

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

  <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>

请帮助我缺少的内容,以帮助进行编码。 我需要关联任何遗漏的罐子吗?

2 个答案:

答案 0 :(得分:3)

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

我要

    DesiredCapabilities capabilities =DesiredCapabilities.android();

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

方法II

    DesiredCapabilities capabilities =DesiredCapabilities.android();

   // method
    public void setCapabilities() {

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

方法III

    static DesiredCapabilities capabilities = DesiredCapabilities.android();

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

    public static void main(String[] args) {

    }

这应该有效。让我知道那里是否有东西。

答案 1 :(得分:0)

初始化设备功能,例如

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);
  }
}