當您檢查一個列表時,結果的第一頁上至少有兩項列表?
我測試了一個網站,它有多個不同類型的搜索結果,並且有測試來驗證它們的排序順序。
- 您需要檢查是否有某種方式來驗證列表排序的方向是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