2016-12-06 48 views
0

我是新来的Selenium IDE,我需要验证列表顺序是否需要。我们列出了从数据库中获得的一些记录。我知道我可以创建两个具有特定值的记录,并使用verifyOrdered或assertOrdered来实现它。但是我们有不同的排序顺序,例如按ID DESC排序或按字母顺序排列ASC,并且我们有分页工具,因此创建的两个记录可能不会显示在同一页中。如何在Selenium IDE中按照要求排列结果,例如按字母顺序排序或ID降低

那么是否有任何有用的方法,我可以验证特定定位器列表的顺序而不知道值,如ID desc?提前致谢。

回答

0

当您检查一个列表时,结果的第一页上至少有两项列表?

我测试了一个网站,它有多个不同类型的搜索结果,并且有测试来验证它们的排序顺序。

  1. 您需要检查是否有某种方式来验证列表排序的方向是ASC还是DSC。检查一个可能类似于“css = th.sortasc”或“css-th.sortdsc”的元素,以验证方向。
  2. 一旦你可以做到这一点,从列表中获取任何两个值(可能是列表中的第一个值,下一个或更多的分页值),然后比较它们以验证其中的一个大于还是小于其他。
  3. 您可能需要对数据进行一些清理,具体取决于它是否应该是数字或字符串。

我正在使用RobotFramework和Selenium来做我们的测试,下面是一些示例代码,它代表您正在做的事情。 {

Click Element ${Name_Column_Header} #clicks the header to sort the column. 
Sleep 2s 
Element Should Be Visible css=th.sortdsc > a #verifies the sort caret is shown and it's descending. 
#next 3 lines grab the text from the field (in this case, person names) 
${Name1} Get Text css=td.ng-binding 
${Name2} Get Text //tbody[2]/tr/td 
${Name3} Get Text //tbody[3]/tr/td 
#next lines grab just the last name from each name, since list is sorted by last name. 
${N1} Fetch From Right ${Name1} ${SPACE} 
${N2} Fetch From Right ${Name2} ${SPACE} 
${N3} Fetch From Right ${Name3} ${SPACE} 
#next two lines do the compare, verifying that the name in line 1 is greater than the name in line 2, and line 2 name is greater than line 3 
Should Be True '${N1}' >= '${N2}' 
Should Be True '${N2}' >= '${N3}' 

}

在硒IDE,命令将是非常相似的。

{

<!--Sort by name--> 
<tr> 
    <td>clickAndWait</td> 
    <td>link=Name</td> 
    <td></td> 
</tr> 
<!--Grab values for name from 1st and 2nd row--> 
<tr> 
    <td>storeText</td> 
    <td><locator value> 
    <td>1stRowName</td> 
</tr> 

<tr> 
    <td>storeText</td> 
    <td><locator value> 
    <td>2ndRowName</td> 
</tr> 
<!--evaluate that 1st row name is less than or equal to 2nd row name--> 
<tr> 
    <td>storeEval</td> 
    <td>var isLess = false; isLess = eval(storedVars['1stRowName'] &lt; storedVars['2ndRowName']);</td> 
    <td>isLess</td> 
</tr> 
<tr> 
    <td>verifyExpression</td> 
    <td>${isLess}</td> 
    <td>true</td> 
</tr> 

}

希望这有助于。 - Klendathu

+0

是的,似乎这是我现在发现的唯一方法。但也许两个定位器值是相等的,所以我最终决定创建两个不同值的记录,我可以比较,我需要缩小搜索条件,以便这两个记录显示在同一页面中。 – Echo