Appium会话,找不到连接的Android设备.显示错误 [英] Appium session, could not find a connected Android device. Shows error

查看:187
本文介绍了Appium会话,找不到连接的Android设备.显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Appium会话,找不到已连接的Android设备.在日食中显示错误

如果有人知道如何解决,请告诉我.

If any one know how to fix please let me know.

** Junit代码:-**

**The Junit code: - **

    import static org.junit.Assert.*;
    import java.io.File;
    import java.net.MalformedURLException;
    import java.net.URL;
    import org.junit.Test;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import io.appium.java_client.android.AndroidDriver;
    import io.appium.java_client.remote.MobileCapabilityType;
    import io.appium.java_client.remote.MobilePlatform;

    public class desiredCapab {

        @Test
        public void test() throws MalformedURLException {

            File appDir = new File("C:\\Eclipse-Neon\\Project\\AppiumT\\Apk\\");

                File app = new File (appDir, "WhatsApp.apk");


            DesiredCapabilities cap = new DesiredCapabilities();
            cap.setCapability(MobileCapabilityType.PLATFORM_NAME,MobilePlatform.ANDROID);
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
cap.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());

AndroidDriver driver = new AndroidDriver(new URL ("http://127.0.0.1:4723/wd/hub"), cap);

            //{"address":"127.0.0.1","logNoColors":true,"platformName":"Android","platformVersion":"23","automationName":"Appium"}
        }
    }

Eclipse Junit错误:-

org.openqa.selenium.SessionNotCreatedException:无法创建新的会话. (原始错误:找不到连接的Android设备.)(警告:服务器未提供任何堆栈跟踪信息) 命令持续时间或超时:28.61秒 内部版本信息:版本:'2.49.0',版本:'365eeb4',时间:'2016-01-13 18:33:29' 系统信息:主机:'DESKTOP-PC1SJR4',ip:'192.168.1.104',操作系统名称:'Windows 10',os.arch:'amd64',os.version:'10 .0',java.version:'1.8 .0_91'

org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Could not find a connected Android device.) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 28.61 seconds Build info: version: '2.49.0', revision: '365eeb4', time: '2016-01-13 18:33:29' System info: host: 'DESKTOP-PC1SJR4', ip: '192.168.1.104', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_91'

AVD管理器设置:-图像

Appium:-错误消息

> info: --> POST /wd/hub/session {"desiredCapabilities":{"app":"C:\\Eclipse-Neon\\Project\\AppiumT\\Apk\\WhatsApp.apk","platformName":"Android","deviceName":"Android Emulator"}}
> info: Client User-Agent string: Apache-HttpClient/4.5.1 (Java/1.8.0_91)
> info: [debug] No appActivity desired capability or server param. Parsing from apk.
> info: [debug] No appPackage desired capability or server param. Parsing from apk.
> info: [debug] Using local app from desired caps: C:\Eclipse-Neon\Project\AppiumT\Apk\WhatsApp.apk
> info: [debug] Creating new appium session c9232f90-f519-4058-9e80-22cd2830de57
> info: Starting android appium
> info: [debug] Getting Java version
> info: Java version is: 1.8.0_101
> info: [debug] Checking whether adb is present
> info: [debug] Using adb from C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe
> info: [debug] Parsing package and activity from app manifest
> info: [debug] Checking whether aapt is present
> info: [debug] Using aapt from C:\Users\bizBoxChat\AppData\Local\Android\sdk\build-tools\24.0.3\aapt.exe
> info: [debug] Extracting package and launch activity from manifest.
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\build-tools\24.0.3\aapt.exe dump badging C:\Eclipse-Neon\Project\AppiumT\Apk\WhatsApp.apk
> info: [debug] badging package: com.whatsapp
> info: [debug] badging act: com.whatsapp.Main
> info: [debug] Parsed package and activity are: com.whatsapp/com.whatsapp.Main
> info: [debug] Using fast reset? true
> info: [debug] Preparing device for session
> info: [debug] Checking whether app is actually present
> info: Retrieving device
> info: [debug] Trying to find a connected android device
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe devices
> info: [debug] 0 device(s) connected
> info: [debug] Could not find devices, restarting adb server...
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe kill-server
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe devices
> info: [debug] 0 device(s) connected
> info: [debug] Could not find devices, restarting adb server...
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe kill-server
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe devices
> info: [debug] 0 device(s) connected
> info: [debug] Could not find devices, restarting adb server...
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe kill-server
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe devices
> info: [debug] 0 device(s) connected
> info: [debug] Could not find devices, restarting adb server...
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe kill-server
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe devices
> info: [debug] 0 device(s) connected
> info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
> warn: UiAutomator did not shut down fast enough, calling it gone
> info: [debug] Cleaning up android objects
> info: [debug] Cleaning up appium session
> error: Failed to start an Appium session, err was: Error: Could not find a connected Android device.
> info: [debug] Error: Could not find a connected Android device.
>     at [object Object].ADB.getDevicesWithRetry (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\lib\adb.js:606:15)
>     at [object Object].androidCommon.prepareActiveDevice (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android-common.js:400:12)
>     at [object Object].<anonymous> (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android-common.js:326:26)
>     at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:607:21
>     at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:246:17
>     at iterate (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:146:13)
>     at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:157:25
>     at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:248:21
>     at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:612:34
>     at [object Object].androidCommon.ensureDeviceLocale (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android-common.js:371:45)
>     at [object Object].androidCommon.prepareEmulator (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android-common.js:364:10)
>     at [object Object].<anonymous> (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android-common.js:325:26)
>     at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:607:21
>     at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:246:17
>     at iterate (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:146:13)
>     at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:157:25
>     at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:248:21
>     at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\async\lib\async.js:612:34
>     at [object Object].<anonymous> (C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android-common.js:344:9)
>     at FSReqWrap.oncomplete (fs.js:95:15)
> info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. (Original error: Could not find a connected Android device.)","origValue":"Could not find a connected Android device."},"sessionId":null}
> info: <-- POST /wd/hub/session 500 28492.200 ms - 206

