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

查看:21
本文介绍了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?

这篇博文

:哦,是的,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天全站免登陆