当前位置: 首页 > 知识库问答 >
问题:

使用Appium对android应用程序执行自动化测试时,应用程序崩溃

史逸春
2023-03-14

我正试图通过Appium、Selenium框架自动化一些在Android设备上运行的移动应用程序测试。我已经在Selenium中设置了测试类,并尝试使用以下所需功能启动android驱动程序。我的Appium版本是1.4.16.1

public static void initialize() {
    // Created object of DesiredCapabilities class.
    DesiredCapabilities capabilities = new DesiredCapabilities();

    // Set android deviceName desired capability. Set your device name.
    capabilities.setCapability("deviceName", "03157df388c7b934");

    // Set BROWSER_NAME desired capability. It's Android in our case
    // here.
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");

    // Set android VERSION desired capability. Set your mobile device's
    // OS
    // version.
    capabilities.setCapability(CapabilityType.VERSION, "6.0.1");

    // Set android platformName desired capability. It's Android in our
    // case
    // here.
    capabilities.setCapability("platformName", "Android");

    // Set android appPackage desired capability. It is
    // com.android.calculator2 for calculator application.
    // Set your application's appPackage if you are using any other app.
    capabilities.setCapability("appPackage","com.pnc.ecommerce.mobile.finder");
    capabilities.setCapability("appActivity", "com.fisglobal.lfi.pnc.ui.MainActivity");

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

            driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("Driver initialization failed", e);
        }
}

当我在真正的三星设备上运行测试时,应用程序被打开,然后在打开时立即崩溃,并带有消息PNC已停止...,我的测试应用程序是PNC移动应用程序

当我在Appium桌面控制台中查看日志时,我看到以下内容:

 << info: Welcome to Appium v1.4.16 (REV ae6877eff263066b26328d457bd285c0cc62430d)

