通过 Appium 启动 (whatsapp) 移动应用程序会导致“'com.whatsapp.Main' 从未启动”错误

Launching (whatsapp) mobile application via Appium causes an "'com.whatsapp.Main' never started" error

通过 Appium 服务器执行代码会导致应用程序启动几秒钟。然后程序停止工作并出现错误:

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: An unknown server-side error occurred while processing the command. Original error: Error occured while starting App. Original error: 'com.whatsapp.Main' never started (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds Build info: version: '3.3.1', revision: '5234b32', time: '2017-03-10 09:04:52 -0800' System info: host: 'DESKTOP-7P0AKLE', ip: '172.20.167.164', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '9' Driver info: driver.version: RemoteWebDriver at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:367) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:113) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604) at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:158) at app.TestManager.createAppiumWebDriver(TestManager.java:227) at app.TestManager.runTests(TestManager.java:167) at app.TestManager.run(TestManager.java:43) at app.Launcher.main(Launcher.java:11)

我使用 Appium 服务器 v1.7.0

我的能力:

    DesiredCapabilities capabilities = new DesiredCapabilities();

    capabilities.setCapability("deviceName", "Galaxy S6");
    capabilities.setCapability("platformVersion", "7.0");
    capabilities.setCapability("platformName", "Android");

    java.io.File file = new java.io.File("D:\Prac\JavaWorkspace\TestAutomationPartners\apk\com.whatsapp.apk");
    capabilities.setCapability("app", file.getAbsolutePath());

    //???
    capabilities.setCapability("app-wait-activity", "Main");
    capabilities.setCapability("app-wait-activity", "MainActivity");
    //???

根据我自己对问题的研究: 我想我应该以某种方式等待 "Main" activity 到 运行。我以为我通过添加 app-wait-activity 功能来做到这一点。但是没有结果... (此外,该应用程序会启动几秒钟,因此 "Main" activity 应该已经 运行ning - 不应该吗?)

这是来自 Appium 服务器的日志:

并在此处完成日志:

> The server is running

