sessionnotcreatedexception:无法创建新的远程会话

z4iuyo4d  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(378)
public class Base {
  public static AndroidDriver<AndroidElement> Capabilities(String appName) throws MalformedURLException, IOException 
    {   
        FileInputStream fis= new 
        FileInputStream(System.getProperty("user.dir")+"\\src\\main\\java\\global.properties");
        Properties prop = new Properties();
        prop.load(fis);
        AndroidDriver<AndroidElement> driver;
        File appDir= new File("src");
        File app=new File(appDir, (String) prop.get(appName));
        DesiredCapabilities cap = new DesiredCapabilities();        
        String device=(String) prop.get("device");
        cap.setCapability(MobileCapabilityType.DEVICE_NAME, device);        
        cap.setCapability(MobileCapabilityType.AUTOMATION_NAME,"uiautomator2");
        cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 14);
        cap.setCapability(MobileCapabilityType.APP,app.getAbsolutePath());
        driver = new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"),cap);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);        
        return driver; 
  } 
}

尝试运行测试时,出现以下错误:

org.openqa.selenium.SessionNotCreatedException: Unable to create a new remote session. Please check the server log for more details. Original error: An unknown server-side error occurred while processing the command. Original error: Could not find a connected Android device in 21449ms.
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'MOBIUSOPC', ip: '192.168.56.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_112'
Driver info: driver.version: AndroidDriver
remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Could not find a connected Android device in 21449ms.
    at getResponseForW3CError (C:\Users\arti\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:804:9)
    at asyncHandler (C:\Users\arti\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:392:37)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'MOBIUSOPC', ip: '192.168.56.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_112'
Driver info: driver.version: AndroidDriver

以下是应用程序日志

