Appium Toast 消息验证真的可以吗?[已测试验证,可以找到了]

bauul · 2017年04月19日 · 最后由 bauul 回复于 2019年01月31日 · 6124 次阅读
本帖已被设为精华帖!

环境

APPIUM Version: 1.6.3
JAVA Client: 5.0.0
JAVA: 1.8
UiAutomator2 Drvier: 0.2.6

Code

//capabilities
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);
//click the button to verify the toast message
driver.findElementByXPath("//*[contains(@text,'Button')]").click();
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[contains(@text, 'port')]")))

Toast 内容

Toast.makeText(getBaseContext(), "Change port successfully", Toast.LENGTH_SHORT).show();

Result

使用 uiautomator2 启动应用是成功的,点击也是成功的,但是尝试验证 Toast 消息时,没有成功过。错误信息如下:
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for presence of element located by: By.xpath: //*contains(@text, 'port')

Other

手机中有安装两个应用:

  1. io.appium.uiautomator2.server
  2. io.appium.uiautomator2.server.test
//同样的代码,定位符改成一个Button的定位符,是能找到的
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@text='Button']")));


源码打开后,这里的红色标记怎么解决啊,没有任何报错啊,编译也没有问题

appium 提供的单元测试源码

@Test
public void toastVerificationTest() throws JSONException {
    getUiDevice().waitForIdle();
    scrollTo("Views"); // Due to 'Views' option not visible on small screen
    waitForElement(By.accessibilityId("Views"), 10 * SECOND);
    click(findElement(By.accessibilityId("Views")));
    scrollTo("Popup Menu");
    waitForElement(By.accessibilityId("Popup Menu"), 10 * SECOND);
    click(findElement(By.accessibilityId("Popup Menu")));
    waitForElement(By.accessibilityId("Make a Popup!"), 10 * SECOND);
    click(findElement(By.accessibilityId("Make a Popup!")));
    waitForElement(By.xpath(".//*[@text='Search']"), 10 * SECOND);
    click(findElement(By.xpath(".//*[@text='Search']")));
    waitForMilliSeconds(500);
    element = findElement(By.xpath("//*[@text='Clicked popup menu item Search']"));
    String toastMSG = getText(element);
    assertEquals("Clicked popup menu item Search", toastMSG);
    Logger.info("[AppiumUiAutomator2Server]", " findElement By.xpath: " + element);
    assertTrue(By.xpath("//*[@text='Clicked popup menu item Search']") + "not found", isElementPresent(element));

    click(findElement(By.accessibilityId("Make a Popup!")));
    waitForElement(By.xpath(".//*[@text='Add']"), 10 * SECOND);
    click(findElement(By.xpath(".//*[@text='Add']")));
    waitForMilliSeconds(500);
    element = findElement(By.xpath("//*[contains(@text,'Clicked popup menu item Add')]"));
    Logger.info("[AppiumUiAutomator2Server]", " findElement By.xpath: " + element);
    assertTrue(By.xpath("//*[@text='Clicked popup menu item Add']") + "not found", isElementPresent(element));
    toastMSG = getText(element);
    assertEquals("Clicked popup menu item Add", toastMSG);

    click(findElement(By.accessibilityId("Make a Popup!")));
    waitForElement(By.xpath(".//*[@text='Edit']"), 10 * SECOND);
    click(findElement(By.xpath(".//*[@text='Edit']")));
    waitForMilliSeconds(500);
    element = findElement(By.xpath("//*[@text='Clicked popup menu item Edit']"));
    Logger.info("[AppiumUiAutomator2Server]", " findElement By.xpath: " + element);
    assertTrue(By.xpath("//*[@text='Clicked popup menu item Edit']") + "not found", isElementPresent(element));
    toastMSG = getText(element);
    assertEquals("Clicked popup menu item Edit", toastMSG);


    click(findElement(By.xpath(".//*[@text='Share']")));
    waitForMilliSeconds(1000);
    element = findElement(By.xpath("//*[@text='Clicked popup menu item Share']"));
    Logger.info("[AppiumUiAutomator2Server]", " findElement By.xpath: " + element);
    assertTrue(By.xpath("//*[@text='Clicked popup menu item Share']") + "not found", isElementPresent(element));
    toastMSG = getText(element);
    assertEquals("Clicked popup menu item Share", toastMSG);

}

单元测试执行方法:

am instrument -w -e class io.appium.uiautomator2.unittest.test.HandlersTest#toastVerificationTest io.appium.uiautomator2.e2etest.test/android.support.test.runner.AndroidJUnitRunner

单元测试日志:

