'Sort and compare
I want to check the "sort" feature when user click the column header to sort the list.
I am planning to do it in steps:
- Get the current list: below script iterate the table row by row.
*** Settings ***
Library Browser
Library String
Library Collections
Resource ../Resources/BrowserFunctions.robot
Suite Setup Start New Browser
Suite Teardown Close Browser
*** Test Cases ***
001-Models
Open New Page To Server
Navigate To Models Module
${elements} = Get Elements table tr td:nth-child(2)
${modelList}= Create List
FOR ${elem} IN @{elements}
${text}= Get Text ${elem}
${new elem}= Set Variable ${text}
Append To List ${modelList} ${new elem}
END
Log To Console ${modelList}
How do I sort the list (this will be stored as ${expected} variable).
User click on the column header
Repeat #1 get the list and stored it as ${actual} variable.
${expected} == ${actual} then PASS
Solution 1:[1]
*** Test Cases ***
Test_Sort_And_Compare_Asc
[Tags] compareAsc
${expected} Create List z x y
${Actual} Create List x y z
Sort List ${expected}
# Sort List ${Actual}
Lists Should Be Equal ${expected} ${Actual}
Test_Sort_And_Compare_Desc
[Tags] compareDesc
${expected} Create List x y z
${Actual} Create List z y x
Reverse List ${expected}
Lists Should Be Equal ${expected} ${Actual}
Test_Compare
[Tags] compare
${expected} Create List z x y
${Actual} Create List x y z
Lists Should Be Equal ${expected} ${Actual}
You can use 3rd case which is suitable for you, As you have sorted list in expected variable and actual list in actual variable. Because you are fetching sorted list from application in expected variable.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Manish Kumar |
