无法创建新会话。 (原始错误:命令失败:)Appium错误

时间:2017-09-13 06:29:06

标签: appium

我正在为Android设备进行自动化测试。 在模拟器中它工作正常。连接到设备时,它创建&安装unlock.apk到Android设备。之后出现以下错误enter image description here

我已在下面设置了配置    DesiredCapabilities capabilities = DesiredCapabilities.android();         capabilities.setCapability(MobileCapabilityType.BROWSER_NAME,"");

       capabilities.setCapability("deviceName", "Moto C Plus");
    //capabilities.setCapability("deviceName", "ZZ22cdddP9");
    //  capabilities.setCapability("udid", "ZZ22cdddP9");
    capabilities.setCapability("platformVersion", "7.0");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("browserName", "chrome");
    //capabilities.setCapability("Device Id", "xxxxxxxx");
          capabilities.setCapability("app", "D:\\abc.apk");
    capabilities.setCapability("appPackage", "com.s.abc"); 
    capabilities.setCapability("appActivity", "com.s.sn");

3 个答案:

答案 0 :(得分:1)

谢谢Shiv&维诺德,

最后解决了那些问题..我把错误的活动名称。所以它被关闭了。通过设置以下功能,它可以正常运行.setCapability(" appActivity"," com.example.main.LaunchActivity");



capabilities.setCapability("deviceName", "ZZ22cdddP9");
   capabilities.setCapability("platformVersion", "7.0");
   capabilities.setCapability("platformName", "Android");
   capabilities.setCapability("app", "D:\\abc.apk");
   capabilities.setCapability("appPackage", "com.s.abc"); 
   capabilities.setCapability("appActivity", "com.example.main.LaunchActivity");




答案 1 :(得分:0)

在初始化appium驱动程序之前添加以下代码。

String cmd = "adb shell getprop ro.build.version.release";

String osVersion=executeCommand(cmd);

if(osVersion.contains("7"))
{
    //uninstall io.appium.settings
    cmd="adb uninstall  io.appium.settings";
    executeCommand(cmd);

    //uninstall io.appium.unlock
    cmd="adb uninstall  io.appium.unlock";
    executeCommand(cmd);

}

public String executeCommand(String cmd)
{
    String commandresponse="";
    try
    {
        Runtime run = Runtime.getRuntime();
        Process proc=run.exec(cmd);
        BufferedReader stdInput = new BufferedReader(new 
                InputStreamReader(proc.getInputStream()));

    BufferedReader stdError = new BufferedReader(new 
            InputStreamReader(proc.getErrorStream()));

    String response=null;
    while ((response = stdInput.readLine()) != null) 
    {
        if(response.length()>0)
        {
            commandresponse=commandresponse+response;
        }
    }

    while ((response = stdError.readLine()) != null) 
    {
        commandresponse=commandresponse+response;

    }
}
catch(Exception e)
{
    e.printStackTrace();
}
//System.out.println(commandresponse);
return commandresponse;

}

答案 2 :(得分:0)

Set following capabilities only and try to start appium :
Note : deviceName should be name which we will get using "adb devices" command.

   capabilities.setCapability("deviceName", "ZZ22cdddP9");
   capabilities.setCapability("platformVersion", "7.0");
   capabilities.setCapability("platformName", "Android");
   capabilities.setCapability("app", "D:\\abc.apk");
   capabilities.setCapability("appPackage", "com.s.abc"); 
   capabilities.setCapability("appActivity", "com.s.sn");