> [Appium] Welcome to Appium v1.7.0
[Appium] Non-default server args:
[Appium]   address: 127.0.0.1
[Appium] Appium REST http interface listener started on 127.0.0.1:4723
[HTTP] --> POST /wd/hub/session {"desiredCapabilities":{"app":"D:\Prac\JavaWorkspace\TestAutomationPartners\apk\com.whatsapp.apk","app-wait-activity":"MainActivity","platformVersion":"7.0","platformName":"Android","deviceName":"Galaxy S6"},"requiredCapabilities":{},"capabilities":{"desiredCapabilities":{"app":"D:\Prac\JavaWorkspace\TestAutomationPartners\apk\com.whatsapp.apk","app-wait-activity":"MainActivity","platformVersion":"7.0","platformName":"Android","deviceName":"Galaxy S6"},"requiredCapabilities":{}},"alwaysMatch":{"app":"D:\Prac\JavaWorkspace\TestAutomationPartners\apk\com.whatsapp.apk","app-wait-activity":"MainActivity","platformVersion":"7.0","platformName":"Android","deviceName":"Galaxy S6"},"firstMatch":[]}
[MJSONWP] Calling AppiumDriver.createSession() with args: [{"app":"D:\Prac\JavaWorkspace\TestAutomationPartners\apk\com.whatsapp.apk","app-wait-activity":"MainActivity","platformVersion":"7.0","platformName":"Android","deviceName":"Galaxy S6"},{},{"desiredCapabilities":{"app":"D:\Prac\JavaWorkspace\TestAutomationPartners\apk\com.whatsapp.apk","app-wait-activity":"MainActivity","platformVersion":"7.0","platformName":"Android","deviceName":"Galaxy S6"},"requiredCapabilities":{}}]
[BaseDriver] Event 'newSessionRequested' logged at 1508327732068 (13:55:32 GMT+0200 (Střední Evropa (letní čas)))
[Appium] Creating new AndroidDriver (v1.26.5) session
[Appium] Capabilities:
[Appium]   app: 'D:\Prac\JavaWorkspace\TestAutomationPartners\apk\com.whatsapp.apk'
[Appium]   app-wait-activity: 'MainActivity'
[Appium]   platformVersion: '7.0'
[Appium]   platformName: 'Android'
[Appium]   deviceName: 'Galaxy S6'
[BaseDriver] The following capabilities were provided, but are not recognized by appium: app-wait-activity.
[BaseDriver] Session created with session id: 20bb4b00-509c-49dd-8796-e1d8ad0714dc
[AndroidDriver] Getting Java version
[AndroidDriver] Java version is: 9
[ADB] Checking whether adb is present
[ADB] Using adb.exe from D:\Prac\AndroidSDK\platform-tools\adb.exe
[AndroidDriver] Retrieving device list
[ADB] Trying to find a connected android device
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[AndroidDriver] Looking for a device with Android '7.0'
[ADB] Setting device id to 04157df4f2639124
[ADB] Getting device platform version
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","getprop","ro.build.version.release"]
[ADB] Current device property 'ro.build.version.release': 7.0
[AndroidDriver] Using device: 04157df4f2639124
[ADB] Checking whether adb is present
[ADB] Using adb.exe from D:\Prac\AndroidSDK\platform-tools\adb.exe
[ADB] Setting device id to 04157df4f2639124
[BaseDriver] Using local app 'D:\Prac\JavaWorkspace\TestAutomationPartners\apk\com.whatsapp.apk'
[AndroidDriver] Checking whether app is actually present
[AndroidDriver] Starting Android session
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","wait-for-device"]
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","echo","ping"]
[Logcat] Starting logcat capture
[AndroidDriver] Pushing settings apk to device...
[ADB] Getting install status for io.appium.settings
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","pm","list","packages","io.appium.settings"]
[ADB] App is installed
[ADB] Getting package info for io.appium.settings
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","dumpsys","package","io.appium.settings"]
[ADB] Checking whether aapt is present
[ADB] Using aapt.exe from D:\Prac\AndroidSDK\build-tools.0.3\aapt.exe
[ADB] The installed "io.appium.settings" package does not require upgrade (4 >= 4)
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","getprop","ro.build.version.sdk"]
[ADB] Current device property 'ro.build.version.sdk': 24
[ADB] Device API level: 24
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","dumpsys","package","io.appium.settings"]
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","pm","dump","io.appium.settings"]
[ADB] Got the following command chunks to execute: pm,grant,io.appium.settings,android.permission.WRITE_SETTINGS,;,pm,grant,io.appium.settings,android.permission.ACCESS_MOCK_LOCATION,;
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","pm","grant","io.appium.settings","android.permission.WRITE_SETTINGS",";","pm","grant","io.appium.settings","android.permission.ACCESS_MOCK_LOCATION",";"]
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","pm","grant","io.appium.settings","android.permission.WRITE_SETTINGS",";","pm","grant","io.appium.settings","android.permission.ACCESS_MOCK_LOCATION",";"]
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","ps"]
[ADB] Device API level: 24
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","appops","set","io.appium.settings","android:mock_location","allow"]
[AndroidDriver] Pushing unlock helper app to device...
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","install","C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-unlock\bin\unlock_apk-debug.apk"]
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","install","C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-unlock\bin\unlock_apk-debug.apk"]
[ADB] Application 'C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-unlock\bin\unlock_apk-debug.apk' already installed. Continuing.
[ADB] Getting device platform version
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","getprop","ro.build.version.release"]
[ADB] Current device property 'ro.build.version.release': 7.0
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","wm","size"]
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","getprop","ro.product.model"]
[ADB] Current device property 'ro.product.model': SM-G920F
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","getprop","ro.product.manufacturer"]
[ADB] Current device property 'ro.product.manufacturer': samsung
[AndroidDriver] Parsing package and activity from app manifest
[ADB] Checking whether aapt is present
[ADB] Using aapt.exe from D:\Prac\AndroidSDK\build-tools.0.3\aapt.exe
[ADB] Extracting package and launch activity from manifest
[ADB] badging package: com.whatsapp
[ADB] badging act: com.whatsapp.Main
[AndroidDriver] Parsed package and activity are: com.whatsapp/com.whatsapp.Main
[AndroidDriver] Remote apk path is /data/local/tmp/3ce651a86314b8d232a800345c91a23c.apk
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","ls","/data/local/tmp/3ce651a86314b8d232a800345c91a23c.apk"]
[AndroidDriver] Checking if app is installed
[ADB] Getting install status for com.whatsapp
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","pm","list","packages","com.whatsapp"]
[ADB] App is installed
[AndroidDriver] Apk is already on remote and installed, resetting
[AndroidDriver] Running fast reset (stop and clear)
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","am","force-stop","com.whatsapp"]
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","pm","clear","com.whatsapp"]
[AndroidDriver] Extracting strings from apk D:\Prac\JavaWorkspace\TestAutomationPartners\apk\com.whatsapp.apk undefined C:\Users\Jan\AppData\Local\Temp\com.whatsapp
[ADB] Extracting strings for language: default
[ADB] Device API level: 24
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","getprop","persist.sys.locale"]
[ADB] Current device property 'persist.sys.locale': cs-CZ
[ADB] Reading strings from converted strings.json
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","push","C:\Users\Jan\AppData\Local\Temp\com.whatsapp\strings.json","/data/local/tmp"]
[AndroidBootstrap] Watching for bootstrap disconnect
[ADB] Forwarding system: 4724 to device: 4724
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","forward","tcp:4724","tcp:4724"]
[UiAutomator] Starting UiAutomator
[UiAutomator] Moving to state 'starting'
[UiAutomator] Parsing uiautomator jar
[UiAutomator] Found jar name: 'AppiumBootstrap.jar'
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","push","C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-android-bootstrap\bootstrap\bin\AppiumBootstrap.jar","/data/local/tmp/"]
[ADB] Attempting to kill all uiautomator processes
[ADB] Getting all processes with uiautomator
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","ps"]
[ADB] No uiautomator process found to kill, continuing...
[UiAutomator] Starting UIAutomator
[ADB] Creating ADB subprocess with args: ["-P",5037,"-s","04157df4f2639124","shell","uiautomator","runtest","AppiumBootstrap.jar","-c","io.appium.android.bootstrap.Bootstrap","-e","pkg","com.whatsapp","-e","disableAndroidWatchers",false,"-e","acceptSslCerts",false]
[UiAutomator] Moving to state 'online'
[AndroidBootstrap] Android bootstrap socket is now connected
[ADB] Getting connected devices...
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] json loading complete.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Registered crash watchers.
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Client connected
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","dumpsys","window"]
[AndroidDriver] Screen already unlocked, doing nothing
[ADB] Device API level: 24
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","am","start","-W","-n","com.whatsapp/com.whatsapp.Main","-S"]
[ADB] Waiting up to 20000ms for activity matching pkg: 'com.whatsapp' and activity: 'com.whatsapp.Main' to be focused
[ADB] Possible activities, to be checked: 'com.whatsapp.Main'
[ADB] Getting focused package and activity
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","dumpsys","window","windows"]
[ADB] Found package: 'com.whatsapp' and fully qualified activity name : 'com.whatsapp.registration.EULA'

