无法使用appium在模拟器中使用

时间:2017-08-02 10:48:15

标签: java automation appium

我正在使用 Selenium java jar 版本:3.4.0 桌面版的 appium :1.4.13.1 java客户端版本: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显示错误,但同时模拟器显示该应用程序已安装 任何人有同样的问题?请建议解决方案

1 个答案:

答案 0 :(得分:1)

  1. 确保在appium中正确配置apk文件的路径,如图所示: Android settings for app
  2. 点击播放按钮确认appium正在运行:image
  3. 确保在代码中正确配置了apk的路径。
  4. 一些所需的功能配置:

    DesiredCapabilities capabilities = new DesiredCapabilities();         capabilities.setCapability(CapabilityType.BROWSER_NAME, “”);         capabilities.setCapability( “设备名称”, “机器人”);         capabilities.setCapability( “设备”, “机器人”);         capabilities.setCapability( “takesScreenshot”, “真”);         capabilities.setCapability( “platformName”, “机器人”);         文件app =新文件(“app-qa-release.apk”);         capabilities.setCapability(“app”,app.getAbsolutePath());         driver = new AndroidDriver(新网址(“http://127.0.0.1:4723/wd/hub”),功能);