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

无法使用appium在emulator中访问android应用程序

殳智志
2023-03-14

我正在使用SeleniumJavaJAR版本:3.4.0Appium,桌面版本:1.4.13.1Java客户端版本:5.0.0-BETA9

代码和所需的功能是:

import org.openqa.selenium.remote.DesiredCapabilities;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;

public class base { 
    public static void main(String[] args) throws MalformedURLException, InterruptedException{
        File apk = new File("src");
        File fs = new File(apk,"betaWFM-v19_15thJune2017.apk");


        DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Test");
        cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, "50");
        cap.setCapability(MobileCapabilityType.APP, fs.getAbsolutePath() );
        AndroidDriver<AndroidElement> driver= new AndroidDriver<>(new URL("http://127.0.0.1:4723/wd/hub"), cap); 
        driver.quit();
    }

}

但当我运行它时,在eclipse控制台中出现了以下错误:

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Command failed: Failed to install C:\Program Files (x86)\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]
) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'LMKT-LT-81', ip: '10.11.11.57', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_131'
Driver info: driver.version: AndroidDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:215)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:167)
at io.appium.java_client.remote.AppiumProtocolHandShake.createSession(AppiumProtocolHandShake.java:161)
at io.appium.java_client.remote.AppiumProtocolHandShake.createSession(AppiumProtocolHandShake.java:76)
at io.appium.java_client.remote.AppiumCommandExecutor.doExecute(AppiumCommandExecutor.java:111)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:162)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:250)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:236)
at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:137)
at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:88)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:112)
at io.appium.java_client.android.AndroidDriver.<init>(AndroidDriver.java:73)
at base.main(base.java:21)

以下是appium的错误:

> 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
> warn: Appium support for versions of node < 0.12 has been deprecated and will be removed in a future version. Please upgrade!
> info: Welcome to Appium v1.4.13 (REV c75d8adcb66a75818a542fe1891a34260c21f76a)
> 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 {"capabilities":[{"desiredCapabilities":{"app":"C:\\Users\\sisatti\\workspace\\Sel3.4\\src\\betaWFM-v19_15thJune2017.apk","platformName":"Android","deviceName":"Test","newCommandTimeout":"50"}},{"requiredCapabilities":{}}],"desiredCapabilities":{"app":"C:\\Users\\sisatti\\workspace\\Sel3.4\\src\\betaWFM-v19_15thJune2017.apk","platformName":"Android","deviceName":"Test","newCommandTimeout":"50"},"requiredCapabilities":{}}
> info: Client User-Agent string: Apache-HttpClient/4.5.3 (Java/1.8.0_131)
> 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:\Users\sisatti\workspace\Sel3.4\src\betaWFM-v19_15thJune2017.apk
> info: [debug] Creating new appium session b22f01e6-aa1f-40df-b4bf-242f7be87eaf
> 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:\Users\sisatti\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\sisatti\AppData\Local\Android\sdk\build-tools\26.0.1\aapt.exe
> info: [debug] Extracting package and launch activity from manifest.
> info: [debug] executing cmd: C:\Users\sisatti\AppData\Local\Android\sdk\build-tools\26.0.1\aapt.exe dump badging C:\Users\sisatti\workspace\Sel3.4\src\betaWFM-v19_15thJune2017.apk
> info: [debug] badging package: com.lmkt.wfmdemo
> info: [debug] badging act: com.lmkt.wfmdemo.activities.LaunchScreenActivity
> info: [debug] Parsed package and activity are: com.lmkt.wfmdemo/com.lmkt.wfmdemo.activities.LaunchScreenActivity
> 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\sisatti\AppData\Local\Android\sdk\platform-tools\adb.exe devices
> info: [debug] 1 device(s) connected
> info: Found device emulator-5554
> info: [debug] Setting device id to emulator-5554
> info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
> info: [debug] executing cmd: C:\Users\sisatti\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 wait-for-device
> info: [debug] executing cmd: C:\Users\sisatti\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 shell "echo 'ready'"
> info: [debug] Starting logcat capture
> info: [debug] Getting device API level
> info: [debug] executing cmd: C:\Users\sisatti\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 shell "getprop ro.build.version.sdk"
> info: [debug] Device is at API Level 24
> info: Device API level is: 24
> info: [debug] Extracting strings for language: default
> info: [debug] executing cmd: C:\Users\sisatti\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 shell "getprop persist.sys.language"
> info: [debug] Current device persist.sys.language: 
> info: [debug] java -jar "C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\jars\appium_apk_tools.jar" "stringsFromApk" "C:\Users\sisatti\workspace\Sel3.4\src\betaWFM-v19_15thJune2017.apk" "C:\Users\sisatti\AppData\Local\Temp\com.lmkt.wfmdemo" 
> info: [debug] Reading strings from converted strings.json
> info: [debug] Setting language to default
 info: [debug] executing cmd: C:\Users\sisatti\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 push "C:\\Users\\sisatti    \\AppData\\Local\\Temp\\com.lmkt.wfmdemo\\strings.json" /data/local/tmp
