UI自动化:导出元素树

时间:2014-02-27 02:21:30

标签: instruments ios-ui-automation

在UI自动化中,有没有办法以不同于默认格式(例如XML)的格式导出logElementTree()生成的元素树。我想在UI自动化之外使用元素层次结构。

我在测试脚本中使用logElementTree()记录了树,但它成功,在编辑器日志中显示为“已通过”。我试图“导出跟踪结果”,但似乎没有做到这一点。

2 个答案:

答案 0 :(得分:1)

您可以使用Appium检查器获取XML结果:Appium

Appium是一个开源自动化框架。它还提供了获取应用程序UI层次结构的工具。

按照说明操作并启动Appium检查器。填写所需信息,例如设备类型和UDID。屏幕截图:Appium Inspector

使用Appium GUI,然后复制XML"右下角的按钮。按刷新按钮以获取当前屏幕的UI层次结构。

这是计算器应用的结果。

<?xml version="1.0" encoding="UTF-8"?>
<AppiumAUT>
    <UIAApplication name="Calculator" label="Calculator" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0" x="0" y="20" width="320" height="548">
        <UIAWindow name="" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0" x="0" y="0" width="320" height="568">
            <UIAStaticText name="Result" label="Result" value="0" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/0" x="0" y="0" width="320" height="168">
            </UIAStaticText>
            <UIAButton name="all clear" label="all clear" value="all clear" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/1" x="1.5" y="169.5" width="78.5" height="79">
            </UIAButton>
            <UIAButton name="plus, minus" label="plus, minus" value="plus, minus" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/2" x="80.5" y="169.5" width="79" height="79">
            </UIAButton>
            <UIAButton name="percent" label="percent" value="percent" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/3" x="160" y="169.5" width="79" height="79">
            </UIAButton>
            <UIAButton name="divide" label="divide" value="divide" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/4" x="239.5" y="169.5" width="79" height="79">
            </UIAButton>
            <UIAButton name="7" label="7" value="7" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/5" x="1.5" y="249" width="78.5" height="79">
            </UIAButton>
            <UIAButton name="8" label="8" value="8" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/6" x="80.5" y="249" width="79" height="79">
            </UIAButton>
            <UIAButton name="9" label="9" value="9" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/7" x="160" y="249" width="79" height="79">
            </UIAButton>
            <UIAButton name="multiply" label="multiply" value="multiply" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/8" x="239.5" y="249" width="79" height="79">
            </UIAButton>
            <UIAButton name="4" label="4" value="4" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/9" x="1.5" y="328.5" width="78.5" height="79">
            </UIAButton>
            <UIAButton name="5" label="5" value="5" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/10" x="80.5" y="328.5" width="79" height="79">
            </UIAButton>
            <UIAButton name="6" label="6" value="6" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/11" x="160" y="328.5" width="79" height="79">
            </UIAButton>
            <UIAButton name="subtract" label="subtract" value="subtract" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/12" x="239.5" y="328.5" width="79" height="79">
            </UIAButton>
            <UIAButton name="1" label="1" value="1" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/13" x="1.5" y="408" width="78.5" height="79">
            </UIAButton>
            <UIAButton name="2" label="2" value="2" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/14" x="80.5" y="408" width="79" height="79">
            </UIAButton>
            <UIAButton name="3" label="3" value="3" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/15" x="160" y="408" width="79" height="79">
            </UIAButton>
            <UIAButton name="add" label="add" value="add" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/16" x="239.5" y="408" width="79" height="79">
            </UIAButton>
            <UIAButton name="0" label="0" value="0" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/17" x="1.5" y="487.5" width="157" height="79">
            </UIAButton>
            <UIAButton name="decimal" label="decimal" value="decimal" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/18" x="160" y="487.5" width="79" height="79">
            </UIAButton>
            <UIAButton name="equals" label="equals" value="equals" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/19" x="239.5" y="487.5" width="79" height="79">
            </UIAButton>
        </UIAWindow>
        <UIAWindow name="" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/1" x="0" y="0" width="320" height="568">
            <UIAStatusBar name="" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/1/0" x="0" y="0" width="320" height="20">
                <UIAElement name="2 of 5 bars, signal strength" label="2 of 5 bars, signal strength" value="" dom="" enabled="true" valid="true" visible="true" hint="Swipe down with three fingers to reveal the notification center., Swipe up with three fingers to reveal the control center, Double-tap to scroll to top" path="/0/1/0/0" x="6" y="0" width="35" height="20">
                </UIAElement>
                <UIAElement name="T-Mobile network" label="T-Mobile network" value="" dom="" enabled="true" valid="true" visible="true" hint="Swipe down with three fingers to reveal the notification center., Swipe up with three fingers to reveal the control center, Double-tap to scroll to top" path="/0/1/0/1" x="44" y="0" width="48" height="20">
                </UIAElement>
                <UIAElement name="3 of 3 Wi-Fi bars" label="3 of 3 Wi-Fi bars" value="FireEye" dom="" enabled="true" valid="true" visible="true" hint="Swipe down with three fingers to reveal the notification center., Swipe up with three fingers to reveal the control center, Double-tap to scroll to top" path="/0/1/0/2" x="97" y="0" width="13" height="20">
                </UIAElement>
                <UIAElement name="10:48 AM" label="10:48 AM" value="" dom="" enabled="true" valid="true" visible="true" hint="Swipe down with three fingers to reveal the notification center., Swipe up with three fingers to reveal the control center, Double-tap to scroll to top" path="/0/1/0/3" x="134" y="0" width="52" height="20">
                </UIAElement>
                <UIAElement name="95% battery power, Charging" label="95% battery power, Charging" value="" dom="" enabled="true" valid="true" visible="true" hint="Swipe down with three fingers to reveal the notification center., Swipe up with three fingers to reveal the control center, Double-tap to scroll to top" path="/0/1/0/4" x="282" y="0" width="33" height="20">
                </UIAElement>
            </UIAStatusBar>
        </UIAWindow>
    </UIAApplication>