[HTTP] --> POST /wd/hub/session
[HTTP] {"desiredCapabilities":{"app":"C:\\Users\\arti\\Desktop\\eclipse-workspace\\BuzzMavenAuto\\src\\Buzz-Android-1.0.20200428.1-release.apk","automationName":"uiautomator2","platformName":"Android","deviceName":"Pixel_2","newCommandTimeout":14},"capabilities":{"firstMatch":[{"appium:app":"C:\\Users\\arti\\Desktop\\eclipse-workspace\\BuzzMavenAuto\\src\\Buzz-Android-1.0.20200428.1-release.apk","appium:automationName":"uiautomator2","appium:deviceName":"Pixel_2","appium:newCommandTimeout":14,"platformName":"android"}]}}
[debug] [W3C] Calling AppiumDriver.createSession() with args: [{"app":"C:\\Users\\arti\\Desktop\\eclipse-workspace\\BuzzMavenAuto\\src\\Buzz-Android-1.0.20200428.1-release.apk","automationName":"uiautomator2","platformName":"Android","deviceName":"Pixel_2","newCommandTimeout":14},null,{"firstMatch":[{"appium:app":"C:\\Users\\arti\\Desktop\\eclipse-workspace\\BuzzMavenAuto\\src\\Buzz-Android-1.0.20200428.1-release.apk","appium:automationName":"uiautomator2","appium:deviceName":"Pixel_2","appium:newCommandTimeout":14,"platformName":"android"}]}]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1609150831575 (15:50:31 GMT+0530 (India Standard Time))
[Appium] Appium v1.17.1 creating new AndroidUiautomator2Driver (v1.44.2) session
[debug] [BaseDriver] W3C capabilities and MJSONWP desired capabilities were provided
[debug] [BaseDriver] Creating session with W3C capabilities: {
[debug] [BaseDriver]   "alwaysMatch": {
[debug] [BaseDriver]     "platformName": "android",
[debug] [BaseDriver]     "appium:app": "C:\\Users\\arti\\Desktop\\eclipse-workspace\\BuzzMavenAuto\\src\\Buzz-Android-1.0.20200428.1-release.apk",
[debug] [BaseDriver]     "appium:automationName": "uiautomator2",
[debug] [BaseDriver]     "appium:deviceName": "Pixel_2",
[debug] [BaseDriver]     "appium:newCommandTimeout": 14
[debug] [BaseDriver]   },
[debug] [BaseDriver]   "firstMatch": [
[debug] [BaseDriver]     {}
[debug] [BaseDriver]   ]
[debug] [BaseDriver] }
[BaseDriver] Session created with session id: 8d0be08f-0e31-418a-bd62-ab4ca9ad2d18
[BaseDriver] Using local app 'C:\Users\arti\Desktop\eclipse-workspace\BuzzMavenAuto\src\Buzz-Android-1.0.20200428.1-release.apk'
[debug] [UiAutomator2] Checking whether app is actually present
[ADB] Found 3 'build-tools' folders under 'C:\Users\arti\AppData\Local\Android\Sdk' (newest first):
[ADB]     C:/Users/arti/AppData/Local/Android/Sdk/build-tools/29.0.3
[ADB]     C:/Users/arti/AppData/Local/Android/Sdk/build-tools/29.0.2
[ADB]     C:/Users/arti/AppData/Local/Android/Sdk/build-tools/28.0.3
[ADB] Using 'adb.exe' from 'C:\Users\arti\AppData\Local\Android\Sdk\platform-tools\adb.exe'
[AndroidDriver] Retrieving device list
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devices...
[debug] [ADB] No connected devices have been detected
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port '5037'
[debug] [ADB] Running 'C:\Users\arti\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 kill-server'
[debug] [ADB] Getting connected devices...
[debug] [ADB] No connected devices have been detected
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port '5037'
[debug] [ADB] Running 'C:\Users\arti\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 kill-server'
[debug] [ADB] Getting connected devices...
[debug] [ADB] No connected devices have been detected
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port '5037'
[debug] [ADB] Running 'C:\Users\arti\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 kill-server'
[debug] [ADB] Getting connected devices...
[debug] [ADB] No connected devices have been detected
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port '5037'
[debug] [ADB] Running 'C:\Users\arti\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 kill-server'
[debug] [ADB] Getting connected devices...
[debug] [ADB] No connected devices have been detected
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port '5037'
[debug] [ADB] Running 'C:\Users\arti\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 kill-server'
[debug] [ADB] Getting connected devices...
[debug] [ADB] No connected devices have been detected
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port '5037'
[debug] [ADB] Running 'C:\Users\arti\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 kill-server'
[debug] [ADB] Getting connected devices...
[debug] [ADB] No connected devices have been detected
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port '5037'
[debug] [ADB] Running 'C:\Users\arti\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 kill-server'
[debug] [ADB] Getting connected devices...
[debug] [ADB] No connected devices have been detected
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port '5037'
[debug] [ADB] Running 'C:\Users\arti\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 kill-server'
[debug] [ADB] Getting connected devices...
[debug] [ADB] No connected devices have been detected
[debug] [ADB] Could not find devices, restarting adb server...
[debug] [ADB] Restarting adb
[debug] [ADB] Killing adb server on port '5037'
[debug] [ADB] Running 'C:\Users\arti\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 kill-server'
[debug] [UiAutomator2] Deleting UiAutomator2 session
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1609150853389 (15:50:53 GMT+0530 (India Standard Time))
[debug] [W3C] Encountered internal error running command: Error: Could not find a connected Android device in 21449ms.
[debug] [W3C]     at getDevices (C:\Users\arti\AppData\Roaming\npm\node_modules\appium\node_modules\appium-adb\lib\tools\system-calls.js:211:13)
[debug] [W3C]     at getDevices (C:\Users\arti\AppData\Roaming\npm\node_modules\appium\node_modules\appium-adb\lib\tools\system-calls.js:224:18)
[debug] [W3C]     at getDevices (C:\Users\arti\AppData\Roaming\npm\node_modules\appium\node_modules\appium-adb\lib\tools\system-calls.js:224:12)
[debug] [W3C]     at getDevices (C:\Users\arti\AppData\Roaming\npm\node_modules\appium\node_modules\appium-adb\lib\tools\system-calls.js:224:12)
[debug] [W3C]     at getDevices (C:\Users\arti\AppData\Roaming\npm\node_modules\appium\node_modules\appium-adb\lib\tools\system-calls.js:224:12)
[debug] [W3C]     at getDevices (C:\Users\arti\AppData\Roaming\npm\node_modules\appium\node_modules\appium-adb\lib\tools\system-calls.js:224:12)
[debug] [W3C]     at getDevices (C:\Users\arti\AppData\Roaming\npm\node_modules\appium\node_modules\appium-adb\lib\tools\system-calls.js:224:12)
[debug] [W3C]     at getDevices (C:\Users\arti\AppData\Roaming\npm\node_modules\appium\node_modules\appium-adb\lib\tools\system-calls.js:224:12)
[debug] [W3C]     at getDevices (C:\Users\arti\AppData\Roaming\npm\node_modules\appium\node_modules\appium-adb\lib\tools\system-calls.js:224:12)
[debug] [W3C]     at getDevices (C:\Users\arti\AppData\Roaming\npm\node_modules\appium\node_modules\appium-adb\lib\tools\system-calls.js:224:12)
[debug] [W3C]     at ADB.getDevicesWithRetry (C:\Users\arti\AppData\Roaming\npm\node_modules\appium\node_modules\appium-adb\lib\tools\system-calls.js:226:10)
[debug] [W3C]     at Object.getDeviceInfoFromCaps (C:\Users\arti\AppData\Roaming\npm\node_modules\appium\node_modules\appium-android-driver\lib\android-helpers.js:180:19)
[debug] [W3C]     at AndroidUiautomator2Driver.startUiAutomator2Session (C:\Users\arti\AppData\Roaming\npm\node_modules\appium\node_modules\appium-uiautomator2-driver\lib\driver.js:290:26)
[debug] [W3C]     at AndroidUiautomator2Driver.createSession (C:\Users\arti\AppData\Roaming\npm\node_modules\appium\node_modules\appium-uiautomator2-driver\lib\driver.js:212:7)
[debug] [W3C]     at AppiumDriver.createSession (C:\Users\arti\AppData\Roaming\npm\node_modules\appium\lib\appium.js:358:35)
[debug] [W3C] Destroying socket connection
[HTTP] <-- POST /wd/hub/session
hlswsv35

hlswsv351#

虽然您的selenium版本是3.141.59,但是您的jdk版本1.8.0112太旧了。

解决方案

确保:
jdk升级到当前的JDK8U271级别。

相关问题