【问题标题】:Getting "Original error: Could not find a connected Android device" error when using Appium with webdriver/sikuli将 Appium 与 webdriver/sikuli 一起使用时出现“原始错误:找不到连接的 Android 设备”错误
【发布时间】:2015-09-07 19:39:23
【问题描述】:

在单独的项目中尝试时,Appium 运行良好。但是当我与 WebDriver/Sikuli 一起使用时,会出现以下异常,

org.openqa.selenium.SessionNotCreatedException:无法创建新会话。 (原始错误:找不到已连接的 Android 设备。)

我的代码是:

public class HelloAppium {
static AppiumDriver appiumDriver;
static WebDriver driver;
static AndroidDriver androidDriver;

public static void main(String[] args) throws InterruptedException, MalformedURLException {

    
    AppiumServerUtils aServer = new AppiumServerUtils();
    aServer.startServer();
    System.out.println("Started");
    
    setUp();
            
    WebElement ele =  androidDriver.findElement(By.id("com.android.device:id/editPin"));
    ele.click();
    ele.sendKeys("1111");
    ele.clear();
    
    ele.sendKeys("");
    androidDriver.hideKeyboard();
            
    aServer.stopServer();
    
}

private static void setUp() throws MalformedURLException {
    DesiredCapabilities mDesiredCapabilities = new DesiredCapabilities();
    mDesiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
    mDesiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Moto X");
    mDesiredCapabilities.setCapability(MobileCapabilityType.APP_PACKAGE, "net.android.device");
    mDesiredCapabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, "com.android.launcher.Main");
    mDesiredCapabilities.setCapability(MobileCapabilityType.APP_WAIT_ACTIVITY, "com.android.tools.remotecontrol.dialogs.Authentication");
    
    mDesiredCapabilities.setCapability(MobileCapabilityType.VERSION, "4.4.4");
    
    driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), mDesiredCapabilities);
    androidDriver = (AndroidDriver)driver;
    appiumDriver = (AppiumDriver)driver;
    driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
    androidDriver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
    appiumDriver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
    
}

}

启动 Appium 的命令行代码是,