推荐答案

出现上述错误的原因是,找不到任何设备或AVD.错误消息中的以下几行显示了这一点:

Reason of above error is, any device or AVD could not be found to be connected. Following lines in your error message show this:

> info: [debug] Trying to find a connected android device
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: C:\Users\bizBoxChat\AppData\Local\Android\sdk\platform-tools\adb.exe devices
> info: [debug] 0 device(s) connected
> info: [debug] Could not find devices, restarting adb server...

> info: [debug] Error: Could not find a connected Android device.

仅在AVD管理器中创建AVD是不够的.它必须启动并运行(已启动并准备就绪).为此,请在您的AVD管理器中选择任何AVD,然后单击开始"按钮.让AVD启动.等待. (这类似于打开真实设备.) 或者,需要连接一些真实的设备.在该设备中,开发人员选项"应为开. "USB调试"应该打开.

Just creating AVD in AVD manager is not sufficient. It has to be up and running (started and ready). To do that, select any AVD in your AVD manager, and click on "Start" button. Let the AVD boot. Wait. (It is similar to a real device switching on.) Or, some real device needs to be connected. In that device, "Developer Options" should be On. "USB debugging" should be On.

转到命令提示符并运行以下命令:

Go to command prompt and run following command:

adb devices

预期的输出:某些设备或AVD应该显示为已连接. 一旦看到任何设备或AVD已连接,然后重试,即可解决您的问题.

Expected output: Some device or AVD should be shown as connected. Once you see any device or AVD connected, and retry, then your problem will be solved.

注意: 在命令窗口中运行"adb设备"命令时,如果看到诸如"abd.exe是无法识别的内部或外部命令或批处理文件..."之类的消息,则需要在路径中包含adb.exe.您可以在环境变量中添加其路径,也可以在运行"adb设备"之前直接运行以下命令:

Note: On running "adb devices" command in command window, if you see message like "abd.exe is an unrecognized internal or external command or batch file...", then you need to have adb.exe in path. You can add its path in environment variables, or simply run following command before running "adb devices":

set path=%PATH%;"D:\AndroidSDK\platform-tools"

请注意,adb.exe文件位于我PC上的platform-tools文件夹中,位于Android SDK文件夹中.您将需要修改此路径,就像在PC上一样.

Note that adb.exe file is in platform-tools folder on my PC, in Android SDK folder. You will need to modify this path as it is on your PC.

这篇关于Appium会话,找不到连接的Android设备.显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