04-20 12:08:19.134  6055  6068 I appium  : [AppiumUiAutomator2Server] Starting S
erver
04-20 12:08:19.379  6055  6068 I appium  : [AppiumUiAutomator2Server] waiting fo
r app to launch
04-20 12:08:30.028  6055  6068 I appium  : [AppiumUiAutomator2Server] findElemen
t By.xpath: {"sessionId":":sessionId","status":0,"value":{"ELEMENT":"f2e952ea-d5
0c-4b4b-a81e-c1244240c30d"}}
04-20 12:08:32.122  6055  6068 I appium  : [AppiumUiAutomator2Server] findElemen
t By.xpath: {"sessionId":":sessionId","status":0,"value":{"ELEMENT":"4e141e0b-a5
3a-4e46-82d4-cec7cd748640"}}
04-20 12:08:34.646  6055  6068 I appium  : [AppiumUiAutomator2Server] findElemen
t By.xpath: {"sessionId":":sessionId","status":0,"value":{"ELEMENT":"3a16e7f8-86
2d-453e-90be-d70eec2bb85b"}}
04-20 12:08:36.705  6055  6068 I appium  : [AppiumUiAutomator2Server] findElemen
t By.xpath: {"sessionId":":sessionId","status":0,"value":{"ELEMENT":"9fc430ea-19
d5-44cd-b121-031275152d9b"}}

从日志来看,单元测试执行时,是有找到 toast 元素的,但是我在 eclipse 里面写测试用例的时候就是报没有找到,真是头疼

如何 debug 验证?

  1. 在代码中需要的地方打断点
  2. 在手机设置应用中,打开开发者选项,选择调试应用,选择 io.appium.uiautomator2.server.test
  3. 这时候给 server 发请求即可,可通过浏览器直接发请求,建立会话,或执行 appium 代码进入调试

原理解析?

private class Listener extends Thread{

        private long previousTime = currentTimeMillis();

        public void run() {
            while (true) {
                AccessibilityEvent accessibilityEvent = null;
                toastMessages = init();

                //return true if the AccessibilityEvent type is NOTIFICATION type
                UiAutomation.AccessibilityEventFilter eventFilter = new UiAutomation.AccessibilityEventFilter() {
                    @Override
                    public boolean accept(AccessibilityEvent event) {
                        return event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
                    }
                };
                Runnable runnable = new Runnable() {
                    @Override
                    public void run() {
                        // Not performing any event.
                    }
                };

                try {
                    //wait for AccessibilityEvent filter
                    accessibilityEvent = UiAutomatorBridge.getInstance().getUiAutomation()
                            .executeAndWaitForEvent(runnable /*executable event*/, eventFilter /* event to filter*/, 500 /*time out in ms*/);
                } catch (Exception ignore) {}

                if (accessibilityEvent != null) {
                    toastMessages = accessibilityEvent.getText();
                    previousTime = currentTimeMillis();
                    Logger.info("toastMessages:" + toastMessages);
                    GetToastMessage.toastMessage = toastMessages.toString();// add by carl
                }
                if(stopLooping){
                    break;
                }
            }
        }

post 方法

引用 uiautomator2.0 server 的相关 jar,不要引 android.jar,json jar: json-20070829.jar

try {
            Runtime.getRuntime().exec("adb forward tcp:"+ 8201 +" tcp:6790");
            Thread.sleep(2000);

            String sessionId = "";
            //create session
            sessionId = TestHelper.post("/wd/hub/session", new JSONObject().put("desiredCapabilities", new JSONObject()).toString());
            System.out.println(sessionId);
            if (sessionId.contains("sessionId")) {
                sessionId = new JSONObject(sessionId).getString("sessionId");
                System.out.println("sessionId:" + sessionId);
            } else {
                sessionId = "c04ada9b-38cf-4778-9168-12faf6747159";
            }

//          System.out.println(TestHelper.get("/wd/hub/session/" + sessionId + "/getPostMsg"));
//          System.exit(1);

            String elementId = "";

            //find element: Make a Popup!
            JSONObject element = new JSONObject("{\"strategy\":\"xpath\",\"selector\":\"//*[contains(@text,'Make a Popup!')]\",\"context\":\"\",\"multiple\":false}");
            elementId = TestHelper.post("/wd/hub/session/" + sessionId + "/element", element.toString());
            System.out.println("elementId:" + elementId);
            elementId = new JSONObject(elementId).getJSONObject("value").getString("ELEMENT");

            //click one element
            JSONObject click = new JSONObject().put("elementId", elementId);
            TestHelper.post("/wd/hub/session/" + sessionId + "/element/" + elementId + "/click", click.toString());
            TestHelper.waitTimes(2000);

            elementId = TestHelper.post("/wd/hub/session/" + sessionId + "/element", new JSONObject("{\"strategy\":\"xpath\",\"selector\":\"//*[@text='Search']\",\"context\":\"\",\"multiple\":false}").toString());
            System.out.println("elementId:" + elementId);
            elementId = new JSONObject(elementId).getJSONObject("value").getString("ELEMENT");

            //click one element
            TestHelper.post("/wd/hub/session/" + sessionId + "/element/" + elementId + "/click", new JSONObject().put("elementId", elementId).toString());

            for (int i=0; i<2000; i++) {
                elementId = TestHelper.post("/wd/hub/session/" + sessionId + "/element", new JSONObject("{\"strategy\":\"xpath\",\"selector\":\"//*[@text='Clicked popup menu item Search']\",\"context\":\"\",\"multiple\":false}").toString());
                if (!elementId.contains("not")) {
                    System.out.println("i=" + i);
                    System.out.println("elementId:" + elementId);
                    elementId = new JSONObject(elementId).getJSONObject("value").getString("ELEMENT");
                    System.out.println(TestHelper.get("/wd/hub/session/" + sessionId + "/element/" + elementId+ "/attribute/text"));
                    break;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

后感

这绝对是个坑,不过让我学习了 uiautomator2.0 drvier server 的原代码,和 uiautomator1.0 不一样,有点意思。
本人做的改动主要包含:

  1. 修改 private final int TOAST_CLEAR_TIMEOUT = 5000;//原来是 3500,不过肯定不是重点,short 类型的 toast 是没有 5 秒那么久的
  2. 增加 toast listener 启停的日志
  3. 增加了一个新的 get 服务,当有 toast 消息时,便记录下来,即使 toast 消息已经消失,仍然可以 get 出来 toast 的内容
package io.appium.uiautomator2.handler;

import io.appium.uiautomator2.handler.request.SafeRequestHandler;
import io.appium.uiautomator2.http.AppiumResponse;
import io.appium.uiautomator2.http.IHttpRequest;
import io.appium.uiautomator2.server.WDStatus;
import io.appium.uiautomator2.utils.Logger;

public class GetToastMessage extends SafeRequestHandler {

    public static String toastMessage = "defalut value is null";//值由GetToastMessage.toastMessage = toastMessages.toString();// add by carl这句更新

    public GetToastMessage(String mappedUri) {
        super(mappedUri);
    }

    @Override
    public AppiumResponse safeHandle(IHttpRequest request) {
        Logger.info("GetToastMessage command");
        return new AppiumResponse(getSessionId(request), WDStatus.SUCCESS, toastMessage);
    }

}

  1. 重新编译,更新本地路径(appium\node_modules\appium-uiautomator2-driver\uiautomator2)的应用,因为打包好的默认在 c 盘 build the android project using below commands: gradle clean assembleServerDebug assembleServerDebugAndroidTest
  2. 最后仍然有些疑惑,不过主要问题已经解决了。
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 90 条回复 时间 点赞
bauul #98 · 2017年04月19日 Author

测试了中文,英文都没有成功过,有试成功的同学吗?求指点,是我哪里写的不对吗?

bauul #97 · 2017年04月19日 Author

@seveniruby @tobecrazy
哥哥们给看下呢

bauul #96 · 2017年04月19日 Author

额,哪位大哥大姐成功过,给指点一下呢

可以捕获到 toast,代码没看出问题,直觉还是配置的问题

—— 来自 TesterHome 官方 安卓客户端

雪怪 回复

有没有再具体点的建议啊,哪个配置,我好检查下呢

应该是支持的,论坛里都有人实践过了 https://testerhome.com/topics/6703
还有官方源码也可以看到

wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//*[contains(@text, 'port')]")))

这样试试

bauul #91 · 2017年04月19日 Author

试过了,也不行,不知道为啥,也不能通过 getPageSource 去,检查当前界面到底有没有,真是头疼

尝试一下

By.xpath("//android.widget.TextView[contains(@text,'Change port successfully')]")

可以的,我都成功了,但感觉不好用

—— 来自 TesterHome 官方 安卓客户端

bauul #88 · 2017年04月19日 Author
zzf 回复

可以帮忙把成功的全部日志贴一下吗?

bauul #87 · 2017年04月19日 Author
William 回复

我试了,也是找不到

bauul #86 · 2017年04月19日 Author
zzf 回复

怎么不好用了,或者有更好的方法的吗?

我很是很好奇,我加了 try catch 就是执行成功的,如果单独获取就是报错的,楼主可以加一个 try catch 试一下

bauul #84 · 2017年04月20日 Author
小茗同学 回复

我有加啊,仍然没有成功,我很怀疑你的成功,是不是真的成功。

bauul 回复

你要是这么说的话我就不知道说啥了

bauul #82 · 2017年04月20日 Author
小茗同学 回复

我希望你提供一下,成功时的 APPIUM 日志,拜托

提个想法,没有实现过,不知道可行不可行。。

先开一个线程,让自动化框架监控页面元素(比如 uiautomator2.0 的 mDevice.wait(Until))。
另一个线程完成相关操作,并弹出测试 toast。

bauul #80 · 2017年04月20日 Author
benlee 回复

试了两遍,也是不行

final WebDriverWait wait = new WebDriverWait(driver, 10, 1);
            Activity activity = new Activity("io.appium.android.apis", ".view.PopupMenu1");
            driver.startActivity(activity);
            waitForMilliSeconds(1500);

            WebElement popUpElement = driver.findElement(MobileBy.AccessibilityId("Make a Popup!"));
            popUpElement.click();
            waitForMilliSeconds(500);

            new Thread(
                    new Runnable(){

                        @Override
                        public void run() {
                            try {                               
                                System.out.println(wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(".//*[@text='Clicked popup menu item Search']"))).toString());
                            } catch (Exception e) {
                                System.out.println(" not found");
//                              e.printStackTrace();
                            }

                        }

                    }
                    ).start();

            driver.findElement(By.xpath(".//*[@text='Search']")).click();

            Thread.sleep(9000);

点击之后不要有延迟

bauul #21 · 2017年04月21日 Author
小胖。 回复

试过了啊,没成功

装的 Appium Desktop 1.0.0 ,测试机是红米 1s ,Android 4.4

[Appium] Welcome to Appium v1.6.4
...
[UiAutomator2] UIAutomator2 Driver version:0.3.1

成功找到 toast 时的 Appium server log:

[HTTP] --> POST /wd/hub/session/ae9075be-45da-4503-be52-9f1b8cfdc369/element/42777326-5280-41c1-9790-4182a1aba703/click {}
[MJSONWP] Calling AppiumDriver.click() with args: ["42777326-5280-41c1-9790-4182a1aba703","ae9075be-45da-4503-be52-9f1b8cfdc369"]
[JSONWP Proxy] Proxying [POST /element/42777326-5280-41c1-9790-4182a1aba703/click] to [POST http://localhost:8222/wd/hub/session/84f012ed-714e-4d4b-bcbf-1d1ec0efe46d/element/42777326-5280-41c1-9790-4182a1aba703/click] with body: {"element":"42777326-5280-41c1-9790-4182a1aba703"}
[JSONWP Proxy] Got response with status 200: {"value":true,"status":0,"sessionId":"84f012ed-714e-4d4b-bcbf-1d1ec0efe46d"}
[MJSONWP] Responding to client with driver.click() result: true
[HTTP] <-- POST /wd/hub/session/ae9075be-45da-4503-be52-9f1b8cfdc369/element/42777326-5280-41c1-9790-4182a1aba703/click 200 252 ms - 76 
[HTTP] --> POST /wd/hub/session/ae9075be-45da-4503-be52-9f1b8cfdc369/element {"using":"xpath","value":".//*[contains(@text, \"toast\")]"}
[MJSONWP] Calling AppiumDriver.findElement() with args: ["xpath",".//*[contains(@text, \"toast\")]","ae9075be-45da-4503-be52-9f1b8cfdc369"]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Waiting up to 0 ms for condition
[JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8222/wd/hub/session/84f012ed-714e-4d4b-bcbf-1d1ec0efe46d/element] with body: {"strategy":"xpath","selector":".//*[contains(@text, \"toast\")]","context":"","multiple":false}
[JSONWP Proxy] Got response with status 200: {"value":{"ELEMENT":"1f60e7a9-3fa5-4b9f-92e4-c060a019e3b9"},"status":0,"sessionId":"84f012ed-714e-4d4b-bcbf-1d1ec0efe46d"}
[MJSONWP] Responding to client with driver.findElement() result: {"ELEMENT":"1f60e7a9-3fa5-4b9f-92e4-c060a019e3b9"}
[HTTP] <-- POST /wd/hub/session/ae9075be-45da-4503-be52-9f1b8cfdc369/element 200 94 ms - 122 
[HTTP] --> GET /wd/hub/session/ae9075be-45da-4503-be52-9f1b8cfdc369/element/1f60e7a9-3fa5-4b9f-92e4-c060a019e3b9/attribute/text {}
[MJSONWP] Calling AppiumDriver.getAttribute() with args: ["text","1f60e7a9-3fa5-4b9f-92e4-c060a019e3b9","ae9075be-45da-4503-be52-9f1b8cfdc369"]
[JSONWP Proxy] Proxying [GET /element/1f60e7a9-3fa5-4b9f-92e4-c060a019e3b9/attribute/text] to [GET http://localhost:8222/wd/hub/session/84f012ed-714e-4d4b-bcbf-1d1ec0efe46d/element/1f60e7a9-3fa5-4b9f-92e4-c060a019e3b9/attribute/text] with body: {}
[JSONWP Proxy] Got response with status 200: "{\"value\":\"Hello toast!\",\"status\":0,\"sessionId\":\"84f012ed-714e-4d4b-bcbf-1d1ec0efe46d\"}"
[MJSONWP] Responding to client with driver.getAttribute() result: "Hello toast!"
[HTTP] <-- GET /wd/hub/session/ae9075be-45da-4503-be52-9f1b8cfdc369/element/1f60e7a9-3fa5-4b9f-92e4-c060a019e3b9/attribute/text 200 114 ms - 86 

直接发 HTTP 请求吧

# 点击按钮触发 toast 
curl -X POST --header "Accept:application/json" --header "Content-Type: application/json; charset=utf-8" --data "{}" http://127.0.0.1:4723/wd/hub/session/${session}/element/${toast_button}/click

# 查找 toast ,toast 还没消失的时候才能找到
curl -X POST --header "Accept:application/json" --header "Content-Type: application/json; charset=utf-8" --data "{\"using\":\"xpath\",\"value\":\".//*[contains(@text, \\\"toast\\\")]\"}" http://127.0.0.1:4723/wd/hub/session/${session}/element

# 获取 toast 的内容
curl -X GET --header "Accept:application/json" --header "Content-Type: application/json; charset=utf-8" http://127.0.0.1:4723/wd/hub/session/${session}/element/${toast}/attribute/text
黑水 回复

感谢,我也试了一下,使用 post 请求验证成功了。

@carl 请教一下,有没有遇到过这个问题

[2017-04-27 07:06:45][UiAutomator2] Starting uiautomator2 server v0.1.4 with cmd: am,instrument,-w,io.appium.uiautomator2.server.test/android.support.test.runner.AndroidJUnitRunner
[2017-04-27 07:06:45][UiAutomator2] running command...
 adb -s 760BBL522XW3 shell am instrument -w io.appium.uiautomator2.server.test/android.support.test.runner.AndroidJUnitRunner... 
[2017-04-27 07:06:45][UiAutomator2] Waiting for UiAutomator2 to be online...
[2017-04-27 07:06:45][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-04-27 07:06:46][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-04-27 07:06:48][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-04-27 07:06:49][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-04-27 07:06:50][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-04-27 07:06:51][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-04-27 07:06:52][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-04-27 07:06:53][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-04-27 07:06:54][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-04-27 07:06:55][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-04-27 07:06:56][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-04-27 07:06:57][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-04-27 07:06:58][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-04-27 07:06:59][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-04-27 07:07:00][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-04-27 07:07:01][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-04-27 07:07:02][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-04-27 07:07:03][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-04-27 07:07:04][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-04-27 07:07:05][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-04-27 07:07:06][UiAutomator2] Deleting UiAutomator2 session
[2017-04-27 07:07:06][UiAutomator2] Deleting UiAutomator2 server session
[2017-04-27 07:07:06][UiAutomator2] Did not get confirmation UiAutomator2 deleteSession worked; Error was: Error: Trying to proxy a session command without session id
[2017-04-27 07:07:06][ADB] Getting connected devices...
[2017-04-27 07:07:06][ADB] 1 device(s) connected
[2017-04-27 07:07:06][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","760BBL522XW3","shell","am","force-stop","cn.lejiayuan.alpha"]
[2017-04-27 07:07:06][Logcat] Stopping logcat capture
[2017-04-27 07:07:06][ADB] Removing forwarded port socket connection: 8200 
[2017-04-27 07:07:06][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","760BBL522XW3","forward","--remove","tcp:8200"]
[2017-04-27 07:07:06][MJSONWP] Encountered internal error running command: ProxyRequestError: Could not proxy command to remote server. Original error: Error: socket hang up
    at JWProxy.proxy$ (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:144:13)
    at tryCatch (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
[2017-04-27 07:07:06][HTTP] <-- POST /wd/hub/session 500 31087 ms - 216 

应该是这个命令启动 server 失败了?

adb -s 760BBL522XW3 shell am instrument -w io.appium.uiautomator2.server.test/android.support.test.runner.AndroidJUnitRunner

连接不到http://localhost:8200/wd/hub/status
但是不知道怎么解决...

bauul #73 · 2017年04月27日 Author

遇到过的,是手机中的两个 server 和 server test 的 APK 没装全,可能只装了一个,把它卸载,再重新执行一遍就好了

bauul #72 · 2017年04月27日 Author
CleverMing 回复

io.appium.uiautomator2.server
io.appium.uiautomator2.server.test
这两个应用,可以在 设置 -> 应用中查看

恒温 将本帖设为了精华贴 04月28日 00:23
bauul 回复

😅 贼恐怖,我这俩一个都没有...

莫非还有什么特殊的配置?应该是配置 AUTOMATION_NAME 为 uiautomator2 就可以自动安装?

bauul #69 · 2017年04月28日 Author
CleverMing 回复

appium\node_modules\appium-uiautomator2-driver\uiautomator2
检查这个目录有没有两个 APK,没有的话就两个方法:

  1. 去 github 网站下载
  2. 有源码的话可以本地重新编译
bauul 回复

我仔细找了一下,由于使用的是 appium-decktop 1.0 的 dmg 安装的 appium,uiautomator2 的目录比较深,在这里能找到 apk:

../Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-driver/uiautomator2

apk 的名字是这两个

现在问题是为啥没安装呢.. appium server 的日志里没找到安装这俩 app 的日志

'automationName': 'Uiautomator2'

find_element_by_xpath('//*[@text="XXXX"]) XXX:toast 信息,亲测可用

bauul #66 · 2017年04月28日 Author
HengF丶 回复

嗯,已解决

请问下,我用的是 appium1.6.4,jdk1.8,selenium3.3.1.添加 capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);这句后,就没办法初始化 driver,报错信息如下
Bad parameters: BadParametersError: Parameters were incorrect.
We wanted {"required":["desiredCapabilities"],"optional":["requiredCapabilities
","capabilities","sessionId","id"]} and you sent ["capabilities"],请问大家有遇到过吗?这是哪里有问题?

bauul #64 · 2017年05月04日 Author
songer 回复

把你设置 capabilities 和创建 drvier 的代码贴出来看下

bauul 回复

protected AndroidDriver driver;

@Parameters({ "serverIP","port", "platformName","udid",
"appPackage", "appActivity" })
@BeforeTest
public void setUp(String serverIP,String port,String platformName,String udid,
String appPackage,String appActivity) throws Exception {

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("platformName", platformName);
capabilities.setCapability("deviceName", udid);

capabilities.setCapability("udid", udid);

capabilities.setCapability("platformVersion", "6.0");
capabilities.setCapability("unicodeKeyboard", true);

capabilities.setCapability("resetKeyboard", true);
capabilities.setCapability("noReset", true);
capabilities.setCapability("noSign", true);
capabilities.setCapability("appPackage", appPackage);
capabilities.setCapability("appActivity", appActivity);
capabilities.setCapability("automationName","uiautomator2");
driver = new AndroidDriver(new URL("http://" + serverIP + ":" + port + "/wd/hub"),capabilities);
}

bauul 回复

protected AndroidDriver driver;最上面这句是这样的不知贴上去怎么变了,注释 capabilities.setCapability("automationName","uiautomator2");这句,就可以跑起来

bauul #61 · 2017年05月04日 Author
songer 回复

切到 ui2.0 后,会在手机上安装本文中提到的两个 APK,它有可能弹出是否允许的对话框 ,需要手动点击允许,检查一下,你手机上是否有安装这两个 APK,如果没有,再检查你的 APPIUM 目录,是否有 uiautomator2 的 driver
appium\node_modules\appium-uiautomator2-driver\uiautomator2


按路径有找到,但是手机没有安装,没任何提示?

bauul #59 · 2017年05月04日 Author
songer 回复

那可能是最新的代码改坏了的关系吧,我这是 1.6.3 的 appium 没问题你试一下用这句替换你的那一句呢,capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);

bauul #58 · 2017年05月04日 Author
songer 回复

https://github.com/appium/appium/issues/8263
在 github 上面有同样的问题,你看下吧

bauul 回复

两种写法是一样的,都试过不行,我手动装了了两个应用,看服务有多这些提示
[UiAutomator2] running command...
adb -s WTKDU16707010313 shell am instrument -w io.appium.uiautomator2.server.te
st/android.support.test.runner.AndroidJUnitRunner...
[UiAutomator2] Waiting for UiAutomator2 to be online...
[debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/h
ub/status] with no body
[debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/h
ub/status] with no body
[debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/h
ub/status] with no body
最后还是报 Bad parameters: BadParametersError: Parameters were incorrect.
We wanted {"required":["desiredCapabilities"],"optional":["requiredCapabilities
","capabilities","sessionId","id"]} and you sent ["capabilities"] 这个结束了

bauul #56 · 2017年05月04日 Author
songer 回复

嗯,可以用 1.6.3 的版本试下,或者更新到 1.6.5 试下,github 上这个问题已经被 close 掉了

bauul 回复


appium 换成 1.6.3,selenium3.0.1,java-client 5.0.0-BETA3,换成跟你一样的版本,不过 UiAutomator2 Drvier 显示是 0.2.3,出现的结果 testng 报上面错误,appium 服务还是报相同错误,然后手机没办法装那两个 apk

bauul #54 · 2017年05月04日 Author
songer 回复

我用是 java client beta6, selenium3.3.1,你试下

也就是楼主你也没遇到过?我几个版本试过了,都是没办法装那两个 apk

bauul #47 · 2017年05月04日 Author
songer 回复

没遇见过这种错误

51楼 已删除
bauul #49 · 2017年05月05日 Author

引的 jar 包不对的关系

UiAutomator2 Drvier: 0.2.6 你这个是单独更新的嘛?安装 appium 自带的,怎么更新?

bauul #51 · 2017年05月05日 Author
songer 回复

安装 appium 自带的,如果要更新的话,可以把 appium-uiautomator2-driver 目录删掉,再重新执行 npm install 去安装
appium\node_modules\appium-uiautomator2-driver

bauul 回复

这样盲目删掉更新是不行的,appium-uiautomator2-driver 有很多依赖,对依赖的版本也有要求,我试过了,起不来,就不知道大神们都是怎么做的,后面我自己的问题找到了,跑起来,后面就没有阻碍了,可以成功找到 toast,没遇到你遇到的问题,谢谢你哈

bauul #46 · 2017年05月06日 Author
songer 回复

删掉这个目录再安装我试过不止一次,没问题。

songer 回复

问下你 Uiautomator2 启动 server 没有自动安装 apk 的问题是怎么解决的?

bauul #44 · 2017年05月08日 Author
CleverMing 回复

贴下你的日志看看报什么错没有

CleverMing 回复

看一下你 sdk 有没有 zipalign.exe 这个工具,他安装前,需要优化压缩 apk,这个过程是必须的。我是 sdk 没有这个工具导致的

songer 回复

@songer Android sdk 的 tools 目录确实没有这个工具,看网上说 Android SDK Build-tools 20 就已经修复了,我都 25 的版本了很奇怪为啥还是没有,我从 build-tools 目录中找了个版本里面有 zipalign,复制到 tools 目录后还是不行,应该不是同一个原因
@carl 完整建立 Session 日志如下

[2017-05-08 11:06:30][Appium] Welcome to Appium v1.6.4
[2017-05-08 11:06:30][Appium] Non-default server args:
[2017-05-08 11:06:30][Appium]   address: 127.0.0.1
[2017-05-08 11:06:30][Appium]   sessionOverride: true
[2017-05-08 11:06:30][Appium]   log: /Users/sqbj/Documents/appium/Log
[2017-05-08 11:06:30][Appium]   logTimestamp: true
[2017-05-08 11:06:30][Appium] Appium REST http interface listener started on 127.0.0.1:4723
[2017-05-08 11:06:40][HTTP] --> POST /wd/hub/session {"capabilities":[{"desiredCapabilities":{"app":"/Users/sqbj/dev/lehome/mobileUITest/res/sqbj_android.apk","appPackage":"cn.lejiayuan.alpha","deviceName":"Mi5","appActivity":"cn.lejiayuan.activity.global.SplashActivity","newCommandTimeout":600,"autoLaunch":false,"platformVersion":"6.0.1","automationName":"UIAutomator2","unicodeKeyboard":true,"platformName":"Android","udid":"79ed76ef","resetKeyboard":true}},{"requiredCapabilities":{}}],"desiredCapabilities":{"app":"/Users/sqbj/dev/lehome/mobileUITest/res/sqbj_android.apk","appPackage":"cn.lejiayuan.alpha","deviceName":"Mi5","appActivity":"cn.lejiayuan.activity.global.SplashActivity","newCommandTimeout":600,"autoLaunch":false,"platformVersion":"6.0.1","automationName":"UIAutomator2","unicodeKeyboard":true,"platformName":"Android","udid":"79ed76ef","resetKeyboard":true},"requiredCapabilities":{}}
[2017-05-08 11:06:40][MJSONWP] Calling AppiumDriver.createSession() with args: [{"app":"/Users/sqbj/dev/lehome/mobileUITest/res/sqbj_android.apk","appPackage":"cn.lejiayuan.alpha","deviceName":"Mi5","appActivity":"cn.lejiayuan.activity.global.SplashActivity","newCommandTimeout":600,"autoLaunch":false,"platformVersion":"6.0.1","automationName":"UIAutomator2","unicodeKeyboard":true,"platformName":"Android","udid":"79ed76ef","resetKeyboard":true},{},[{"desiredCapabilities":{"app":"/Users/sqbj/dev/lehome/mobileUITest/res/sqbj_android.apk","appPackage":"cn.lejiayuan.alpha","deviceName":"Mi5","appActivity":"cn.lejiayuan.activity.global.SplashActivity","newCommandTimeout":600,"autoLaunch":false,"platformVersion":"6.0.1","automationName":"UIAutomator2","unicodeKeyboard":true,"platformName":"Android","udid":"79ed76ef","resetKeyboard":true}},{"requiredCapabilities":{}}],null,null]
[2017-05-08 11:06:40][BaseDriver] Event 'newSessionRequested' logged at 1494212800853 (11:06:40 GMT+0800 (CST))
[2017-05-08 11:06:40][Appium] Creating new AndroidUiautomator2Driver (v0.3.1) session
[2017-05-08 11:06:40][Appium] Capabilities:
[2017-05-08 11:06:40][Appium]   app: '/Users/sqbj/dev/lehome/mobileUITest/res/sqbj_android.apk'
[2017-05-08 11:06:40][Appium]   appPackage: 'cn.lejiayuan.alpha'
[2017-05-08 11:06:40][Appium]   deviceName: 'Mi5'
[2017-05-08 11:06:40][Appium]   appActivity: 'cn.lejiayuan.activity.global.SplashActivity'
[2017-05-08 11:06:40][Appium]   newCommandTimeout: 600
[2017-05-08 11:06:40][Appium]   autoLaunch: false
[2017-05-08 11:06:40][Appium]   platformVersion: '6.0.1'
[2017-05-08 11:06:40][Appium]   automationName: 'UIAutomator2'
[2017-05-08 11:06:40][Appium]   unicodeKeyboard: true
[2017-05-08 11:06:40][Appium]   platformName: 'Android'
[2017-05-08 11:06:40][Appium]   udid: '79ed76ef'
[2017-05-08 11:06:40][Appium]   resetKeyboard: true
[2017-05-08 11:06:40][BaseDriver] Session created with session id: b3edbabc-8911-4799-8f64-84a75aff9bb5
[2017-05-08 11:06:40][BaseDriver] Using local app '/Users/sqbj/dev/lehome/mobileUITest/res/sqbj_android.apk'
[2017-05-08 11:06:40][UiAutomator2] Checking whether app is actually present
[2017-05-08 11:06:41][UiAutomator2] UIAutomator2 Driver version:0.3.1
[2017-05-08 11:06:41][AndroidDriver] Getting Java version
[2017-05-08 11:06:41][AndroidDriver] Java version is: 1.8.0_152-ea
[2017-05-08 11:06:41][ADB] Checking whether adb is present
[2017-05-08 11:06:41][ADB] Using adb from /Users/sqbj/Documents/Android_sdk/platform-tools/adb
[2017-05-08 11:06:41][AndroidDriver] Retrieving device list
[2017-05-08 11:06:41][ADB] Trying to find a connected android device
[2017-05-08 11:06:41][ADB] Getting connected devices...
[2017-05-08 11:06:41][ADB] 1 device(s) connected
[2017-05-08 11:06:41][AndroidDriver] Using device: 79ed76ef
[2017-05-08 11:06:41][ADB] Checking whether adb is present
[2017-05-08 11:06:41][ADB] Using adb from /Users/sqbj/Documents/Android_sdk/platform-tools/adb
[2017-05-08 11:06:41][ADB] Setting device id to 79ed76ef
[2017-05-08 11:06:41][ADB] Getting device platform version
[2017-05-08 11:06:41][ADB] Getting connected devices...
[2017-05-08 11:06:41][ADB] 1 device(s) connected
[2017-05-08 11:06:41][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","shell","getprop","ro.build.version.release"]
[2017-05-08 11:06:41][ADB] Getting connected devices...
[2017-05-08 11:06:41][ADB] 1 device(s) connected
[2017-05-08 11:06:41][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","shell","wm","size"]
[2017-05-08 11:06:42][ADB] Getting connected devices...
[2017-05-08 11:06:42][ADB] 1 device(s) connected
[2017-05-08 11:06:42][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","shell","getprop","ro.product.model"]
[2017-05-08 11:06:42][ADB] Current device property 'ro.product.model': MI 5
[2017-05-08 11:06:42][ADB] Getting connected devices...
[2017-05-08 11:06:42][ADB] 1 device(s) connected
[2017-05-08 11:06:42][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","shell","getprop","ro.product.manufacturer"]
[2017-05-08 11:06:42][ADB] Current device property 'ro.product.manufacturer': Xiaomi
[2017-05-08 11:06:42][ADB] Getting connected devices...
[2017-05-08 11:06:42][ADB] 1 device(s) connected
[2017-05-08 11:06:42][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","shell","am","force-stop","io.appium.uiautomator2.server"]
[2017-05-08 11:06:43][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","wait-for-device"]
[2017-05-08 11:06:43][ADB] Getting connected devices...
[2017-05-08 11:06:43][ADB] 1 device(s) connected
[2017-05-08 11:06:43][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","shell","echo","ping"]
[2017-05-08 11:06:43][Logcat] Starting logcat capture
[2017-05-08 11:06:43][AndroidDriver] Enabling Unicode keyboard support
[2017-05-08 11:06:43][AndroidDriver] Pushing unicode ime to device...
[2017-05-08 11:06:43][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","install","/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-android-ime/bin/UnicodeIME-debug.apk"]
[2017-05-08 11:06:44][ADB] Getting connected devices...
[2017-05-08 11:06:44][ADB] 1 device(s) connected
[2017-05-08 11:06:44][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","shell","settings","get","secure","default_input_method"]
[2017-05-08 11:06:45][AndroidDriver] Unsetting previous IME io.appium.android.ime/.UnicodeIME
[2017-05-08 11:06:45][AndroidDriver] Setting IME to 'io.appium.android.ime/.UnicodeIME'
[2017-05-08 11:06:45][ADB] Getting connected devices...
[2017-05-08 11:06:45][ADB] 1 device(s) connected
[2017-05-08 11:06:45][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","shell","ime","enable","io.appium.android.ime/.UnicodeIME"]
[2017-05-08 11:06:46][ADB] Getting connected devices...
[2017-05-08 11:06:46][ADB] 1 device(s) connected
[2017-05-08 11:06:46][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","shell","ime","set","io.appium.android.ime/.UnicodeIME"]
[2017-05-08 11:06:47][AndroidDriver] Pushing settings apk to device...
[2017-05-08 11:06:47][ADB] Getting install status for io.appium.settings
[2017-05-08 11:06:47][ADB] Getting connected devices...
[2017-05-08 11:06:47][ADB] 1 device(s) connected
[2017-05-08 11:06:47][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","shell","pm","list","packages","io.appium.settings"]
[2017-05-08 11:06:47][ADB] App is installed
[2017-05-08 11:06:47][ADB] Getting package info for io.appium.settings
[2017-05-08 11:06:47][ADB] Getting connected devices...
[2017-05-08 11:06:47][ADB] Checking whether aapt is present
[2017-05-08 11:06:47][ADB] Using aapt from /Users/sqbj/Documents/Android_sdk/build-tools/20.0.0/aapt
[2017-05-08 11:06:47][ADB] 1 device(s) connected
[2017-05-08 11:06:47][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","shell","dumpsys","package","io.appium.settings"]
[2017-05-08 11:06:47][ADB] Cannot read version codes of /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/io.appium.settings/app/build/outputs/apk/settings_apk-debug.apk and/or io.appium.settings. Assuming correct app version is already installed
[2017-05-08 11:06:47][ADB] Getting connected devices...
[2017-05-08 11:06:47][ADB] 1 device(s) connected
[2017-05-08 11:06:47][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","shell","getprop","ro.build.version.sdk"]
[2017-05-08 11:06:47][ADB] Device API level: 23
[2017-05-08 11:06:47][ADB] Getting connected devices...
[2017-05-08 11:06:47][ADB] 1 device(s) connected
[2017-05-08 11:06:47][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","shell","dumpsys","package","io.appium.settings"]
[2017-05-08 11:06:48][ADB] Getting connected devices...
[2017-05-08 11:06:48][ADB] 1 device(s) connected
[2017-05-08 11:06:48][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","shell","pm","dump","io.appium.settings"]
[2017-05-08 11:06:48][ADB] Getting connected devices...
[2017-05-08 11:06:48][ADB] 1 device(s) connected
[2017-05-08 11:06:49][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","shell","pm","grant","io.appium.settings","android.permission.WRITE_SETTINGS",";","pm","grant","io.appium.settings","android.permission.ACCESS_MOCK_LOCATION",";"]
[2017-05-08 11:06:49][AndroidDriver] Pushing unlock helper app to device...
[2017-05-08 11:06:49][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","install","/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-unlock/bin/unlock_apk-debug.apk"]
[2017-05-08 11:06:50][ADB] Device API level: 23
[2017-05-08 11:06:50][ADB] Getting connected devices...
[2017-05-08 11:06:50][ADB] 1 device(s) connected
[2017-05-08 11:06:50][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","shell","appops","set","io.appium.settings","android:mock_location","allow"]
[2017-05-08 11:06:51][UiAutomator2] Forwarding UiAutomator2 Server port 6790 to 8200
[2017-05-08 11:06:51][ADB] Forwarding system: 8200 to device: 6790
[2017-05-08 11:06:51][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","forward","tcp:8200","tcp:6790"]
[2017-05-08 11:06:51][ADB] Getting connected devices...
[2017-05-08 11:06:51][ADB] 1 device(s) connected
[2017-05-08 11:06:51][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","shell","dumpsys","window"]
[2017-05-08 11:06:51][AndroidDriver] Screen already unlocked, doing nothing
[2017-05-08 11:06:51][ADB] Getting connected devices...
[2017-05-08 11:06:51][ADB] 1 device(s) connected
[2017-05-08 11:06:51][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","shell","am","force-stop","io.appium.uiautomator2.server"]
[2017-05-08 11:06:52][UiAutomator2] Starting uiautomator2 server v0.1.4 with cmd: am,instrument,-w,io.appium.uiautomator2.server.test/android.support.test.runner.AndroidJUnitRunner
[2017-05-08 11:06:52][UiAutomator2] running command...
 adb -s 79ed76ef shell am instrument -w io.appium.uiautomator2.server.test/android.support.test.runner.AndroidJUnitRunner... 
[2017-05-08 11:06:52][UiAutomator2] Waiting for UiAutomator2 to be online...
[2017-05-08 11:06:52][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-05-08 11:06:53][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-05-08 11:06:54][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-05-08 11:06:55][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-05-08 11:06:56][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-05-08 11:06:57][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-05-08 11:06:58][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-05-08 11:06:59][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-05-08 11:07:00][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-05-08 11:07:01][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-05-08 11:07:02][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-05-08 11:07:03][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-05-08 11:07:04][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-05-08 11:07:05][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-05-08 11:07:06][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-05-08 11:07:07][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-05-08 11:07:09][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-05-08 11:07:10][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-05-08 11:07:11][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-05-08 11:07:12][JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8200/wd/hub/status] with no body
[2017-05-08 11:07:13][UiAutomator2] Deleting UiAutomator2 session
[2017-05-08 11:07:13][UiAutomator2] Deleting UiAutomator2 server session
[2017-05-08 11:07:13][UiAutomator2] Did not get confirmation UiAutomator2 deleteSession worked; Error was: Error: Trying to proxy a session command without session id
[2017-05-08 11:07:13][ADB] Getting connected devices...
[2017-05-08 11:07:13][ADB] 1 device(s) connected
[2017-05-08 11:07:13][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","shell","am","force-stop","cn.lejiayuan.alpha"]
[2017-05-08 11:07:13][Logcat] Stopping logcat capture
[2017-05-08 11:07:13][ADB] Removing forwarded port socket connection: 8200 
[2017-05-08 11:07:13][ADB] Running '/Users/sqbj/Documents/Android_sdk/platform-tools/adb' with args: ["-P",5037,"-s","79ed76ef","forward","--remove","tcp:8200"]
[2017-05-08 11:07:13][MJSONWP] Encountered internal error running command: ProxyRequestError: Could not proxy command to remote server. Original error: Error: socket hang up
    at JWProxy.proxy$ (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-base-driver/lib/jsonwp-proxy/proxy.js:144:13)
    at tryCatch (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
[2017-05-08 11:07:13][HTTP] <-- POST /wd/hub/session 500 32927 ms - 216 

过程中没有报错就看到有一个端口转换

[2017-05-08 11:06:40][UiAutomator2] Checking whether app is actually present
[2017-05-08 11:06:41][UiAutomator2] UIAutomator2 Driver version:0.3.1

貌似就检查了一下 app 是否存在 然后后面就直接启动 Uiautomator2 的 server,等待响应,然后就没有然后了...

bauul #41 · 2017年05月08日 Author

@mingmingfree
APPIUM 切到 ui2.0 后,会在手机上安装本文中提到的两个 APK,它有可能弹出是否允许的对话框 ,需要手动点击允许,检查一下,你手机上是否有安装这两个 APK,如果没有,再检查你的 APPIUM 目录,是否有 uiautomator2 的 driver
appium\node_modules\appium-uiautomator2-driver\uiautomator2

bauul 回复

1.手机设置了 adb 安装应用不提醒,所以木有对话框,日志也没发现安装 Uiautomator2 的俩应用
2.uiautomator2 的 driver 是存在的,apk 也都在,就是没有自动安装,不知道什么鬼
还有没有其他要注意的...
@seveniruby 思寒大人求助求助..😢

bauul #60 · 2017年05月08日 Author
CleverMing 回复

检查这个目录有没有两个 APK:appium\node_modules\appium-uiautomator2-driver\uiautomator2
另外可以升级到 1.6.5 试下

bauul 回复

好的谢谢,我再找找原因😃

@carl uiautomator2 不支持中文输入?

bauul #36 · 2017年05月09日 Author

可以的啊,碰到什么问题了吗?

bauul 回复

输入框里 sendkeys 失败, 没有写入任何内容。
删除
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);
就可以正常输入。

报错信息:org.openqa.selenium.NoSuchElementException: Can't locate an element by this strategy: Locator map:

bauul #34 · 2017年05月11日 Author

从日志看这个控件定位符在 ui2.0 上并没有找到对应的控件,修改一下控件定位符试试

bauul 回复

id,className,xpath 都试过,就是不行,不知道有没有人遇到同样的问题?
貌似不是控件定位的问题。
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: java.lang.NullPointerException
at android.support.test.uiautomator.UiObject2.setText(UiObject2.java:601)

有时会报 ui2.setText 不支持。

bauul #32 · 2017年05月11日 Author

这个有报过,在小米手机 android 4.4 的版本上出现过,输入密码的时候。暂时还没来得及看到底怎么回事

appium 貌似从 1.6 版本开始 RF+appiumlibrary 就输入不了中文了,英文和数字可以 unicodeKeyboard=True resetKeyboard=True 这 2 个加了 也不行,之前版本是可以的;哪位大神碰到过啊

#8 楼 @carl 这个可以有

—— 来自 TesterHome 官方 安卓客户端

@songer 你好,看到你在帖子上的回复,你设置 capabilities 和创建 drvier 的代码使用了@Parameters@BeforeTest

请教你一个问题哈,我目前在思考多线程的问题,想要通过@Parameters@BeforeTest将 testNG.xml 文件的参数传参创建 drvier,但是问题是,值一直没有传过去

难道还需要做其他配置?Grid?

请问 这个 APPIUM Version: 1.6.3 版本在哪里下载
我看官网没有尼

bauul #27 · 2017年09月05日 Author
Ji Wei 回复

github 上

bauul 回复

请问怎么弄的啊,我看了你的分析还是没太明白。我是用的 python.
UIAUTOMATOR2 的两个 APK 安装目录下有,手机上没安装,运行时手机上只提示安装 appium settings 和 unlock

bauul #25 · 2017年09月07日 Author
xrandy 回复

需要设置 automation 为 uiautomator2,这是 java 设置代码:
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, AutomationName.ANDROID_UIAUTOMATOR2);

bauul 回复

我设置了的

bauul #23 · 2017年09月07日 Author
xrandy 回复

那就看下 appium 执行的日志,看看哪里出了问题

毛小利 Appium+UiAutomator2 通过脚本验证 Toast 消息 中提及了此贴 09月15日 13:47

测试 demo 是 ok 的,可是公司开发的 app,就是拿不到,拿到的是页面的元素,如果 toast 内容也页面内容重复,怎么处理

bauul #18 · 2017年11月15日 Author
菜菜鸟 回复

可以

bauul 回复

中文 需要什么特殊处理吗 我这边有时候可以 有时候识别不到,是因为时间太短?特殊符号什么的 是加 双\ 处理吗

bauul #16 · 2017年11月15日 Author

不需要,不过我是修改了源码,将这个 toast 值保存到一个静态变量中,增加了获取这个 toast 的静态变量的接口,我直接调这个接口,即使 toast 消失了,也可以知道最后一次显示的是什么消息

bauul 回复

现在发现 toast 消息有重复的时候 怎么处理

bauul #14 · 2017年11月15日 Author
菜菜鸟 回复

可以增加一个重试机制

13楼 已删除
xrandy 回复

使用 Appium UIAutomator2 pressKeyCode(66) 不生效,server 也没有报错。你遇到了吗?
问题详情见下方链接帖子,感谢~

Appium 中使用 pressKeyCode 方法不起作用也没有报错

bauul #11 · 2018年03月22日 Author
KD 回复

去分析问题啊,首先命令行执行 adb shell input keyevent 66 有没有效果?然后其他键有没有效果?是 appium 的问题吗?一步一步的分析

bauul 回复

感谢~ 昨天终于找到问题原因了,已解决。

CleverMing 回复

最后问题解决了吗?

CleverMing 回复

你最后问题解决没?没有自动安装

Proxying [POST /element] to [POST http://localhost:8200/wd/hub/session/a47fd6da-2f85-40a6-a36f-8f613dabf298/element] with body: {"strategy":"id","selector":"com.cmi.jegotrip:id/log_out","context":"","multiple":false}
[MJSONWP] Encountered internal error running command: ProxyRequestError: Could not proxy command to remote server. Original error: Error: socket hang up
    at JWProxy.proxy$ (../../../lib/jsonwp-proxy/proxy.js:152:13)
    at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
    at <anonymous>
[HTTP] <-- POST /wd/hub/session/be37a78e-43a7-402c-9840-4f2554810855/element 500 173 ms - 250
[debug] [UiAutomator2] [UIAutomator2] io.appium.uiautomator2.server.test.AppiumUiAutomator2Server:INSTRUMENTATION_RESULT: shortMsg=Process crashed.

1、我的这两个 apk 都安装了
2、手机为 vivo x9
3、系统 7.1.1
看了大家发生的情况,都和我这个不太一样,我的是执行过程中有一段时间是好的,突然就挂掉了, 看日志比较像 Automator2 挂掉了,不知道有人遇到过没

05-04 15:37:22.029  7164  7821 I appium  : channel read invoked!
05-04 15:37:22.029  7164  7821 I appium  : channel read: POST /wd/hub/session/6a8067ba-9127-4ab2-b8e3-9cc8eb6b4ff9/element
05-04 15:37:22.030  7164  7821 I appium  : Find element command
05-04 15:37:22.031  7164  7821 I appium  : find element command using 'id' with selector 'com.cmi.jegotrip:id/skip_btn'.
05-04 15:37:22.504  7164  7821 I appium  : AppiumResponse: {"sessionId":"6a8067ba-9127-4ab2-b8e3-9cc8eb6b4ff9","status":7,"value":"An element could not be located on the page using the given search parameters."}
05-04 15:37:23.026  7164  7822 I appium  : channel read invoked!
05-04 15:37:23.027  7164  7822 I appium  : channel read: POST /wd/hub/session/6a8067ba-9127-4ab2-b8e3-9cc8eb6b4ff9/element
05-04 15:37:23.027  7164  7822 I appium  : Find element command
05-04 15:37:23.029  7164  7822 I appium  : find element command using 'id' with selector 'com.cmi.jegotrip:id/skip_btn'.
05-04 15:37:23.502  7164  7822 I appium  : AppiumResponse: {"sessionId":"6a8067ba-9127-4ab2-b8e3-9cc8eb6b4ff9","status":7,"value":"An element could not be located on the page using the given search parameters."}
05-04 15:37:24.024  7164  7825 I appium  : channel read invoked!
05-04 15:37:24.024  7164  7825 I appium  : channel read: POST /wd/hub/session/6a8067ba-9127-4ab2-b8e3-9cc8eb6b4ff9/element
05-04 15:37:24.025  7164  7825 I appium  : Find element command
05-04 15:37:24.026  7164  7825 I appium  : find element command using 'id' with selector 'com.cmi.jegotrip:id/skip_btn'.
05-04 15:37:24.516  7164  7825 I appium  : AppiumResponse: {"sessionId":"6a8067ba-9127-4ab2-b8e3-9cc8eb6b4ff9","status":7,"value":"An element could not be located on the page using the given search parameters."}
05-04 15:37:29.477  1471  1891 I ActivityManager: Force stopping io.appium.uiautomator2.server appid=10850 user=0: from pid 2759
05-04 15:37:29.477  1471  1891 I ActivityManager: Killing 7164:io.appium.uiautomator2.server/u0a850 (adj 0): stop io.appium.uiautomator2.server
05-04 15:37:29.478  1471  1891 W ActivityManager: Crash of app io.appium.uiautomator2.server running instrumentation ComponentInfo{io.appium.uiautomator2.server.test/android.support.test.runner.AndroidJUnitRunner}
05-04 15:37:29.478  1471  1891 I ActivityManager: Force stopping io.appium.uiautomator2.server appid=10850 user=0: finished inst
05-04 15:37:29.524  1471  1892 W AppOps  : Bad call: specified package io.appium.uiautomator2.server.test under uid 10850 but it is really 10849

更新下 Automator2 被杀死时的日志

文贤平 回复
  1. 是你的操作导致的?
  2. 是 vivo 手机自己杀的?

搞清楚动作来源

bauul 回复

不是我自己杀死的,我这边做的操作就是常规的跑 appium 自动化,脚本在运行一段时间后,有一定几率抛异常,然后我抓了 Automator2 的日志,发现是进程被杀掉了,不知道是 vivo 自己杀死的还是 appium 触发了某个异常之后杀死的

CleverMing 回复

是的,你要指定为 U2 才能自动安装。

[debug] [W3C] Calling AppiumDriver.createSession() with args: [{"appActivity":".ApiDemos","appPackage":"com.example.android.apis","automationName":"Uiautomator2","platformName":"Android","deviceName":"emulator-5554"},null,{"alwaysMatch":{"appium:appActivity":".ApiDemos","appium:appPackage":"com.example.android.apis","appium:automationName":"Uiautomator2","appium:deviceName":"emulator-5554","platformName":"android"},"firstMatch":[{}]}]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1548926366177 (17:19:26 GMT+0800 (GMT+08:00))
[Appium] Creating new AndroidUiautomator2Driver (v1.19.0) session
[Appium] Capabilities:
[Appium]   platformName: android
[Appium]   appActivity: .ApiDemos
[Appium]   appPackage: com.example.android.apis
[Appium]   automationName: Uiautomator2
[Appium]   deviceName: emulator-5554
[debug] [BaseDriver] W3C capabilities {"alwaysMatch":{"platformNa... and MJSONWP desired capabilities {"appActivity":".ApiDemos",... were provided
[debug] [BaseDriver] Creating session with W3C capabilities: {"alwaysMatch":{"platformNa...
[BaseDriver] Session created with session id: 4cb8465d-adf7-422c-bb9d-7257240150b0
[AndroidDriver] Java version is: 1.8.0_181
[AndroidDriver] Retrieving device list
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[AndroidDriver] Using device: emulator-5554
[debug] [ADB] Setting device id to emulator-5554
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell getprop ro.build.version.sdk'
[debug] [ADB] Current device property 'ro.build.version.sdk': 24
[debug] [ADB] Device API level: 24
[AndroidDriver] No app sent in, not parsing package/activity
[ADB] Getting device platform version
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell getprop ro.build.version.release'
[debug] [ADB] Current device property 'ro.build.version.release': 7.0
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell wm size'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell wm density'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell getprop ro.product.model'
[debug] [ADB] Current device property 'ro.product.model': Android SDK built for x86
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell getprop ro.product.manufacturer'
[debug] [ADB] Current device property 'ro.product.manufacturer': Google
[debug] [ADB] Device API level: 24
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell am force-stop io.appium.uiautomator2.server'
[debug] [ADB] Checking app cert for /usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v1.18.0.apk
[debug] [ADB] Starting '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/build-tools/28.0.3/apksigner' with args '["verify","--print-certs","/usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v1.18.0.apk"]'
[debug] [ADB] apksigner stdout: Signer #1 certificate DN: EMAILADDRESS=android@android.com, CN=Android, OU=Android, O=Android, L=Mountain View, ST=California, C=US
[debug] [ADB] Signer #1 certificate SHA-256 digest: a40da80a59d170caa950cf15c18c454d47a39b26989d8b640ecd745ba71bf5dc
[debug] [ADB] Signer #1 certificate SHA-1 digest: 61ed377e85d386a8dfee6b864bd85b0bfaa5af81
[debug] [ADB] Signer #1 certificate MD5 digest: e89b158e4bcf988ebd09eb83f5378e87
[debug] [ADB] WARNING: META-INF/INDEX.LIST not protected by signature. Unauthorized modifications to this JAR entry will not be detected. Delete or move the entry outside of META-INF/.
[debug] [ADB] WARNING: META-INF/io.netty.versions.properties not protected by signature. Unauthorized modifications to this JAR entry will not be detected. Delete or move the entry outside of META-INF/.
[debug] [ADB]
[debug] [ADB] '/usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v1.18.0.apk' is already signed.
[debug] [ADB] Checking app cert for /usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk
[debug] [ADB] Starting '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/build-tools/28.0.3/apksigner' with args '["verify","--print-certs","/usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk"]'
[debug] [ADB] apksigner stdout: Signer #1 certificate DN: EMAILADDRESS=android@android.com, CN=Android, OU=Android, O=Android, L=Mountain View, ST=California, C=US
[debug] [ADB] Signer #1 certificate SHA-256 digest: a40da80a59d170caa950cf15c18c454d47a39b26989d8b640ecd745ba71bf5dc
[debug] [ADB] Signer #1 certificate SHA-1 digest: 61ed377e85d386a8dfee6b864bd85b0bfaa5af81
[debug] [ADB] Signer #1 certificate MD5 digest: e89b158e4bcf988ebd09eb83f5378e87
[debug] [ADB]
[debug] [ADB] '/usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk' is already signed.
[debug] [ADB] Getting install status for io.appium.uiautomator2.server
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell pm list packages io.appium.uiautomator2.server'
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for 'io.appium.uiautomator2.server'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys package io.appium.uiautomator2.server'
[debug] [ADB] The installed 'io.appium.uiautomator2.server' package does not require upgrade ('1.18.0' >= '1.18.0')
[debug] [ADB] Getting install status for io.appium.uiautomator2.server.test
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell pm list packages io.appium.uiautomator2.server.test'
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for 'io.appium.uiautomator2.server.test'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys package io.appium.uiautomator2.server.test'
[ADB] Cannot read version codes of '/usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk' and/or 'io.appium.uiautomator2.server.test'
[ADB] Cannot read version names of '/usr/local/lib/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-debug-androidTest.apk' and/or 'io.appium.uiautomator2.server.test'. Assuming correct app version is already installed
[debug] [UiAutomator2] Waiting up to 20000ms for instrumentation 'io.appium.uiautomator2.server.test/android.support.test.runner.AndroidJUnitRunner' to be available
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell pm list instrumentation'
[debug] [UiAutomator2] Instrumentation 'io.appium.uiautomator2.server.test/android.support.test.runner.AndroidJUnitRunner' available
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 wait-for-device'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell echo ping'
[debug] [AndroidDriver] Pushing settings apk to device...
[debug] [ADB] Getting install status for io.appium.settings
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell pm list packages io.appium.settings'
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for 'io.appium.settings'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys package io.appium.settings'
[debug] [ADB] The installed 'io.appium.settings' package does not require upgrade (13 > 5)
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell ps'
[debug] [AndroidDriver] io.appium.settings is already running. There is no need to reset its permissions.
[debug] [ADB] Device API level: 24
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell appops set io.appium.settings android\:mock_location allow'
[AndroidDriver] setDeviceLanguageCountry requires language or country.
[AndroidDriver] Got language: 'null' and country: 'null'
[debug] [Logcat] Starting logcat capture
[debug] [AndroidDriver] Pushing unlock helper app to device...
[debug] [ADB] Getting install status for io.appium.unlock
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell pm list packages io.appium.unlock'
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for 'io.appium.unlock'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell dumpsys package io.appium.unlock'
[debug] [ADB] The installed 'io.appium.unlock' package does not require upgrade ('2.0.0' >= '2.0.0')
[debug] [UiAutomator2] Forwarding UiAutomator2 Server port 6790 to 8200
[debug] [ADB] Forwarding system: 8200 to device: 6790
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 forward tcp\:8200 tcp\:6790'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell rm -rf /data/local/tmp/strings.json'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell pm path com.example.android.apis'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 pull /data/app/ApiDemos/ApiDemos.apk /var/folders/gf/jjhn56c97293xtjvtwlnwr8h0000gp/T/com.example.android.apis.apk'
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 pull /data/app/ApiDemos/ApiDemos.apk /var/folders/gf/jjhn56c97293xtjvtwlnwr8h0000gp/T/com.example.android.apis.apk'
[debug] [UiAutomator2] Deleting UiAutomator2 session
[debug] [UiAutomator2] Deleting UiAutomator2 server session
[debug] [JSONWP Proxy] Matched '/' to command name 'deleteSession'
[UiAutomator2] Did not get confirmation UiAutomator2 deleteSession worked; Error was: UnknownError: An unknown server-side error occurred while processing the command. Original error: Trying to proxy a session command without session id
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 shell am force-stop com.example.android.apis'
[debug] [Logcat] Stopping logcat capture
[debug] [ADB] Removing forwarded port socket connection: 8200
[debug] [ADB] Running '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 forward --remove tcp\:8200'
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1548926370387 (17:19:30 GMT+0800 (GMT+08:00))
[debug] [W3C] Encountered internal error running command: Error: Error executing adbExec. Original error: 'Command '/Users/zhangc/Desktop/mine/install/android-sdk-macosx/platform-tools/adb -P 5037 -s emulator-5554 pull /data/app/ApiDemos/ApiDemos.apk /var/folders/gf/jjhn56c97293xtjvtwlnwr8h0000gp/T/com.example.android.apis.apk' exited with code 1'; Stderr: ''; Code: '1'
[debug] [W3C]     at ADB.execFunc$ (/usr/local/lib/node_modules/appium/node_modules/appium-adb/lib/tools/system-calls.js:327:13)
[debug] [W3C]     at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
[debug] [W3C]     at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
[debug] [W3C]     at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
[debug] [W3C]     at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
[HTTP] <-- POST /wd/hub/session 500 4214 ms -

大神我报的这个错误,一直没找到解决办法

Tester-Owen 回复

我不用模拟器的,我不太确定是不是在建立 tcp 连接的时候出问题了,看日志有可能是,你可以在 CMD 中执行 adb forward tcp:8200 tcp :6297 试一下看看有没有报错

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册