在Java中为Android构建基本的Appium测试 .
当我运行代码时,它给我一个异常错误:
线程“main”中的异常java.lang.Error:未解决的编译问题:驱动程序无法解析驱动程序无法解析驱动程序无法解析为test.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 回答
首先,您没有显示声明AndroidDriver的位置 .
第二件事是我没有看到你的依赖药Appium,你只需要进口硒 .
如果使用maven,你应该在你的pom中有这样的东西:
https://mvnrepository.com/artifact/io.appium/java-client/6.0.0
我的依赖:
希望这可以帮助...