自动化过程中,我们公司通常习惯在每个页面上插入一个检查点,通过 pageid 来判断当前页面是否是期望页面。
PC 的 web 上,可以直接 F12 找网页的 page id
安卓的应用,暂时使用的是 activityID,这个可以通过 appium 的'currentactivity'来获取,作为 app 不同页面的标识
请教下各位,iOS 上的 APP 能用什么作为页面的标识?问了一些开发也自己研究了下,都说有个 UIViewController 可以用,但是貌似 appium 没提供接口...
还有没有其他的思路呢?除了拿页面的某些特定控件作判断。
最近我在写 iOS 的自动化工具, 也遇到了这个难题. 在 appium 的 getPageSource 中, 是没有任何类似于 activity 的概念的.
而且也没提供层次概念. 比如是否是浮层等.
我想到的办法是根据页面的信息做 hash 做一个标记. 比如把下面的信息所有 tag 抽取出来做 hash.
这样只要页面布局变动, 就认为是个新页面.
另外一个是使用触发新页面的元素作为页面标记. 不过这个不太好, 我也在探索.
<?xml version="1.0" encoding="UTF-8"?>
<AppiumAUT>
<UIAApplication name="雪球" label="雪球" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0" x="0" y="0" width="320" height="480">
<UIAWindow name="" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0" x="0" y="0" width="320" height="480">
<UIANavigationBar name="SNBCubeDetailVC" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/0" x="0" y="20" width="320" height="44">
<UIAImage name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/0/0" x="0" y="0" width="320" height="64">
<UIAImage name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/0/0/0" x="0" y="64" width="320" height="0">
</UIAImage>
</UIAImage>
<UIAStaticText name="旗舰-十二圣徒" label="旗舰-十二圣徒" value="旗舰-十二圣徒" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/0/1" x="80" y="26" width="160" height="16">
</UIAStaticText>
<UIAStaticText name="ZH001206" label="ZH001206" value="ZH001206" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/0/2" x="130" y="46" width="60.5" height="12">
</UIAStaticText>
<UIAStaticText name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/0/3" x="160" y="64" width="0" height="12">
</UIAStaticText>
<UIAButton name="Back" label="Back" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/0/4" x="8" y="31.5" width="21" height="21">
</UIAButton>
<UIAButton name="nav_icon_back" label="nav_icon_back" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/0/5" x="16" y="26" width="30" height="32">
</UIAButton>
<UIAButton name="关注" label="关注" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/0/6" x="253" y="30" width="60" height="24">
</UIAButton>
</UIANavigationBar>
<UIATableView name="" label="" value="moved to row 1 of 28" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/1" x="0" y="0" width="320" height="440">
<UIATableCell name="释老毛" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/1/0" x="0" y="244" width="320" height="203">
<UIAStaticText name="释老毛" label="释老毛" value="释老毛" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/1/0/0" x="60" y="251" width="36" height="29.5">
</UIAStaticText>
<UIAStaticText name="【声明】勿跟风,2015-7-8日停止更新,见《告雪友书——事了拂衣去,深藏身与名》 -----十二圣徒,核心组合,非卖品,弱周期,无与伦比,王者之风,王者虽然蒙尘,内心依然散发着君临天下的光辉。" label="【声明】勿跟风,2015-7-8日停止更新,见《告雪友书——事了拂衣去,深藏身与名》 -----十二圣徒,核心组合,非卖品,弱周期,无与伦比,王者之风,王者虽然蒙尘,内心依然散发着君临天下的光辉。" value="【声明】勿跟风,2015-7-8日停止更新,见《告雪友书——事了拂衣去,深藏身与名》 -----十二圣徒,核心组合,非卖品,弱周期,无与伦比,王者之风,王者虽然蒙尘,内心依然散发着君临天下的光辉。" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/1/0/1" x="60" y="280.5" width="248" height="144.5">
</UIAStaticText>
<UIAStaticText name="主理" label="主理" value="主理" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/1/0/2" x="99" y="258.5" width="24" height="14.5">
</UIAStaticText>
</UIATableCell>
<UIATableCell name="业绩评级 (最后评估时间:2015-12-11)" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/1" x="0" y="447" width="320" height="35">
<UIAStaticText name="业绩评级 (最后评估时间:2015-12-11)" label="业绩评级 (最后评估时间:2015-12-11)" value="业绩评级 (最后评估时间:2015-12-11)" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/1/0" x="0" y="0" width="285" height="17">
</UIAStaticText>
</UIATableCell>
<UIATableCell name="择时能力" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/2" x="0" y="482" width="320" height="260">
<UIAStaticText name="择时能力" label="择时能力" value="择时能力" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/2/0" x="0" y="0" width="86" height="26.687999725341797">
</UIAStaticText>
<UIAStaticText name="选股能力" label="选股能力" value="选股能力" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/2/1" x="0" y="0" width="86" height="26.687999725341797">
</UIAStaticText>
<UIAStaticText name="稳定性" label="稳定性" value="稳定性" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/2/2" x="0" y="0" width="72" height="26.687999725341797">
</UIAStaticText>
<UIAStaticText name="抗风险" label="抗风险" value="抗风险" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/2/3" x="0" y="0" width="72" height="26.687999725341797">
</UIAStaticText>
<UIAStaticText name="绝对收益" label="绝对收益" value="绝对收益" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/2/4" x="0" y="0" width="86" height="26.687999725341797">
</UIAStaticText>
<UIAStaticText name="45" label="45" value="45" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/2/5" x="0" y="0" width="42.42640686035156" height="42.42640686035156">
</UIAStaticText>
<UIAButton name="查看雪球星级评价标准" label="查看雪球星级评价标准" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/2/6" x="0" y="0" width="100" height="24">
</UIAButton>
</UIATableCell>
<UIATableCell name="查看组合投资报告" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/3" x="0" y="742" width="320" height="35">
<UIAStaticText name="查看组合投资报告" label="查看组合投资报告" value="查看组合投资报告" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/3/0" x="0" y="0" width="184" height="17">
</UIAStaticText>
<UIAStaticText name="2015-12-04更新" label="2015-12-04更新" value="2015-12-04更新" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/3/1" x="0" y="0" width="101" height="17">
</UIAStaticText>
</UIATableCell>
<UIATableGroup name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/4" x="0" y="447" width="320" height="10">
</UIATableGroup>
<UIATableCell name="最新调仓 (2015-12-11 10:50:34)" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/5" x="0" y="787" width="320" height="35">
<UIAStaticText name="最新调仓 (2015-12-11 10:50:34)" label="最新调仓 (2015-12-11 10:50:34)" value="最新调仓 (2015-12-11 10:50:34)" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/5/0" x="0" y="0" width="229" height="17">
</UIAStaticText>
<UIAStaticText name="调仓分析" label="调仓分析" value="调仓分析" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/5/1" x="0" y="0" width="56" height="17">
</UIAStaticText>
</UIATableCell>
<UIATableCell name="贵州茅台" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/6" x="0" y="822" width="320" height="50">
<UIAStaticText name="贵州茅台" label="贵州茅台" value="贵州茅台" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/6/0" x="0" y="0" width="73" height="17.5">
</UIAStaticText>
<UIAStaticText name="SH600519" label="SH600519" value="SH600519" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/6/1" x="0" y="0" width="47.5" height="12">
</UIAStaticText>
<UIAStaticText name="23.60% → 23.00%" label="23.60% → 23.00%" value="23.60% → 23.00%" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/6/2" x="0" y="0" width="137" height="19">
</UIAStaticText>
<UIAStaticText name="参考成交价 211.45" label="参考成交价 211.45" value="参考成交价 211.45" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/6/3" x="0" y="0" width="83.5" height="12">
</UIAStaticText>
<UIAStaticText name="卖" label="卖" value="卖" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/6/4" x="0" y="0" width="16" height="16">
</UIAStaticText>
<UIAButton name="下单" label="下单" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/6/5" x="0" y="0" width="48" height="32">
</UIAButton>
</UIATableCell>
<UIATableCell name="人福医药" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/7" x="0" y="872" width="320" height="50">
<UIAStaticText name="人福医药" label="人福医药" value="人福医药" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/7/0" x="0" y="0" width="90.5" height="17.5">
</UIAStaticText>
<UIAStaticText name="SH600079" label="SH600079" value="SH600079" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/7/1" x="0" y="0" width="47.5" height="12">
</UIAStaticText>
<UIAStaticText name="9.45% → 7.00%" label="9.45% → 7.00%" value="9.45% → 7.00%" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/7/2" x="0" y="0" width="119.5" height="19">
</UIAStaticText>
<UIAStaticText name="参考成交价 19.9" label="参考成交价 19.9" value="参考成交价 19.9" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/7/3" x="0" y="0" width="72.5" height="12">
</UIAStaticText>
<UIAStaticText name="卖" label="卖" value="卖" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/7/4" x="0" y="0" width="16" height="16">
</UIAStaticText>
<UIAButton name="下单" label="下单" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/7/5" x="0" y="0" width="48" height="32">
</UIAButton>
</UIATableCell>
<UIATableCell name="中国平安" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/8" x="0" y="922" width="320" height="50">
<UIAStaticText name="中国平安" label="中国平安" value="中国平安" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/8/0" x="0" y="0" width="73" height="17.5">
</UIAStaticText>
<UIAStaticText name="SH601318" label="SH601318" value="SH601318" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/8/1" x="0" y="0" width="47.5" height="12">
</UIAStaticText>
<UIAStaticText name="16.07% → 15.00%" label="16.07% → 15.00%" value="16.07% → 15.00%" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/8/2" x="0" y="0" width="137" height="19">
</UIAStaticText>
<UIAStaticText name="参考成交价 34.36" label="参考成交价 34.36" value="参考成交价 34.36" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/8/3" x="0" y="0" width="78" height="12">
</UIAStaticText>
<UIAStaticText name="卖" label="卖" value="卖" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/8/4" x="0" y="0" width="16" height="16">
</UIAStaticText>
<UIAButton name="下单" label="下单" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/8/5" x="0" y="0" width="48" height="32">
</UIAButton>
</UIATableCell>
<UIATableCell name="宋城演艺" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/9" x="0" y="972" width="320" height="50">
<UIAStaticText name="宋城演艺" label="宋城演艺" value="宋城演艺" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/9/0" x="0" y="0" width="90.5" height="17.5">
</UIAStaticText>
<UIAStaticText name="SZ300144" label="SZ300144" value="SZ300144" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/9/1" x="0" y="0" width="46" height="12">
</UIAStaticText>
<UIAStaticText name="1.22% → 0.00%" label="1.22% → 0.00%" value="1.22% → 0.00%" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/9/2" x="0" y="0" width="119.5" height="19">
</UIAStaticText>
<UIAStaticText name="参考成交价 29.45" label="参考成交价 29.45" value="参考成交价 29.45" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/9/3" x="0" y="0" width="78" height="12">
</UIAStaticText>
<UIAStaticText name="卖" label="卖" value="卖" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/9/4" x="0" y="0" width="16" height="16">
</UIAStaticText>
<UIAButton name="下单" label="下单" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/9/5" x="0" y="0" width="48" height="32">
</UIAButton>
</UIATableCell>
<UIATableCell name="美的集团" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/10" x="0" y="1022" width="320" height="50">
<UIAStaticText name="美的集团" label="美的集团" value="美的集团" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/10/0" x="0" y="0" width="81.5" height="17.5">
</UIAStaticText>
<UIAStaticText name="SZ000333" label="SZ000333" value="SZ000333" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/10/1" x="0" y="0" width="46" height="12">
</UIAStaticText>
<UIAStaticText name="10.56% → 0.00%" label="10.56% → 0.00%" value="10.56% → 0.00%" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/10/2" x="0" y="0" width="128.5" height="19">
</UIAStaticText>
<UIAStaticText name="参考成交价 29.21" label="参考成交价 29.21" value="参考成交价 29.21" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/10/3" x="0" y="0" width="78" height="12">
</UIAStaticText>
<UIAStaticText name="卖" label="卖" value="卖" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/10/4" x="0" y="0" width="16" height="16">
</UIAStaticText>
<UIAButton name="下单" label="下单" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/10/5" x="0" y="0" width="48" height="32">
</UIAButton>
</UIATableCell>
<UIATableCell name="五粮液" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/11" x="0" y="1072" width="320" height="50">
<UIAStaticText name="五粮液" label="五粮液" value="五粮液" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/11/0" x="0" y="0" width="73" height="17.5">
</UIAStaticText>
<UIAStaticText name="SZ000858" label="SZ000858" value="SZ000858" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/11/1" x="0" y="0" width="46" height="12">
</UIAStaticText>
<UIAStaticText name="12.63% → 12.00%" label="12.63% → 12.00%" value="12.63% → 12.00%" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/11/2" x="0" y="0" width="137" height="19">
</UIAStaticText>
<UIAStaticText name="参考成交价 24.37" label="参考成交价 24.37" value="参考成交价 24.37" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/11/3" x="0" y="0" width="78" height="12">
</UIAStaticText>
<UIAStaticText name="卖" label="卖" value="卖" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/1/11/4" x="0" y="0" width="0" height="0">
</UIAStaticText>
<UIAButton name="" label="" value="" dom="" enabled="false" valid="false" visible="false" hint="" path="/0/0/1/11/5" x="0" y="0" width="0" height="0">
</UIAButton>
</UIATableCell>
</UIATableView>
<UIAButton name="下单" label="下单" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/2" x="0" y="436" width="107" height="44">
</UIAButton>
<UIAButton name="点评" label="点评" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/3" x="107" y="436" width="107" height="44">
</UIAButton>
<UIAButton name="分享" label="分享" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/4" x="214" y="436" width="107" height="44">
</UIAButton>
<UIATabBar name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/5" x="0" y="431" width="320" height="49">
<UIAImage name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/5/0" x="0" y="430.5" width="320" height="0.5">
</UIAImage>
<UIAImage name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/5/1" x="0" y="431" width="320" height="49">
</UIAImage>
<UIAButton name="首页" label="首页" value="1" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/5/2" x="2" y="432" width="60" height="48">
</UIAButton>
<UIAButton name="自选" label="自选" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/5/3" x="66" y="432" width="60" height="48">
</UIAButton>
<UIAButton name="动态" label="动态" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/5/4" x="130" y="432" width="60" height="48">
</UIAButton>
<UIAStaticText name="95" label="95" value="95" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/5/5" x="166" y="434" width="24" height="18">
</UIAStaticText>
<UIAButton name="组合" label="组合" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/5/6" x="194" y="432" width="60" height="48">
</UIAButton>
<UIAButton name="交易" label="交易" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/5/7" x="258" y="432" width="60" height="48">
</UIAButton>
</UIATabBar>
<UIAPageIndicator name="" label="" value="page 1 of 3" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/7" x="0" y="666" width="320" height="21">
</UIAPageIndicator>
</UIAWindow>
<UIAWindow name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/1" x="0" y="0" width="320" height="480">
</UIAWindow>
<UIAWindow name="" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/2" x="0" y="0" width="320" height="480">
<UIAStatusBar name="" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/2/0" x="0" y="0" width="320" height="20">
<UIAElement name="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" label="" 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/2/0/0" x="6" y="0" width="39" height="20">
</UIAElement>
<UIAElement name="3 of 3 Wi-Fi bars" label="3 of 3 Wi-Fi bars" value="SSID" 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/2/0/1" x="50" y="0" width="13" height="20">
</UIAElement>
<UIAElement name="7:45 PM" label="7:45 PM" 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/2/0/2" x="138" y="0" width="49" height="20">
</UIAElement>
<UIAElement name="-100% battery power" label="-100% battery power" 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/2/0/3" x="290" y="0" width="25" height="20">
</UIAElement>
</UIAStatusBar>
</UIAWindow>
<UIAWindow name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/3" x="0" y="0" width="320" height="480">
</UIAWindow>
</UIAApplication>
</AppiumAUT>
如果采用 hash 的这种方式性能会不会太慢了
appium 拿不到 UIViewController
@seveniruby 你这种会累死的
#3 楼 @dengwei729 我目前用的这种方式, 还比较稳定. 也不慢. 只有 1s 耗时