如何验证 Selenium IDE 中按要求排序的结果,例如按字母顺序排序或 ID 递减
How Can I verity the results ordered as required in Selenium IDE, such as alphabetically sort or ID decreasing
我是Selenium的新手IDE,我需要验证列表顺序是否符合要求。我们列出了从数据库中获得的一些记录。我知道我可以创建两个具有特定值的记录,并使用 verifyOrdered 或 assertOrdered 实现它。但是我们有不同的排序顺序,例如按ID DESC 排序或按名称字母ASC 排序,并且我们有分页工具,因此创建的两条记录可能不会显示在同一页中。
那么有没有什么有用的方法可以在不知道值(例如 ID desc)的情况下验证特定定位器列表的顺序?提前致谢。
当您检查列表时,是否至少有两项列表位于结果的第一页?
我测试了一个网站,该网站有多个不同类型的搜索结果,并进行了验证所有结果排序顺序的测试。
- 您需要查看是否有某种方法可以验证列表的排序方向,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}'
}
在 selenium 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>
}
希望这对您有所帮助。
-- 克伦达图
我是Selenium的新手IDE,我需要验证列表顺序是否符合要求。我们列出了从数据库中获得的一些记录。我知道我可以创建两个具有特定值的记录,并使用 verifyOrdered 或 assertOrdered 实现它。但是我们有不同的排序顺序,例如按ID DESC 排序或按名称字母ASC 排序,并且我们有分页工具,因此创建的两条记录可能不会显示在同一页中。
那么有没有什么有用的方法可以在不知道值(例如 ID desc)的情况下验证特定定位器列表的顺序?提前致谢。
当您检查列表时,是否至少有两项列表位于结果的第一页?
我测试了一个网站,该网站有多个不同类型的搜索结果,并进行了验证所有结果排序顺序的测试。
- 您需要查看是否有某种方法可以验证列表的排序方向,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}'
}
在 selenium 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>
}
希望这对您有所帮助。 -- 克伦达图