> info: [debug] Checking whether aapt is present
> info: [debug] Using aapt from C:\Users\sisatti\AppData\Local\Android\sdk\build-tools\26.0.1\aapt.exe
> info: [debug] Retrieving process from manifest.
> info: [debug] executing cmd: C:\Users\sisatti\AppData\Local\Android\sdk\build-tools\26.0.1\aapt.exe dump xmltree C:\Users\sisatti\workspace\Sel3.4\src\betaWFM-v19_15thJune2017.apk AndroidManifest.xml
> info: [debug] Set app process to: com.lmkt.wfmdemo
> info: [debug] Not uninstalling app since server not started with --full-reset
> info: [debug] Checking app cert for C:\Users\sisatti\workspace\Sel3.4\src\betaWFM-v19_15thJune2017.apk.
> info: [debug] executing cmd: java -jar "C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-adb\jars\verify.jar" C:\Users\sisatti\workspace\Sel3.4\src\betaWFM-v19_15thJune2017.apk
> info: [debug] App already signed.
> info: [debug] Zip-aligning C:\Users\sisatti\workspace\Sel3.4\src\betaWFM-v19_15thJune2017.apk
> info: [debug] Checking whether zipalign is present
> info: [debug] Using zipalign from C:\Users\sisatti\AppData\Local\Android\sdk\build-tools\26.0.1\zipalign.exe
> info: [debug] Zip-aligning apk.
> info: [debug] executing cmd: C:\Users\sisatti\AppData\Local\Android\sdk\build-tools\26.0.1\zipalign.exe -f 4 C:\Users\sisatti\workspace\Sel3.4\src\betaWFM-v19_15thJune2017.apk C:\Users\sisatti\AppData\Local\Temp\11772-4612-746m00\appium.tmp
> info: [debug] MD5 for app is a4d18a355b0b6ad0eaa66b444e8f557c
> info: [debug] executing cmd: C:\Users\sisatti\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 shell "ls /data/local/tmp/a4d18a355b0b6ad0eaa66b444e8f557c.apk"
> info: [debug] Getting install status for com.lmkt.wfmdemo
> info: [debug] Getting device API level
> info: [debug] executing cmd: C:\Users\sisatti\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 shell "getprop ro.build.version.sdk"
> info: [debug] Device is at API Level 24
> info: [debug] executing cmd: C:\Users\sisatti\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 shell "pm list packages -3 com.lmkt.wfmdemo"
> info: [debug] App is installed
> info: App is already installed, resetting app
> info: [debug] Running fast reset (stop and clear)
> info: [debug] executing cmd: C:\Users\sisatti\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 shell "am force-stop com.lmkt.wfmdemo"
> info: [debug] executing cmd: C:\Users\sisatti\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 shell "pm clear com.lmkt.wfmdemo"
> info: [debug] Forwarding system:4724 to device:4724
> info: [debug] executing cmd: C:\Users\sisatti\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 forward tcp:4724 tcp:4724
> info: [debug] Pushing appium bootstrap to device...
> info: [debug] executing cmd: C:\Users\sisatti\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 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:\Users\sisatti\AppData\Local\Android\sdk\platform-tools\adb.exe -s emulator-5554 install "C:\Program Files (x86)\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk"
> info: [debug] Stopping logcat capture
> info: [debug] Logcat terminated with code null, signal SIGTERM
> info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
> warn: UiAutomator did not shut down fast enough, calling it gone
> error: Failed to start an Appium session, err was: Error: Command failed: Failed to install C:\Program Files (x86)\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]
> 
> info: [debug] Cleaning up android objects
> info: [debug] Cleaning up appium session
> info: [debug] Error: Command failed: Failed to install C:\Program Files (x86)\Appium\node_modules\appium\build\settings_apk\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]
> 
>     at ChildProcess.exithandler (child_process.js:637:15)
>     at ChildProcess.EventEmitter.emit (events.js:98:17)
>     at maybeClose (child_process.js:743:16)
>     at Process.ChildProcess._handle.onexit (child_process.js:810:5)
> info: [debug] Responding to client with error: {"status":33,"value":    {"message":"A new session could not be created.     (Original error: Command failed: Failed to install C:\\Program Files     (x86)\\Appium\\node_modules\\appium\\build\\settings_apk\\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]\r\n)","killed":false,"code":1,"signal":null,"origValue":"Command failed: Failed to install C:\\Program Files (x86)\\Appium\\node_modules\\appium\\build\\settings_apk\\settings_apk-debug.apk: Failure [INSTALL_FAILED_ALREADY_EXISTS: Attempt to re-install io.appium.settings without first uninstalling.]\r\n"},"sessionId":null}
> info: <-- POST /wd/hub/session 500 11271.814 ms - 654 

