Appium会话,找不到已连接的Android设备。在eclipse中显示错误
如果有人知道如何解决,请告诉我。
** Junit代码: - **
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',os.name:' Windows 10',os.arch:&# 39; 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
答案 0 :(得分:1)
上述错误的原因是,找不到任何设备或AVD连接。错误消息中的以下行显示:
> 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调试”应该开启。
转到命令提示符并运行以下命令:
adb devices
预期输出:某些设备或AVD应显示为已连接。 一旦您看到任何设备或AVD连接,然后重试,您的问题就会得到解决。
注意: 在命令窗口中运行“adb devices”命令时,如果看到“abd.exe是无法识别的内部或外部命令或批处理文件...”之类的消息,则需要在路径中包含adb.exe。您可以在环境变量中添加其路径,或者在运行“adb devices”之前运行以下命令:
set path=%PATH%;"D:\AndroidSDK\platform-tools"
请注意,adb.exe文件位于我的PC上的platform-tools文件夹中,位于Android SDK文件夹中。您需要修改此路径,就像在PC上一样。
答案 1 :(得分:0)
尝试使用真实设备,因为仿真器非常慢,启动时间也会花费更多时间。即使是真正的设备,我也面临着这样的问题,
期待原因:
如果出现adb问题,则需要在cmd中运行以下命令:
adb kill-server
adb start-server
然后你尝试使用Android模拟器,并确保你的系统有足够的内存这些模拟器,如VM,这将CPU和&amp;记住你的系统责任金额。
答案 2 :(得分:-2)
对我来说有帮助的是用最新的版本替换旧版的chromedriver。
Chrome browser is not able to navigate to any site in appium