当前位置:  开发笔记 > 编程语言 > 正文

无法使用appium在真实设备上执行任何操作以实现本机应用程序自动化

如何解决《无法使用appium在真实设备上执行任何操作以实现本机应用程序自动化》经验,为你挑选了1个好方法。

我正在尝试使用Appium来测试计算器应用程序(仅出于知识目的)。但是我无法执行任何操作。以下是详细信息:
Real Mobile:小米Redmi注意事项3
Android版本:6.0.1
MIUI:8.1
Appium版本:1.4.16
Android SDK版本:24.4.1
appium Java客户端:4.1.2
代码:

package unittest;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Properties;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;

public class LaunchWardRobe {

    @Test
    public void swipeTest() throws IOException {
        String propFileName = "wardrobe.properties";
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(propFileName);
        Properties prop = new Properties();
        prop.load(inputStream);
        DesiredCapabilities cap = new DesiredCapabilities();
        cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, prop.getProperty("cap.platform.version"));
        cap.setCapability(MobileCapabilityType.PLATFORM_NAME, prop.getProperty("cap.platform.name"));
        cap.setCapability(MobileCapabilityType.DEVICE_NAME, prop.getProperty("cap.device.name"));
        cap.setCapability("appPackage", prop.getProperty("cap.app.package"));
        cap.setCapability("appActivity", prop.getProperty("cap.app.activity"));
        cap.setCapability(MobileCapabilityType.BROWSER_NAME, "");
        cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
        AndroidDriver browser = new AndroidDriver(
                new URL(prop.getProperty("cap.hub.url")), cap);
        MobileElement dig5 = browser.findElement(By.id("com.miui.calculator:id/btn_5"));
        dig5.tap(1, 3);
        dig5.click();
        browser.closeApp();
    }
}

属性文件:

cap.platform.version=6.0.1
cap.platform.name=Android
cap.device.name=Redmi
cap.app.package=com.miui.calculator
cap.app.activity=com.miui.calculator.cal.CalculatorActivity
cap.hub.url=http://127.0.0.1:4723/wd/hub

Eclipse控制台IDE上的异常或stacktrace:

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 410 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'mrunal-laptop', ip: '192.168.56.1', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_111'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities [{appPackage=com.miui.calculator, networkConnectionEnabled=true, warnings={}, databaseEnabled=false, deviceName=80b83390, platform=LINUX, appActivity=com.miui.calculator.cal.CalculatorActivity, desired={appPackage=com.miui.calculator, appActivity=com.miui.calculator.cal.CalculatorActivity, platformVersion=6.0.1, automationName=Appium, browserName=, platformName=Android, deviceName=Redmi}, platformVersion=6.0.1, webStorageEnabled=false, locationContextEnabled=false, automationName=Appium, browserName=, takesScreenshot=true, javascriptEnabled=true, platformName=Android}]
Session ID: caa419ad-6146-47e0-a1b1-ef700d6645e6
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:678)
    at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:40)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
    at io.appium.java_client.AppiumDriver.performTouchAction(AppiumDriver.java:336)
    at io.appium.java_client.MultiTouchAction.perform(MultiTouchAction.java:71)
    at io.appium.java_client.AppiumDriver.tap(AppiumDriver.java:361)
    at io.appium.java_client.MobileElement.tap(MobileElement.java:50)
    at unittest.LaunchWardRobe.swipeTest(LaunchWardRobe.java:33)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Appium日志:

