我运行了以下代码,用于通过Appium自动化Android的简单测试:
package appiumtest;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.*;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.AppiumSetting;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.*;
import org.testng.*;
//import org.junit.*;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.*;
public class AppiumTest {
public static void main(String[] args) throws InterruptedException, MalformedURLException{
// TODO Auto-generated method stub
AppiumTest testcases = new AppiumTest();
testcases.launchtest();
}
public void launchtest() throws InterruptedException, MalformedURLException{
File app = new File("D:\\Radio\\ebayTest.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
capabilities.setCapability(CapabilityType.BROWSER_NAME,"");
capabilities.setCapability("platformname", "Android");
capabilities.setCapability(CapabilityType.VERSION,"4.4.2");
capabilities.setCapability("deviceName", "07d4bb0a00caa300");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.ebay.mobile");
capabilities.setCapability("appActivity", ".activities.eBay");
Thread.sleep(3000);
System.out.println("App launched");
WebElement signin = driver.findElement(By.id("button_sign_in"));
signin.click();
Thread.sleep(4000);
}
}
现在,在运行测试之后,我在日志和“ Appium服务器”窗口中不断看到以下错误消息:
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: The following desired capabilities are required, but were not provided: deviceName) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 200 milliseconds
为什么我看到此错误消息?我在“所需功能”中提供了正确的设备名称参数,如“ adb设备”中所示。
最佳答案
在设置所有功能之前,已使用功能初始化了驱动程序。
将此行移到AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
在此行之后capabilities.setCapability("appActivity", ".activities.eBay");
关于android - Appium:即使提供了所有相关值后,为什么在日志中仍然看到期望的容量错误?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34589596/