现在有

[ADB] Incorrect package and activity. Retrying.
    [ADB] Getting focused package and activity
    [ADB] Getting connected devices...
    [ADB] 1 device(s) connected
    [ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","dumpsys","window","windows"]
    [ADB] Found package: 'com.whatsapp' and fully qualified activity name : 'com.whatsapp.registration.EULA'

很多次...

[ADB] Incorrect package and activity. Retrying.
[ADB] Error: Error occured while starting App. Original error: 'com.whatsapp.Main' never started
    at Object.wrappedLogger.errorAndThrow (C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-support\lib\logging.js:63:13)
    at ADB.callee[=14=][=14=]$ (C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-adb\lib\tools\apk-utils.js:101:9)
    at tryCatch (C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
 Error: Error occured while starting App. Original error: 'com.whatsapp.Main' never started
    at Object.wrappedLogger.errorAndThrow (C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-support\lib\logging.js:63:13)
    at ADB.callee[=14=][=14=]$ (C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-adb\lib\tools\apk-utils.js:101:9)
    at tryCatch (C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
[AndroidDriver] Shutting down Android driver
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","am","force-stop","com.whatsapp"]
[ADB] Pressing the HOME button
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","input","keyevent",3]
[AndroidBootstrap] Sending command to android: {"cmd":"shutdown"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"shutdown"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type SHUTDOWN
[AndroidBootstrap] Received command result from bootstrap
[UiAutomator] Shutting down UiAutomator
[UiAutomator] Moving to state 'stopping'
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":0,"value":"OK, shutting down"}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Closed client connection
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: numtests=1
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: stream=.
[AndroidBootstrap] [UIAUTO STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
[UiAutomator] UiAutomator shut down normally
[UiAutomator] Moving to state 'stopped'
[ADB] Attempting to kill all uiautomator processes
[ADB] Getting all processes with uiautomator
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","ps"]
[ADB] No uiautomator process found to kill, continuing...
[UiAutomator] Moving to state 'stopped'
[Logcat] Stopping logcat capture
[ADB] Getting connected devices...
[ADB] 1 device(s) connected
[ADB] Running 'D:\Prac\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","04157df4f2639124","shell","am","force-stop","io.appium.unlock"]
[AndroidDriver] Not cleaning generated files. Add `clearSystemFiles` capability if wanted.
[MJSONWP] Encountered internal error running command: Error: Error occured while starting App. Original error: 'com.whatsapp.Main' never started
    at Object.wrappedLogger.errorAndThrow (C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-support\lib\logging.js:63:13)
    at ADB.callee[=14=][=14=]$ (C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-adb\lib\tools\apk-utils.js:101:9)
    at tryCatch (C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (C:\Users\Jan\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
[HTTP] <-- POST /wd/hub/session 500 64685 ms - 220 

如果您提供 app 功能,则无需指定功能 appPackageappActivity

如果您已经在我们的设备中预安装了该应用程序,那么您可以使用 appPackage 和 [=40= 功能启动该应用程序]appActivity

File app_apk = new File("/Users/Yash/Desktop/APK/Sample.apk");
capabilities.setCapability("app", file.getAbsolutePath());

现在不需要提供appPackage & appActivity

假设应用程序已安装,您想要启动它

capabilities.setCapability("appPackage", "Your-appPackage-name");
capabilities.setCapability("appActivity", "Your-appActivity-name");

如何获取应用程序的appPackage & appActivity?

确保 adb 已连接 > 在您的设备中打开应用 > 输入

adb shell "dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'"

时钟应用程序的示例输出

mCurrentFocus=Window{ce2e95b u0 com.google.android.deskclock/com.android.deskclock.DeskClock}
mFocusedApp=AppWindowToken{3cac5b0 token=Token{c58d7d6 ActivityRecord{74c3ff1 u0 com.google.android.deskclock/com.android.deskclock.DeskClock t80}}}

从上面的输出我们可以找出appPackageappActivity appPackage/appActivity

com.google.android.deskclock/com.android.deskclock.DeskClock
appPackage = com.google.android.deskclock
appActivity = com.android.deskclock.DeskClock

如何检查我的 appPackage/appActivity 是否正确?

试试这个

adb shell am start -n appPackage/appActivity
adb shell am start -n com.google.android.deskclock/com.android.deskclock.DeskClock

应该启动时钟应用程序

兄弟,我想按照上面的任何一种方法你都可以解决你的问题。否则请告诉我。