info: [debug] Appium session started with sessionId caa419ad-6146-47e0-a1b1-ef700d6645e6 info: <-- POST /wd/hub/session 303 10720.889 ms - 74  info: --> GET /wd/hub/session/caa419ad-6146-47e0-a1b1-ef700d6645e6 {} info: [debug] Responding to client with success: {"status":0,"value":{"platform":"LINUX","browserName":"","platformVersion":"6.0.1","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"appPackage":"com.miui.calculator","appActivity":"com.miui.calculator.cal.CalculatorActivity","platformVersion":"6.0.1","automationName":"Appium","browserName":"","platformName":"Android","deviceName":"Redmi"},"appPackage":"com.miui.calculator","appActivity":"com.miui.calculator.cal.CalculatorActivity","automationName":"Appium","platformName":"Android","deviceName":"80b83390"},"sessionId":"caa419ad-6146-47e0-a1b1-ef700d6645e6"} info: <-- GET /wd/hub/session/caa419ad-6146-47e0-a1b1-ef700d6645e6 200 1.228 ms - 700 {"status":0,"value":{"platform":"LINUX","browserName":"","platformVersion":"6.0.1","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"appPackage":"com.miui.calculator","appActivity":"com.miui.calculator.cal.CalculatorActivity","platformVersion":"6.0.1","automationName":"Appium","browserName":"","platformName":"Android","deviceName":"Redmi"},"appPackage":"com.miui.calculator","appActivity":"com.miui.calculator.cal.CalculatorActivity","automationName":"Appium","platformName":"Android","deviceName":"80b83390"},"sessionId":"caa419ad-6146-47e0-a1b1-ef700d6645e6"} info: --> POST /wd/hub/session/caa419ad-6146-47e0-a1b1-ef700d6645e6/element {"using":"id","value":"com.miui.calculator:id/btn_5"} info: [debug] Waiting up to 0ms for condition info: [debug] Pushing command to appium work queue: ["find",{"strategy":"id","selector":"com.miui.calculator:id/btn_5","context":"","multiple":false}] info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"id","selector":"com.miui.calculator:id/btn_5","context":"","multiple":false}} info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION info: [debug] [BOOTSTRAP] [debug] Got command action: find info: [debug] [BOOTSTRAP] [debug] Finding com.miui.calculator:id/btn_5 using ID with the contextId:  multiple: false info: [debug] [BOOTSTRAP] [debug] Using: UiSelector[INSTANCE=0, RESOURCE_ID=com.miui.calculator:id/btn_5] info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":{"ELEMENT":"1"}} info: [debug] Responding to client with success: {"status":0,"value":{"ELEMENT":"1"},"sessionId":"caa419ad-6146-47e0-a1b1-ef700d6645e6"} info: <-- POST /wd/hub/session/caa419ad-6146-47e0-a1b1-ef700d6645e6/element 200 82.020 ms - 87 {"status":0,"value":{"ELEMENT":"1"},"sessionId":"caa419ad-6146-47e0-a1b1-ef700d6645e6"} info: --> POST /wd/hub/session/caa419ad-6146-47e0-a1b1-ef700d6645e6/touch/perform {"actions":[{"action":"press","options":{"element":"1"}},{"action":"wait","options":{"ms":3}},{"action":"release","options":{}}]} info: [debug] Pushing command to appium work queue: ["element:getLocation",{"elementId":"1"}] info: [debug] Pushing command to appium work queue: ["element:getSize",{"elementId":"1"}] info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:getLocation","params":{"elementId":"1"}} info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION info: [debug] [BOOTSTRAP] [debug] Got command action: getLocation info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":{"x":270,"y":1317}} info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:getSize","params":{"elementId":"1"}} info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION info: [debug] [BOOTSTRAP] [debug] Got command action: getSize info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":{"width":270,"height":201}} info: [debug] Pushing command to appium work queue: ["element:getLocation",{"elementId":"1"}] info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:getLocation","params":{"elementId":"1"}} info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION info: [debug] [BOOTSTRAP] [debug] Got command action: getLocation info: [debug] Pushing command to appium work queue: ["element:getSize",{"elementId":"1"}] info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":{"x":270,"y":1317}} info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:getSize","params":{"elementId":"1"}} info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION info: [debug] [BOOTSTRAP] [debug] Got command action: getSize info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":{"width":270,"height":201}} info: [debug] Pushing command to appium work queue: ["element:touchDown",{"elementId":"1","x":405,"y":1417.5}] info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:touchDown","params":{"elementId":"1","x":405,"y":1417.5}} info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION info: [debug] [BOOTSTRAP] [debug] Got command action: touchDown info: [debug] [BOOTSTRAP] [debug] Performing TouchDown using element? true x: 405, y: 1417 info: [debug] [BOOTSTRAP] [error] error while invoking method private boolean com.android.uiautomator.core.InteractionController.touchDown(int,int) on object com.android.uiautomator.core.InteractionController@358f4be with parameters [405, 1417] null info: [debug] [BOOTSTRAP] [debug] Problem invoking touchDown: java.lang.RuntimeException: error while invoking method private boolean com.android.uiautomator.core.InteractionController.touchDown(int,int) on object com.android.uiautomator.core.InteractionController@358f4be with parameters [405, 1417] info: [debug] Responding to client with error: {"status":13,"value":{"message":"An unknown server-side error occurred while processing the command.","origValue":"Failed to execute touch event"},"sessionId":"caa419ad-6146-47e0-a1b1-ef700d6645e6"} info: <-- POST /wd/hub/session/caa419ad-6146-47e0-a1b1-ef700d6645e6/touch/perform 500 358.523 ms - 198  info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":13,"value":"Failed to execute touch event"}

小智.. 5

我也遇到了同样的问题,并找到了解决方案,Redmi note 3仅在启用该操作后才在开发人员选项中具有额外的安全性,然后我尝试并为我工作。尝试:

    转到开发者选项

    在这里,在USB调试下方(已启用),您将找到另一个选项“ USB调试(安全设置)”

    启用此功能,它将弹出一些警告弹出窗口,并保持允许状态,然后将其启用,现在可以执行所有操作。测试完成后,您可以禁用此功能。

在此处输入图片说明



1> 小智..:

我也遇到了同样的问题,并找到了解决方案,Redmi note 3仅在启用该操作后才在开发人员选项中具有额外的安全性,然后我尝试并为我工作。尝试:

    转到开发者选项

    在这里,在USB调试下方(已启用),您将找到另一个选项“ USB调试(安全设置)”

    启用此功能,它将弹出一些警告弹出窗口,并保持允许状态,然后将其启用,现在可以执行所有操作。测试完成后,您可以禁用此功能。

在此处输入图片说明

推荐阅读
保佑欣疼你的芯疼
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有