乱入测试的 Android 开发实习僧

  • #14 楼 @chenhengjie123

    从这里看到,从获得命令到完成输入一共有以下步骤:

    1. 判断并存储 replace, text, unicodeKeyboard 参数的值
    2. 通过 getText 获取当前元素的文字,存到 currText 中
    3. 使用 new Clear().execute(command);清除当前元素的所有文字
    4. 再次获取当前元素文字。如果文字仍不为空,认定它是 hint text 并把 currText 置空(由于此处也有可能是 clear 方法出错导致没有 clear 成功,因此留了一个 log 说明假设还存在的 text 是 hint text)
    5. 如果 replace 不是 true,在 text 前面加入 currText。
    6. 调用 setText 方法执行实际输入。

    我这边是当清空当前元素文字时,还有 hint text 提示文字,这样就把 currText 置为空了,然后后面调用 setText 方法时,text 前面加入的 currText 就为空,导致效果是没有追加输入。

    这种情况求解答啊🙏

  • #14 楼 @chenhengjie123

    这样我想要在后面输入 123456 时,它会把前面的话题删除掉,我代码是

    driver.findElementById("com.m4399.gamecenter.plugin.main:id/zone_edit").sendKeys("123456");
    

    appium 打印的日志

    info: [debug] Pushing command to appium work queue: ["element:setText",{"elementId":"22","text":"123456","replace":false,"unicodeKeyboard":true}]
    info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"element:setText","params":{"elementId":"22","text":"123456","replace":false,"unicodeKeyboard":true}}
    info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
    info: [debug] [BOOTSTRAP] [debug] Got command action: setText
    info: [debug] [BOOTSTRAP] [debug] Using element passed in.
    info: [debug] [BOOTSTRAP] [debug] Attempting to clear using UiObject.clearText().
    info: [debug] [BOOTSTRAP] [debug] Clearing text not successful. Attempting to clear by selecting all and deleting.
    info: [debug] [BOOTSTRAP] [debug] Clearing text not successful. Attempting to clear by sending delete keys.
    info: [debug] [BOOTSTRAP] [debug] Text remains after clearing, but it appears to be hint text.
    info: [debug] [BOOTSTRAP] [debug] Text not cleared. Assuming remainder is hint text.
    info: [debug] [BOOTSTRAP] [debug] Sending plain text to element: 123456
    info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
    info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"b04c397a-2135-4793-b902-102038be5222"}
    
  • #10 楼 @chenhengjie123 你好,我问一下哈,我这边是直接在原有文字后面追加输入时,它会把原有的文字删除后 sendkeys,日志打印的和 9 楼的一样,按照你说的这个

    从你的 Log 来看, clearText() 方法执行不成功,因此它假定没能删掉的文字是提示文字(hint text),即平时我们一旦在输入框输入内容后就会自动消失的文字。所以第二次 setText 时它认为留在输入框的文字(我估计就是你第一次 sendKeys 时输入的 helo.everyone )是会自动消失的,所以就没有再次输入它了。

    所以如果我要追加输入时,是不是 sendkeys 要把前面文本框原有的内容也加入?

    ps:我的 appium 版本是 1.4.16

  • 实在不行这不是还有 classname 吗

  • 楼主不知道你这个问题解决了么😁

  • 你好我有个疑问,我按照你的这个走了一遍,发现个问题,最后得到的这个 num 值是相同 id 或 class 的控件个数,但是要怎么判断所选节点是这几个相同控件中的第几个啊?

  • #11 楼 @sanlengjingvv 我看到一个帖子是遍历把属性都相同的控件放到一个 list 里面,然后去判断点的是第几个,uiautomatorviewer 功能扩展实践

    这样感觉比给出绝对路径的要简单,反正不管了,先试试这个思路,昨天搞了一天那个绝对路径没出来。

  • #9 楼 @nickli 我看阿里那个 mqc 录制工具录制出来的脚本,针对这种情况就是利用坐标和控件 id 双重限制来实现定位,不过这录制出来的脚本就太有限制性了,换一个分辨率不同的手机,这个路径就行不通了。

  • #7 楼 @sanlengjingvv 但是我们老大给我的要求是,当点击 “下载” 按钮,就直接可以生成这样的路径

    //android.widget.TextView[text()='疯狂俄罗斯人']/parent::*/parent::*/following-sibling::*[1]/android.widget.Button[text()='下载']
    

    然后在封装一下直接生成可运行的脚本,尽量人不用在去改脚本。不过我才接触测试不到一个月,搞这个有点吃力😂

  • #3 楼 @xdf 谢谢你告诉我这个消息,我去找找 app-inspector 的源码看看,不知道找不找的到。😂

乱入测试的 Android 开发实习僧