试图通过更改不同版本来解决,但无法解决。appium正在显示错误,但同时emulator正在显示已安装的应用程序。
有人有相同的问题吗?请提出解决方案

共有1个答案

曹季同
2023-03-14

DesiredCapabilities=新的DesiredCapabilities();setCapability(CapabilityType.BROWSER_NAME,“”);setCapability(“deviceName”、“Android”);能力。设置能力(“设备”、“Android”);能力。设置能力(“takesScreenshot”、“true”);能力。设置能力(“平台名”、“Android”);文件app=新文件(“app qa release.apk”);setCapability(“app”,app.getAbsolutePath());驱动程序=新的AndroidDriver(新的URL(“http://127.0.0.1:4723/wd/hub(能力),;

 类似资料:
  • 当我尝试在ios应用程序中执行刷卡操作时,它会显示此错误。 [org.openqa.selenium.未知命令,除滚动之外的所有移动命令都已删除。(警告:服务器没有提供任何stackTrack信息)。] 请给我答案。

  • 无法启动应用程序,请查找以下相同的跟踪 注意:同样的应用程序与卡拉巴赫工作,即我能够启动应用程序 我正在使用以下功能:

  • 当我在我的设备(Galaxy Note 3和Ouya)上调试一个在Android Studio中编写的应用程序时,该应用程序调试良好,并在设备上运行,但是该应用程序从未出现在应用程序抽屉中,所以我无法在断开连接的设备上运行它(即当我的开发计算机离开时,向其他人显示正在运行的应用程序)。我的应用程序曾经安装为可运行的应用程序,但这似乎不再发生。然而,应用程序在应用程序管理器中被列为一个应用程序,我可

  • 我的操作系统是Windows 7 Pro,我安装了Android Studio 2.1,这是目前最新的版本,我按照本视频教程中的说明安装和设置Genymotion,我完全按照视频中显示的步骤进行操作,但最终我无法在Genymotion中创建的虚拟设备上运行我的应用程序(但在视频中,它运行良好),我得到的是: 如截图所示,左边的模拟器是从AS中的Geny插件启动的,右边的对话框是我点击运行按钮后得到

  • 我正在Android应用程序上进行自动化测试,需要滚动才能看到需要滚动的字段 我尝试从这里使用以下代码: 运行此代码后,会出现以下错误: 嗯,我知道我已经通过了中的驱动程序,该驱动程序的类型是。 我该怎么解决这个问题?

  • LOGCAT: 2021-07-18:01:16.9425655-5655/com。实例Androidinterestcalculator E/AndroidRuntime:致命异常:主进程:com。实例Android有趣的镜头图像描述hereculator,PID:5655 java。lang.RuntimeException:无法启动活动组件信息{com.example.android.int