GithubHelp home page GithubHelp logo

Write it as a blog about cafe HOT 18 OPEN

baidu avatar baidu commented on July 17, 2024
Write it as a blog

from cafe.

Comments (18)

salomon1184 avatar salomon1184 commented on July 17, 2024

我看了一下源码,捕获进程外控件,你是通过和hierarchyviewer相同的方式,从dump的字符串里解析出来符合条件的控件。但是我尝试了一下用remote.clickviewbyid调用拍照功能,传递参数为"id/shutter_button" 也尝试了”shutter_button"两者都没有触发点击的动作(已经执行了cafe_start.sh),能不能请教一下为什么?难道我的调用方式不对?还有什么方式能够精确捕获进程外控件呢?

from cafe.

luxiaoyu avatar luxiaoyu commented on July 17, 2024

跨进程点击功能只有在adb shell getprop ro.debuggable返回1的时候才能使用。
如果返回1,那么你需要的调用方式为remote.clickViewById("id/shutter_button"),这个一定可以work:)

from cafe.

salomon1184 avatar salomon1184 commented on July 17, 2024

那就得要求系统编译时设置debug的属性为1啊,市面上所有的手机应该都是0吧。有没有其他办法能实现跨应用的精确捕获?可惜没办法把uiautomator的给移植进来。

from cafe.

luxiaoyu avatar luxiaoyu commented on July 17, 2024

如果上市的手机这个属性不为1的话那得多不安全啊。。 这个功能本来就是for debug&test的,所以推荐刷机。
其他适应所有版本的跨进程捕获只有OCR了。。
如果跨进程的元素位置是固定的话,也可以变通一下用remote.clickScreen(int x, int y);这个不需要debug等于1,所有android版本都能用,带价就是非运行时查找

from cafe.

luxiaoyu avatar luxiaoyu commented on July 17, 2024
public boolean clickViewById(String id) {
    return clickView("mID", id, LocalLib.SEARCHMODE_COMPLETE_MATCHING, 0,
            TIMEOUT_DEFAULT_VALUE/*10000*/, 0, 0, 0, null, 0);
}

另外,这个函数最后两个参数表示scrollView的id和index,缺省为null和0,即表示不滚动查找

from cafe.

salomon1184 avatar salomon1184 commented on July 17, 2024

嗯,看源码看到了,谢谢啊

from cafe.

salomon1184 avatar salomon1184 commented on July 17, 2024

希望大牛什么时候考虑基于uiautomator封装扩展一下,加上webview, 事件等待,以及低版本兼容等,那么android ui自动化测试就不会那么痛苦了

from cafe.

luxiaoyu avatar luxiaoyu commented on July 17, 2024

等低版本的android变成非主流才有可能采用uiautomator。
webview你指的是webview的那些feature?

from cafe.

salomon1184 avatar salomon1184 commented on July 17, 2024

是啊,webview里包含的一些空间的获取之类的。又看了一下源码,发现点击控件的事件都是通过monkey发送的 private final static int USE_MONKEY = 1;
private final static int EVENT_SENDER = USE_MONKEY;

没有通过instrumentation,那也就是说adb shell getprop ro.debuggable 不为1应该也能点击吧,难道我理解错了?

from cafe.

salomon1184 avatar salomon1184 commented on July 17, 2024

adb -s emulator-5556 shell service call window 1 i32 4939, 可以通过这个命令把ViewServer打开。能不能和hirerachyviewer一样,在建立socket链接之前用这个把viewserver打开,这样那个remote.clickxxx就好使了吧。上边那个问题我明白了,不是click不行,是无法获得控件的property,无法确定坐标。

from cafe.

luxiaoyu avatar luxiaoyu commented on July 17, 2024

你说得对,debug不为1的时候无法获取其他进程view的坐标,所以无法完成跨进程点击。同样,打开viewserver也需要debug属性为1。

from cafe.

salomon1184 avatar salomon1184 commented on July 17, 2024

好多手机debug属性不为1,为什么hierarchyview也可以捕获控件?我看源码,他通过adb -s emulator-5556 shell service call window 1 i32 4939这个命令打开的viewserver, window 2 关闭, window 3 查看状态,我通过这个命令手动打开了,但是运行cafe.jar时还是提示没有打开,好奇怪。

from cafe.

salomon1184 avatar salomon1184 commented on July 17, 2024

我觉着吧,既然hierachyviewer可以在那些debug属性不为1的设备上捕获得到ui属性,那么cafe同样也可以,希望大牛想想办法解决一下吧。虽然接触Android ui自动化时间很短,谈不上认识多深,但真心觉得Cafe的想法很有创意,封装得很契合UI自动化本身特点,希望别留这个小遗憾

from cafe.

luxiaoyu avatar luxiaoyu commented on July 17, 2024

debug属性不为1,hierarchyviewer是不可能捕获控件的,这个我100%确定,因为我看过源码的。如果你确定有反例,还请不吝赐教:D

from cafe.

salomon1184 avatar salomon1184 commented on July 17, 2024

我这有一部htc one x,貌似被刷过机,但是debug属性显示为0, 用hierarchyviewer能得到各个控件属性,但不能调用cafe里remote.clickViewById的方法点击系统相机里的拍照按钮,查看logcat提示 view server is not open,尝试了小米1,系统为最新开发版3.5.10,用debug属性显示为1,hierarchyviewer能得到各个控件属性,仍然不能调用cafe里remote.clickViewById,情形原因如上(已经打开了cafe.start.sh(为了验证调用了remote.presskey调节了音量)一直找不到原因,站在cafe开发者的角度,能不能帮忙给想想到底原因是什么呢?如果需要截图和代码,回头发给你。

from cafe.

salomon1184 avatar salomon1184 commented on July 17, 2024

只要能打开viewserver这个cafe remote的方法就好使吧, 我不刷机,采用这种方法可以吗?http://blog.apkudo.com/tag/viewserver/

from cafe.

luxiaoyu avatar luxiaoyu commented on July 17, 2024

判断viewserver是否work可以用一个简单的api验证,remote.getWindowList() 这个函数会返回String[],打印出来看看是不是当前的窗口列表就行了,如果有list说明viewserver是work的。

from cafe.

luxiaoyu avatar luxiaoyu commented on July 17, 2024

另外,remote.clickViewById()会在logcat中打印"centerX + xOffset = XXX"和"centerY + yOffset = YYY",你可以看一下xy坐标是不是你要点击的view的位置,如果没有打印这句说明没找到view,如果打印了但是位置不对说明,坐标迭代计算错误。

from cafe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.