2016-12-06 81 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