当您检查一个列表时,结果的第一页上至少有两项列表?
我测试了一个网站,它有多个不同类型的搜索结果,并且有测试来验证它们的排序顺序。
- 您需要检查是否有某种方式来验证列表排序的方向是ASC还是DSC。检查一个可能类似于“css = th.sortasc”或“css-th.sortdsc”的元素,以验证方向。
- 一旦你可以做到这一点,从列表中获取任何两个值(可能是列表中的第一个值,下一个或更多的分页值),然后比较它们以验证其中的一个大于还是小于其他。
- 您可能需要对数据进行一些清理,具体取决于它是否应该是数字或字符串。
我正在使用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'] < storedVars['2ndRowName']);</td>
<td>isLess</td>
</tr>
<tr>
<td>verifyExpression</td>
<td>${isLess}</td>
<td>true</td>
</tr>
}
希望这有助于。 - Klendathu
是的,似乎这是我现在发现的唯一方法。但也许两个定位器值是相等的,所以我最终决定创建两个不同值的记录,我可以比较,我需要缩小搜索条件,以便这两个记录显示在同一页面中。 – Echo