排序和比较
Sort and compare
我想在用户单击 header 列对列表进行排序时检查“排序”功能。
我打算分步进行:
- 获取当前列表:下面的脚本逐行迭代 table。
*** 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}
如何对列表进行排序(这将存储为 ${expected} 变量)。
用户点击列header
重复 #1 获取列表并将其存储为 ${actual} 变量。
${预期} == ${实际}然后通过
*** 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}
您可以使用适合您的第三种情况,因为您已经对预期变量中的列表和实际变量中的实际列表进行了排序。因为您正在从预期变量中的应用程序中获取排序列表。
我想在用户单击 header 列对列表进行排序时检查“排序”功能。
我打算分步进行:
- 获取当前列表:下面的脚本逐行迭代 table。
*** 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}
如何对列表进行排序(这将存储为 ${expected} 变量)。
用户点击列header
重复 #1 获取列表并将其存储为 ${actual} 变量。
${预期} == ${实际}然后通过
*** 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}
您可以使用适合您的第三种情况,因为您已经对预期变量中的列表和实际变量中的实际列表进行了排序。因为您正在从预期变量中的应用程序中获取排序列表。