gpt4 book ai didi

java - Appium Webdriver 导入问题

转载 作者:行者123 更新时间:2023-12-02 11:06:32 27 4
gpt4 key购买 nike

使用 Java 为 Android 构建基本的 Appium 测试。

当我运行代码时,它给我一个异常错误:

Exception in thread "main" java.lang.Error: Unresolved compilation problems:

driver cannot be resolved

driver cannot be resolved

driver cannot be resolved to a variable

at tests.AppiumTest.main(AppiumTest.java:50)

我已经三重检查了我的 jar 文件,所有这些文件似乎都包含在内,并且我没有遗漏任何文件,但是当我将鼠标悬停在驱动程序文本上时,导入 Webdriver 选项不会出现。

代码如下:

package tests;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;


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

public class AppiumTest {

public static void main(String[] args) {

//Set the Desired Capabilities
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "My Phone");
caps.setCapability("udid", "Redacted"); //Give Device ID of your mobile phone
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "7.1.1");
caps.setCapability("appPackage", "com.android.vending");
caps.setCapability("appActivity", "com.google.android.finsky.activities.MainActivity");
caps.setCapability("noReset", "true");

// Instagram: com.instagram.android/com.instagram.android.activity.MainTabActivity
// Facebook: com.facebook.katana/com.facebook.katana.LoginActivity

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

} catch (MalformedURLException e) {
System.out.println(e.getMessage());
}

//Added 5 seconds wait so that the app loads completely before starting with element identification
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}

//Find Google Play element using ID property and click on it
driver.findElement(By.id("com.android.vending:id/search_box_idle_text")).click();

//Find 'Google Play Store' element and set the value Google
driver.findElement(By.id("com.android.vending:id/search_box_text_input")).sendKeys("Google");

//Press Enter key from Keyboard using any of the below methods
((AndroidDriver<MobileElement>) driver).pressKeyCode(66);
}

}

导入jar文件的截图:

1

2

最佳答案

首先,您没有显示 AndroidDriver 的声明位置。

第二件事是我没有在你的依赖项 Appium 中看到,你只是导入了 selenium。

appium.io

如果使用 maven,你的 pom 中应该有类似这样的内容:

https://mvnrepository.com/artifact/io.appium/java-client/6.0.0

<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>6.0.0</version>
</dependency>

我的依赖:

enter image description here

希望这有帮助...

关于java - Appium Webdriver 导入问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50919134/

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