info: Appium REST http interface listener started on 127.0.0.1:4723
info: [debug] Non-default server args: {"address":"127.0.0.1","logNoColors":true,"platformName":"Android","platformVersion":"23","automationName":"Appium"}
info: Console LogLevel: debug
Killed Node Server.
Appium server process ended
Launching Appium server with command: C:\Program Files (x86)\Appium\node.exe lib\server\main.js --address 127.0.0.1 --port 4723 --platform-name Android --platform-version 23 --automation-name Appium --log-no-color
info: Welcome to Appium v1.4.16 (REV ae6877eff263066b26328d457bd285c0cc62430d)
info: Appium REST http interface listener started on 127.0.0.1:4723
info: [debug] Non-default server args: {"address":"127.0.0.1","logNoColors":true,"platformName":"Android","platformVersion":"23","automationName":"Appium"}
info: Console LogLevel: debug
info: --> POST /wd/hub/session {"desiredCapabilities":{"appPackage":"com.pnc.ecommerce.mobile.finder","appActivity":"com.fisglobal.lfi.pnc.ui.MainActivity","browserName":"Android","platformName":"Android","deviceName":"03157df388c7b934","version":"6.0.1"}}
info: Client User-Agent string: Apache-HttpClient/4.3.3 (java 1.5)
info: [debug] The following desired capabilities were provided, but not recognized by appium. They will be passed on to any other services running on this server. : version
info: [debug] Didn't get app but did get Android package, will attempt to launch it on the device
info: [debug] Creating new appium session 4950142d-270c-433f-ba7f-c6fdea58f76a
info: Starting android appium
info: [debug] Getting Java version
info: Java version is: 1.8.0_131
info: [debug] Checking whether adb is present
info: [debug] Using adb from C:\Android\android-sdk-windows\platform-tools\adb.exe
warn: No app capability, can't parse package/activity
info: [debug] Using fast reset? true
info: [debug] Preparing device for session
info: [debug] Not checking whether app is present since we are assuming it's already on the device
info: Retrieving device
info: [debug] Trying to find a connected android device
info: [debug] Getting connected devices...
info: [debug] executing cmd: C:\Android\android-sdk-windows\platform-tools\adb.exe devices
info: [debug] 1 device(s) connected
info: Found device 03157df388c7b934
info: [debug] Setting device id to 03157df388c7b934
info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
info: [debug] executing cmd: C:\Android\android-sdk-windows\platform-tools\adb.exe -s 03157df388c7b934 wait-for-device
info: [debug] executing cmd: C:\Android\android-sdk-windows\platform-tools\adb.exe -s 03157df388c7b934 shell "echo 'ready'"
info: [debug] Starting logcat capture
info: [debug] Getting device API level
info: [debug] executing cmd: C:\Android\android-sdk-windows\platform-tools\adb.exe -s 03157df388c7b934 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 23
info: Device API level is: 23
info: [debug] Extracting strings for language: default
info: [debug] Apk doesn't exist locally
info: [debug] Could not get strings, but it looks like we had an old strings file anyway, so ignoring
info: [debug] executing cmd: C:\Android\android-sdk-windows\platform-tools\adb.exe -s 03157df388c7b934 shell "rm -rf /data/local/tmp/strings.json"
info: [debug] Not uninstalling app since server not started with --full-reset
info: [debug] Skipping install since we launched with a package instead of an app path
info: [debug] Forwarding system:4724 to device:4724
info: [debug] executing cmd: C:\Android\android-sdk-windows\platform-tools\adb.exe -s 03157df388c7b934 forward tcp:4724 tcp:4724
info: [debug] Pushing appium bootstrap to device...
info: [debug] executing cmd: C:\Android\android-sdk-windows\platform-tools\adb.exe -s 03157df388c7b934 push "C:\Program Files (x86)\Appium\node_modules\appium\build\android_bootstrap\AppiumBootstrap.jar" /data/local/tmp/
info: [debug] Pushing settings apk to device...
info: [debug] executing cmd: C:\Android\android-sdk-windows\platform-tools\adb.exe -s 03157df388c7b934 install "C:\Program Files (x86)\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk"
info: [debug] Pushing unlock helper app to device...
info: [debug] executing cmd: C:\Android\android-sdk-windows\platform-tools\adb.exe -s 03157df388c7b934 install "C:\Program Files (x86)\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"
info: Starting App
info: [debug] Attempting to kill all 'uiautomator' processes
info: [debug] Getting all processes with 'uiautomator'
info: [debug] executing cmd: C:\Android\android-sdk-windows\platform-tools\adb.exe -s 03157df388c7b934 shell "ps 'uiautomator'"
info: [debug] No matching processes found
info: [debug] Running bootstrap
info: [debug] spawning: C:\Android\android-sdk-windows\platform-tools\adb.exe -s 03157df388c7b934 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.pnc.ecommerce.mobile.finder -e disableAndroidWatchers false
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
info: [debug] [BOOTSTRAP] [debug] Loading json...
info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
info: [debug] Waking up device if it's not alive
info: [debug] Pushing command to appium work queue: ["wake",{}]
info: [debug] [BOOTSTRAP] [debug] Client connected
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"wake","params":{}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: wake
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
info: [debug] executing cmd: C:\Android\android-sdk-windows\platform-tools\adb.exe -s 03157df388c7b934 shell "dumpsys window"
info: [debug] Screen already unlocked, continuing.
info: [debug] Pushing command to appium work queue: ["getDataDir",{}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"getDataDir","params":{}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: getDataDir
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":"\/data\/local\/tmp"}
info: [debug] dataDir set to: /data/local/tmp
info: [debug] Pushing command to appium work queue: ["compressedLayoutHierarchy",{"compressLayout":false}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"compressedLayoutHierarchy","params":{"compressLayout":false}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: compressedLayoutHierarchy
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":false}
info: [debug] Getting device API level
info: [debug] executing cmd: C:\Android\android-sdk-windows\platform-tools\adb.exe -s 03157df388c7b934 shell "getprop ro.build.version.sdk"
info: [debug] Device is at API Level 23
info: [debug] executing cmd: C:\Android\android-sdk-windows\platform-tools\adb.exe -s 03157df388c7b934 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n com.pnc.ecommerce.mobile.finder/com.fisglobal.lfi.pnc.ui.MainActivity"
info: [debug] Waiting for pkg "com.pnc.ecommerce.mobile.finder" and activity "com.fisglobal.lfi.pnc.ui.MainActivity" to be focused
info: [debug] Getting focused package and activity
info: [debug] executing cmd: C:\Android\android-sdk-windows\platform-tools\adb.exe -s 03157df388c7b934 shell "dumpsys window windows"
info: [debug] executing cmd: C:\Android\android-sdk-windows\platform-tools\adb.exe -s 03157df388c7b934 shell "getprop ro.build.version.release"
info: [debug] Device is at release version 6.0.1
info: [debug] Device launched! Ready for commands
info: [debug] Setting command timeout to the default of 60 secs
info: [debug] Appium session started with sessionId 4950142d-270c-433f-ba7f-c6fdea58f76a
info: <-- POST /wd/hub/session 303 5351.163 ms - 74 
info: --> GET /wd/hub/session/4950142d-270c-433f-ba7f-c6fdea58f76a {}
info: [debug] Responding to client with success: {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"6.0.1","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"appPackage":"com.pnc.ecommerce.mobile.finder","appActivity":"com.fisglobal.lfi.pnc.ui.MainActivity","browserName":"Android","platformName":"Android","deviceName":"03157df388c7b934","version":"6.0.1"},"appPackage":"com.pnc.ecommerce.mobile.finder","appActivity":"com.fisglobal.lfi.pnc.ui.MainActivity","platformName":"Android","deviceName":"03157df388c7b934","version":"6.0.1"},"sessionId":"4950142d-270c-433f-ba7f-c6fdea58f76a"}
info: <-- GET /wd/hub/session/4950142d-270c-433f-ba7f-c6fdea58f76a 200 3.558 ms - 705 {"status":0,"value":{"platform":"LINUX","browserName":"Android","platformVersion":"6.0.1","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"appPackage":"com.pnc.ecommerce.mobile.finder","appActivity":"com.fisglobal.lfi.pnc.ui.MainActivity","browserName":"Android","platformName":"Android","deviceName":"03157df388c7b934","version":"6.0.1"},"appPackage":"com.pnc.ecommerce.mobile.finder","appActivity":"com.fisglobal.lfi.pnc.ui.MainActivity","platformName":"Android","deviceName":"03157df388c7b934","version":"6.0.1"},"sessionId":"4950142d-270c-433f-ba7f-c6fdea58f76a"}
Killed Node Server.
Appium server process ended >>

请帮我解决这个问题

共有1个答案

微生永春
2023-03-14

测试开始后,尝试从终端运行adb logcat。您可以在屏幕上不断显示的日志中找到Java运行时异常。如果你仍然无法弄清坠机的细节。只需执行adb日志

 类似资料:
  • 我在Cucumber自动化框架中使用Ruby来自动化我的Android和iOS应用程序。我正在使用Appium 1.6.4测试版,因为它支持iOS 10.2。 当Appium服务器首次在设备上安装iOS应用程序时,会出现一个警报对话框,询问是否允许通知。据我所知,使用Appium时,“自动接受器”功能目前不起作用。 我的主要问题是如何检查警报对话框是否存在,然后使用类似“查找元素”的功能按下“允许

  • 我最近开始研究iOS本机应用程序自动化- MAC OS 10.10.2iOS模拟器-iPhone 5s,iOS8.1 Appium 1.3.4 应用在应用商店中-我正在使用此应用商店应用的.App文件 Appium.app中的iOS设置-应用路径-为.app文件提供路径强制设备-模拟器设备 代码- 我还尝试只在代码中提供应用程序路径,但没有在appium.app中提供,我尝试使用和不使用应用程序的

  • 在以前的代码上,谁医生帮了我 现在,android应用程序在我的手机上运行时崩溃了,这是错误日志 第一个问题是在我用相机扫描二维码后,它不能显示在二维码的结果进入 第二个问题是,我从存储器中选择了一个QRcode图像,然后点击确认,它崩溃了 下面是我认为的问题 类型不匹配:推断的类型是Uri?但乌里是意料之中的 冗余SAM构造函数 'onRequestPermissionsResult(Int,数

  • 在这一点上,我只是不知道该去哪里找。Appium网站似乎没有关于用于测试的命令的详细文档。

  • 主要活动 碎片 这是一个简单对话框的代码。 这里有一个我从中学习的链接。如果我只需通过调用按钮创建对话框,它就可以完全正常工作。