UI应用程序检查器(如Appium中的检查器)如何工作? [英] How does a UI app inspectors (like the one in Appium) work?

查看:149
本文介绍了UI应用程序检查器(如Appium中的检查器)如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Appium可以使用检查器检查应用程序的视图层次结构.我有兴趣自己建一个.

Appium has a way to inspect the view hierarchy of an app using an inspector. I am interested in building one myself.

我知道以下方面的概述答案:它使用一些webdriver来完成此任务.但是如何? 令我感到困惑的是,一个单独的iOS应用程序可以在某种程度上与另一个应用程序进行通信,甚至显示其屏幕.

I know the overview answer of: it uses some webdriver to accomplish this. But how? It puzzles me that a separate iOS app can some how communicate to another app, and show even its screen.

它是如何工作的?或iOS应用如何与UI检查器通信以发送其屏幕截图和层次结构?

How does it work under the hood? or how does the iOS app communicate to the UI inspector to send its screen shots and hierarchy?

推荐答案

让我感到困惑的是,一个单独的iOS应用程序可以在某种程度上与另一个应用程序进行通信,甚至显示其屏幕.

It puzzles me that a separate iOS app can some how communicate to another app, and show even its screen.

是的!应用程序不能执行此操作.但是,存在一种专门用于测试的应用程序,可以做到这一点.

Yes! Apps should not be able to do this. But there exists a special kind of app, built just for testing, which IS able to do this.

完成此操作的方法是使用Apple的XCUITest框架.当您使用XCode编写XCUITest时,它将构建一个特殊的应用程序,该应用程序可以启动您的测试应用程序,然后使用XCUITest方法与其进行通信.这些方法使您可以检查视图中的元素.

The way this is done is using Apple's XCUITest framework. When you write an XCUITest in XCode, it builds a special app which is able to start your test app and then communicate with it using the XCUITest methods. These methods allow you to inspect elements in the view.

要创建视图树,请从根视图开始并遍历子级,以遍历树的方式构建一棵树.

In order to create a view tree, you start at the root view and iterate over the children, building out a tree with a tree traversal.

通常,XCUITest应用程序在测试脚本完成时退出,这意味着您将无法从桌面应用程序访问它以在更新树时查看该树.如果编写测试脚本以运行无限循环并打开网络端口以与外部进程进行通信,则现在可以构建查看器.这正是Appium所做的,所以建议您查看 appium源代码,然后也许只是用那个?

Normally, the XCUITest app exits when your test script finishes, which means you won't be able to access it from a desktop app for viewing the tree as it updates. If you write your test script to run an infinite loop and open a network port for communication with an outside process, now you can build your viewer. This is exactly what Appium does, so I suggest you check out the appium source code and maybe just use that?

此博客文章

[edit]:是的,Appium使用Feacebook的WebDriverAgent项目作为在该应用程序上运行的脚本.因此,WebDriverAgent基本上是一个XCUITest脚本,它运行服务器并可以在测试期间接受命令. Appium做了大量工作,将其捆绑并打包到能够访问您的应用程序的特殊类型的配套应用程序中,将其安装在iOS设备上,然后运行测试. WebDriverAgent具有一个在UIHierarchy上迭代并返回整个树的命令.

[edit]: Oh yeah, Appium uses Feacebook's WebDriverAgent project as the script that runs on the app. So WebDriverAgent is basically an XCUITest script which runs a server and can take commands during a test. Appium does a ton of work to bundle and package it into the special kind of companion app that is able to access your app, installs it on the iOS device, and then runs the test. WebDriverAgent has a command which iterates over the UIHierarchy and returns the whole tree.

这篇关于UI应用程序检查器(如Appium中的检查器)如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