属性比较部分

 

在高级RanoreXPath Editor的属性等式部分,你可以定义基于RanoreXPath的属性值比较。如果你想定义不同属性访问的适配器而不用Ranorex所建议的,你可以自由地通过勾选或者不勾选相应的属性来改变对象标识方法。

考虑KeePass和数据驱动方法(见课程3:数据驱动测试),我们通过验证条目在单元格中的存在来验证“Adding an entry”(添加一个条目)的成功。因而我们添加两个样本条目(WordPressDemo 和 GMail)到KeePass中。当用Ranorex Spy追踪Gmail条目的User Name(第二行第二单元格)时,在path Editor中,得到如下RanoreXPath的结构:

/ form [ @controlname =’MainForm ’]/ container / container [ @caption =’’ and @controltypename =’ SplitterPanel ’ and @instance =’0’]/ container / container [ @caption =’’ and @controltypename =’ SplitterPanel ’ and @instance =’1’]/ table / row [ @index =’1’]/ cell [ @text =’Ranorex ’]

从RanoreXPath结构(在高级RanoreXPath Editor中)和RanoreXPath本身,我们可以看出,row(适配器)是由索引属性指示的(row[@index=’1′])。这就意味着“Ranorex”单元格只有位于第一行的时候才会被识别出来。如果在这个单元格上插入新的一行,使得它的索引值改变,它将不会被找到。而且,为列排序(如Username列)也容易引起row索引值发生改变。为了避免row索引值带来的问题,你可以用RanoreXPath Editor,在row节点不勾选index属性选框来改变其路径,使得该元素和row无关。

10-rx-uncheck-row-82

图:在row节点不勾选index属性

/ form [ @controlname =’MainForm ’]/ container / container [ @caption =’’ and @controltypename =’ SplitterPanel ’ and @instance =’0’]/ container / container [ @caption =’’ and @controltypename =’ SplitterPanel ’ and @instance =’1’]/ table / row / cell [ @text =’Ranorex ’]

这条路径指向含有文本“Ranorex”的任何行的任何单元格。考虑到我们要验证添加一个条目是否成功,如果这条路径指向任何行中UserName列的文本值“Ranorex”,会更有意义。因而我们再次打开RanoreXPath Editor,通过勾选来添加列索引属性。

10-rx-path-cell-ae

图:勾选列索引属性

/ form [ @controlname =’MainForm ’]/ container / container [ @caption =’’ and @controltypename =’ SplitterPanel ’ and @instance =’0’]/ container / container [ @caption =’’ and @controltypename =’ SplitterPanel ’ and @instance =’1’]/ table / row / cell [ @text =’Ranorex ’ and @columnindex =’1’]

如果添加另外一个有相同UserName(“Ranorex”)的KeePass条目,这条路径将指向多个结果。你可以容易地在path editor中检查你的XPath结果——通过看左下角的文本。

 10-rx-path-2results-f7

图:当前路径指向两个元素

为了找出当前路径指向了哪些元素,请点击RanoreXPath Editor底部的“Highlight”按钮

 10-kp-tworesults-71

图:路径指向KeePass的两个元素

如你所见,创建一个健壮和唯一的路径是至关重要的任务,这经常依赖于应用程序的特性。在此过程中,Ranorex尽可能灵活地给你提供最优化的支持。

Leave a comment

请输入正确的验证码