public class AppiumServerUtils {

public  void startServer(){
    CommandLine command = new CommandLine("cmd");
    command.addArgument("/c",false);
    command.addArgument("F:\\Softwares\\Selenium\\Appium\\AppiumForWindows-1.2.4.1\\Appium\\node.exe",false);
    command.addArgument("F:\\Softwares\\Selenium\\Appium\\AppiumForWindows-1.2.4.1\\Appium\\node_modules\\appium\\bin\\appium.js", false);
    command.addArgument("--address",false);
    
    command.addArgument("127.0.0.1",false);
    command.addArgument("--port",false);
    command.addArgument("4723",false);
    command.addArgument("--bootstrap-port",false);
    command.addArgument("4724",false);
    command.addArgument("--selendroid-port",false);
    command.addArgument("8082",false); 
    command.addArgument("--no-reset",false);
    command.addArgument("--local-timezone",false);
    command.addArgument("--log",false);
    command.addArgument("F:\\Softwares\\Selenium\\Appium\\appiumServerLogs.txt",false);
    DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
    DefaultExecutor executor = new DefaultExecutor();
    executor.setExitValue(1);


    InputStream is = new InputStream() {
        @Override
        public int read() throws IOException {
            return 0;
        }
    };

    try{
        //code for looking Appium server logs
        //executor.getStreamHandler().setProcessOutputStream(is);
        
        executor.execute(command, resultHandler);
        
        for(int i=1;i<=10;i++){
            if(new File("F:\\Softwares\\Selenium\\Appium\\appiumServerLogs.txt").length()!=0){
                System.out.println("file size is not Zero ");
                break;
            }
                            
            System.out.println("file size is Zero ");
                Thread.sleep(4000);
            
        }

    }catch(IOException e){
        e.printStackTrace();
    }
    catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

public  void stopServer(){

    CommandLine command = new CommandLine("cmd");
    command.addArgument("/c");
    command.addArgument("taskkill");
    command.addArgument("/F");
    command.addArgument("/IM");
    command.addArgument("node.exe");

    DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
    DefaultExecutor executor = new DefaultExecutor();
    executor.setExitValue(1);

    try {
        executor.execute(command, resultHandler);
    } catch (IOException e) {
        e.printStackTrace();
    }


}

}

日志:

[36minfo[39m: [37m-->[39m [37mPOST[39m [37m/wd/hub/session[39m [90m{“desiredCapabilities”:{“platformName”:“Android”,“deviceName”:” Moto X","appActivity":"com.android.launcher.Main","appWaitActivity":"com.android.tools.remotecontrol.dialogs.Authentication","appPackage":"net.android.device","version ":"4.4.4"}}[39m [36minfo[39m: [debug] 提供了以下所需功能,但 appium 无法识别。它们将被传递到此服务器上运行的任何其他服务。 : 版本 [36minfo[39m: [debug] 没有获得应用程序但确实获得了 Android 包,将尝试在设备上启动它 [36minfo[39m: [debug] 创建新的 appium 会话 adee76d7-4d68-46a7-96d2-ae617d5a900d [36minfo[39m: 启动 android appium [36minfo[39m: [debug] 使用快速重置? false [36minfo[39m: [debug] 正在为会话准备设备 [36minfo[39m: [debug] 不检查应用程序是否存在,因为我们假设它已经在设备上 [36minfo[39m: [debug] 检查 adb 是否存在] 36minfo[39m: [debug] 使用 D:\Saravanan\Softwares\android-sdk\platform-tools\adb.exe 中的 adb [36minfo[39m: 检索设备 [36minfo[39m: [debug] 试图找到连接的 android 设备[36minfo[39m: [debug] 获取连接的设备... [36minfo[39m: [debug] 正在执行:“D:\Saravanan\Softwares\android-sdk\platform-tools\adb.exe”设备 [36minfo[39m: [调试] 找不到设备,正在重新启动 adb 服务器... [36minfo [39m: [调试] 正在执行:“D:\Saravanan\Softwares\android-sdk\platform-tools\adb.exe”kill-server [31merror[ 39m: 杀死 ADB 服务器时出错,要查看它是否在线 [36minfo[39m: [debug] 正在连接设备... [36minfo[39m: [debug] 执行:“D:\Saravanan\Softwares\android-sdk\ platform-tools\adb.exe" 设备 [36minfo [39m: [debug] 无法找到d 设备,重新启动 adb 服务器... [31merror[39m: 杀死 ADB 服务器时出错,去看看它是否在线 [36minfo[39m: [debug] 执行:“D:\Saravanan\Softwares\android-sdk\platform- tools\adb.exe" kill-server [36minfo[39m: [debug] 正在连接设备... [36minfo[39m: [debug] 正在执行:"D:\Saravanan\Softwares\android-sdk\platform-tools\adb .exe" 设备 [36minfo[39m: [debug] 找不到设备,正在重新启动 adb 服务器... [36minfo[39m: [debug] 正在执行:“D:\Saravanan\Softwares\android-sdk\platform-tools\adb .exe" kill-server [31merror[39m: 杀死 ADB 服务器时出错,去看看它是否在线 [36minfo[39m: [debug] 正在连接设备... [36minfo[39m: [debug] 正在执行:“D: \Saravanan\Softwares\android-sdk\platform-tools\adb.exe" 设备 [36minfo[39m: [debug] 找不到设备,正在重新启动 adb 服务器... [36minfo[39m: [debug] 正在执行:"D: \Saravanan\Softwares\android-sdk\platform-tools\adb.exe" kill-server [31merror[39m: Error Killing ADB server, going to s ee 是否仍然在线 [36minfo[39m: [debug] 正在连接设备... [36minfo[39m: [debug] 正在执行:“D:\Saravanan\Softwares\android-sdk\platform-tools\adb.exe”设备[36minfo[39m: [debug] 找不到设备,正在重新启动 adb 服务器... [36minfo[39m: [debug] 正在执行:“D:\Saravanan\Softwares\android-sdk\platform-tools\adb.exe” kill -server [31merror[39m: 杀死 ADB 服务器时出错,要查看它是否在线\android-sdk\platform-tools\adb.exe" 设备 [36minfo[39m: [debug] 找不到设备,正在重新启动 adb 服务器... [36minfo[39m: [debug] 正在执行:“D:\Saravanan\Softwares \android-sdk\platform-tools\adb.exe" kill-server [31merror[39m: 杀死 ADB 服务器时出错,去看看它是否在线 [36minfo[39m: [debug] 正在连接设备... [36minfo[ 39m:[调试] 执行:“D:\Saravanan\Softwares\android-sdk\platform-tools\adb.exe”设备 [36minfo[39m:[调试] 找不到设备,重新启动 adb 服务器... [36minfo [39m:[调试] 执行:“D:\Saravanan\Softwares\android-sdk\platform-tools\adb.exe”kill-server [31merror[39m : 杀死 ADB 服务器时出错,去看看它是否在线 [36minfo[39m: [debug] 正在连接设备... [36minfo[39m: [debug] 正在执行:“D:\Saravanan\Softwares\android-sdk\platform -tools\adb.exe" 设备 [36minfo[39m: [debug] 找不到设备,正在重新启动 adb 服务器... [36minfo[39m: [debug] 正在执行:“D:\Saravanan\Softwares\android-sdk\platform -tools\adb.exe" kill-server [31merror[39m:杀死ADB服务器时出错,去看看它是否在线[36minfo[39m:[debug]正在连接设备...[36minfo[39m:[debug]正在执行] : "D:\Saravanan\Softwares\android-sdk\platform-tools\adb.exe" 设备 [36minfo[39m: [debug] 找不到设备,正在重新启动 adb 服务器... [36minfo[39m: [debug] 正在执行: "D:\Saravanan\Softwares\android-sdk\platform-tools\adb.exe" kill-server [31merror[39m: 杀死 AD 时出错B 服务器,去看看它是否在线 [36minfo[39m: [debug] 正在连接设备... [36minfo[39m: [debug] 正在执行:“D:\Saravanan\Softwares\android-sdk\platform-tools\ adb.exe" 设备 [36minfo[39m: [debug] 找不到设备,正在重新启动 adb 服务器... [36minfo[39m: [debug] 正在执行:“D:\Saravanan\Softwares\android-sdk\platform-tools\ adb.exe" kill-server [31merror[39m: 杀死 ADB 服务器时出错,去看看它是否在线 [36minfo[39m: [debug] 正在连接设备... [36minfo[39m: [debug] 正在执行:“D :\Saravanan\Softwares\android-sdk\platform-tools\adb.exe" 设备 [36minfo[39m: [debug] 找不到设备,正在重新启动 adb 服务器... [36minfo[39m: [debug] 正在执行:“D :\Saravanan\Softwares\android-sdk\platform-tools\adb.exe" kill-server [31merror[39m: 杀死 ADB 服务器时出错,去看看它是否在线 [36minfo[39m: [debug] 连接设备。 .. [36minfo[39m: [调试] 执行:“D:\Saravanan\Softwares\android-sdk\platform-tools\adb.exe”开发ices [36minfo[39m: [debug] 找不到设备,正在重新启动 adb 服务器... [36minfo[39m: [debug] 正在执行:“D:\Saravanan\Softwares\android-sdk\platform-tools\adb.exe” kill-server [31merror[39m: 杀死 ADB 服务器时出错,去看看它是否在线 [36minfo[39m: [debug] 正在连接设备... [36minfo[39m: [debug] 正在执行:“D:\Saravanan\ Softwares\android-sdk\platform-tools\adb.exe" 设备 [36minfo[39m: [debug] 找不到设备,正在重新启动 adb 服务器... [36minfo[39m: [debug] 正在执行:“D:\Saravanan\ Softwares\android-sdk\platform-tools\adb.exe" kill-server [31merror[39m:杀死ADB服务器时出错,去看看它是否在线[36minfo [39m:[调试]正在连接设备... [36minfo [39m:[调试]正在执行:“D:\ Saravanan\Softwares\android-sdk\platform-tools\adb.exe”设备[36minfo [39m:[调试]找不到设备,重新启动adb服务器...... [36minfo [39m:[调试] 执行:“D:\Saravanan\Softwares\android-sdk\platform-tools\adb.exe”kill-server [31merror[3 9m:杀死 ADB 服务器时出错,要查看它是否在线 [36minfo[39m: [debug] 正在连接设备... [36minfo[39m: [debug] 正在执行:“D:\Saravanan\Softwares\android-sdk\ platform-tools\adb.exe" 设备 [36minfo[39m: [debug] 找不到设备,正在重新启动 adb 服务器... [36minfo[39m: [debug] 正在执行:“D:\Saravanan\Softwares\android-sdk\ platform-tools\adb.exe" kill-server [31merror[39m: 杀死 ADB 服务器时出错,去看看它是否在线 [36minfo[39m: [debug] 正在连接设备... [36minfo[39m: [debug]执行:“D:\Saravanan\Softwares\android-sdk\platform-tools\adb.exe”设备 [36minfo[39m: [debug] 找不到设备,正在重新启动 adb 服务器... [36minfo[39m: [debug]执行:"D:\Saravanan\Softwares\android-sdk\platform-tools\adb.exe" kill-server [31merror[39m: 杀死 ADB 服务器时出错,去看看它是否在线 [36minfo[39m: [debug]正在连接设备... [36minfo[39m: [debug] 正在执行:“D:\Saravanan\Softwares\android-sdk\platfor m-tools\adb.exe" 设备 [36minfo[39m: [debug] 找不到设备,正在重新启动 adb 服务器... [36minfo[39m: [debug] 正在执行:“D:\Saravanan\Softwares\android-sdk\ platform-tools\adb.exe" kill-server [31merror[39m: 杀死 ADB 服务器时出错,去看看它是否在线 [36minfo[39m: [debug] 正在连接设备... [36minfo[39m: [debug]执行:“D:\Saravanan\Softwares\android-sdk\platform-tools\adb.exe”设备 [36minfo[39m: [debug] 找不到设备,正在重新启动 adb 服务器... [36minfo[39m: [debug]执行:"D:\Saravanan\Softwares\android-sdk\platform-tools\adb.exe" kill-server [31merror[39m: 杀死 ADB 服务器时出错,去看看它是否在线 [36minfo[39m: [debug]正在连接设备... [36minfo [39m:[调试]正在执行:“D:\ Saravanan\Softwares\android-sdk\platform-tools\adb.exe”设备[36minfo [39m:[调试]找不到设备,重新启动 adb 服务器... [36minfo[39m: [debug] 正在执行:“D:\Saravanan\Softwares\android-sdk\platform-tools\adb.exe” kil l-server [31merror[39m:杀死ADB服务器时出错,去看看它是否在线[36minfo[39m:[debug]正在连接设备...[36minfo[39m:[debug]正在执行:“D:\ Saravanan\ Softwares\android-sdk\platform-tools\adb.exe" 设备 [36minfo[39m: [debug] 找不到设备,正在重新启动 adb 服务器... [36minfo[39m: [debug] 正在执行:“D:\Saravanan\ Softwares\android-sdk\platform-tools\adb.exe" kill-server [31merror[39m:杀死ADB服务器时出错,去看看它是否在线[36minfo [39m:[调试]正在连接设备... [36minfo [39m:[debug]正在执行:“D:\Saravanan\Softwares\android-sdk\platform-tools\adb.exe”设备[36minfo[39m:[debug]发送关机命令,等待UiAutomator停止... [ 33mwarn [39m:UiAutomator 没有足够快地关闭,称它消失了 [31merror [39m:无法启动 Appium 会话,错误是:错误:找不到连接的 Android 设备。 [36minfo [39m:[调试]清理android对象[36minfo [39m:[调试]清理appium会话[36minfo [39m:[调试]错误:找不到连接的Android设备。 在 ADB.getDevicesWithRetry (F:\Softwares\Selenium\Appium\AppiumForWindows-1.2.4.1\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:612:15) 在 androidCommon.prepareActiveDevice (F:\Softwares\Selenium\Appium\AppiumForWindows-1.2.4.1\Appium\node_modules\appium\lib\devices\android\android-common.js:387:12) 在空。 (F:\Softwares\Selenium\Appium\AppiumForWindows-1.2.4.1\Appium\node_modules\appium\lib\devices\android\android-common.js:325:26) 在 F:\Softwares\Selenium\Appium\AppiumForWindows-1.2.4.1\Appium\node_modules\appium\node_modules\async\lib\async.js:610:21 在 F:\Softwares\Selenium\Appium\AppiumForWindows-1.2.4.1\Appium\node_modules\appium\node_modules\async\lib\async.js:249:17 在迭代(F:\Softwares\Selenium\Appium\AppiumForWindows-1.2.4.1\Appium\node_modules\appium\node_modules\async\lib\async.js:149:13) 在 F:\Softwares\Selenium\Appium\AppiumForWindows-1.2.4.1\Appium\node_modules\appium\node_modules\async\lib\async.js:160:25 在 F:\Softwares\Selenium\Appium\AppiumForWindows-1.2.4.1\Appium\node_modules\appium\node_modules\async\lib\async.js:251:21 在 F:\Softwares\Selenium\Appium\AppiumForWindows-1.2.4.1\Appium\node_modules\appium\node_modules\async\lib\async.js:615:34 在 androidCommon.prepareEmulator (F:\Softwares\Selenium\Appium\AppiumForWindows-1.2.4.1\Appium\node_modules\appium\lib\devices\android\android-common.js:377:5) [36minfo[39m: [debug]以错误响应客户端:{“status”:33,“value”:{“message”:“无法创建新会话。(原始错误:找不到连接的Android设备。)”,“origValue”: “找不到连接的 Android 设备。”},"sessionId":null} [36minfo[39m: [37m

任何人都可以帮助和任何建议来解决这个问题吗?

【问题讨论】:

    标签: android eclipse appium


    【解决方案1】:

    你的APP_PACKAGE "net.android.device"APP_ACTIVITY "com.android.launcher.Main" 指向不同的包,这对我来说很奇怪。

    通常定义如下

    APP_PACKAGE  com.example.simpleaapp
    APP_ACTIVITY com.example.simpleaapp.MyActivity
    

    【讨论】:

    • 在我们的应用中,修改了AndroidManifest.xml中的包名。它是一个可选的,你可以改变或不改变
    • 但是这也显示在日志中 - 不同的包
    猜你喜欢
    • 2017-02-28
    • 2013-09-14
    • 1970-01-01
    • 2019-06-26
    • 1970-01-01
    • 1970-01-01
    • 2017-06-21
    • 2016-08-21
    • 1970-01-01
    相关资源
    最近更新 更多