gpt4 book ai didi

java - Appium框架: Why do I have this error message with 'driver' cannot be resolved. Selenium已安装

转载 作者:行者123 更新时间:2023-12-02 10:54:56 26 4
gpt4 key购买 nike

您好,我正在使用 testNG 创建一个 appium 框架,并且我正在复制一个拖放 android 测试以在我的框架中使用作为基本示例。

出于某种原因,“驱动程序”旁边有一条错误消息(见下文),我很困惑为什么我会得到它,因为我的 pom.xml 文件中有 selenium(见下文)。我还导入了 Selenium (也见下文)。我真的很困惑为什么我会收到这条消息。我还添加了这个问题的测试用例。

我想知道:

  • 我是否忘记将某些内容导入测试中?
  • 我是否忘记在 .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()
{

}

}

最佳答案

您必须在方法之外定义 AppiumDriver。您必须定义所需的功能。使用期望的功能,它会知道要打开哪个应用程序以及我们应该在哪个设备上运行它。您必须启用驱动程序中定义的 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
}

关于java - Appium框架: Why do I have this error message with 'driver' cannot be resolved. Selenium已安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51844801/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com