Appium框架:为什么我的“驱动程序”出现此错误消息无法解决。硒已安装

时间:2018-08-14 15:21:11

标签: java automation frameworks appium

嗨,我正在用testNG创建一个appium框架,我正在复制一个拖放Android测试以在我的框架中用作基本示例。

由于某种原因,“驱动程序”旁边有一条错误消息(请参阅下文),我很困惑为什么要这样做,因为pom.xml文件中包含了硒(请参阅下文)。我也进口了硒(也见下文)。我真的很困惑为什么收到此消息。我还将这个问题添加到测试用例中。

我想知道:

  • 我忘了将某些内容导入测试吗?
  • 我是否忘记在.pom xml文件中添加一些内容?
  • 为什么出现以下错误消息 它源自的测试工作完美(我创建了该测试 也)?

enter image description here

Pom xml文件

<dependencies>

  <!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
    <groupId>io.appium</groupId>
    <artifactId>java-client</artifactId>
    <version>5.0.4</version>
</dependency>
  <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.11.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
    <groupId>org.testng</groupId>
    <artifactId>testng</artifactId>
    <version>6.11</version>
    <scope>test</scope>
</dependency>


  </dependencies>    <artifactId>testng</artifactId>
    <version>6.11</version>
    <scope>test</scope>
</dependency>


  </dependencies>
</project> 

测试

package android;



import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.net.MalformedURLException;
import java.time.Duration;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.interactions.touch.TouchActions;

import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import org.openqa.selenium.WebDriver;

public class Dragndroptest  extends invoke {

             //Given I am on the Home screen 
             //When I  tap Views   
             //Then I will see the View menu 
             //When I am in the 'view menu' I will select 'drag n drop'
             //Then I will see 3 dots  
             //When  I select a dot and drag it
             //Then I will drop it on the dot below


    @BeforeTest
    public void Cookies() throws MalformedURLException
    {

          AndroidDriver<AndroidElement> driver =Capabilities();

        driver.findElementByAccessibilityId("Views").click();


    }

    @Test
    public void dragnddrop()
    {

        //tap syntax using TOUCHACTIONS
                TouchAction t = new TouchAction (driver);
                t.tap(driver.findElementByAccessibilityId("Drag and Drop")).perform();


                //Drag & Drop Syntax 

                t.longPress(driver.findElementById("io.appium.android.apis:id/drag_dot_1")).
                moveTo(driver.findElementById("io.appium.android.apis:id/drag_dot_3")).release().perform();


    }


    @AfterTest
    public void Testtitle here()
    {

    }

}

1 个答案:

答案 0 :(得分:1)

您必须在方法之外定义AppiumDriver。您必须定义所需的功能。使用desireCapabilities,它将知道要打开哪个应用程序以及应该在哪个设备上运行它。您必须启用驱动程序中定义的appium服务器。

public class Dragndroptest  extends invoke {

    AppiumDriver<MobileElement> driver;

    @BeforeSuite(alwaysRun=true)
    public void setupDesiredCaps(){
    DesiredCapabilities caps = new DesiredCapabilities();

    caps.setCapability("deviceName", "Any name");
    caps.setCapability("udid", "your device udid");
    caps.setCapability("platformName", "Android");
    caps.setCapability("platformVersion", "your device platform version");
    caps.setCapability("appPackage", "your app Package name");
    caps.setCapability("appActivity", "your app's main package name");

    driver = new AndroidDriver<MobileElement>(new URL(
                "http://127.0.0.1:4723/wd/hub"), caps);
    }

 //your other code after it
 }