Appium:即使我提供了所有相关值,为什么我在日志中看到了所需的容量错误?

时间:2016-01-04 10:59:12

标签: android appium

我运行以下代码,通过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 devices”中所示。

1 个答案:

答案 0 :(得分:2)

在设置所有功能之前,您已使用功能初始化驱动程序。

移动此行AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities); 在此行之后capabilities.setCapability("appActivity", ".activities.eBay");