</AppiumAUT>

答案 1 :(得分:0)

http://www.w3schools.com/xsl/xsl_transformation.asp

上述工作会不会有效?

例如,类似的东西会将测试结果粗略地解析为HTML表格:

<table border="1" style="width:800px">
                    <tr>
                    <th>Timestammp</th>
                    <th>Sequence</th>
                    <th>Message</th>
                    <th>Type</th>
                    <th>Screenshot</th>
                    </tr>
<xsl:for-each select="plist/dict/array/dict">
                        <tr>
                            <td>
                                <xsl:value-of select="translate(translate(date, 'T',' '), 'Z','')"/>
                            </td>
                            <td><xsl:value-of select="position()"/></td>
                            <td><xsl:value-of select="string"/></td>
                            <td>
                                <xsl:choose>
                                    <xsl:when test="integer = 8"><span style="color:blue">Screenshot</span></xsl:when>
                                    <xsl:when test="integer = 5"><span style="color:green">Pass</span></xsl:when>
                                    <xsl:when test="integer = 4"><span style="color:orange">Message</span></xsl:when>
                                    <xsl:otherwise><xsl:value-of select="integer"/></xsl:otherwise>
                                </xsl:choose>
                            </td>
                            <td>
                                <xsl:if test="integer = 8">
                                    <xsl:element name="img">
                                        <xsl:attribute name="src"><xsl:value-of select="string"/>.png</xsl:attribute>
                                        <xsl:attribute name="style">height:250px;width:167px;</xsl:attribute>
                                    </xsl:element>
                                </xsl:if>
                            </td>
                        </tr>
                    </xsl:for-each>
                </table>

作为一个说明,我已经有一段时间了,因为我还没有在我的项目中使用过这一点,我相信其中大部分来自某个人的博客。如果我能再次找到该网站,我将发布信用额度。