我可以一次验证 xpaths 列表吗?
Can i verify a list of xpaths at once?
我是 Robot Framework 的新手,所以我创建了一个测试用例来验证目标网页上是否存在大量元素,所以我的问题是:
Page Should Contain Element ${text_field1}
Page Should Contain Element ${text_field2}
Page Should Contain Element ${text_field3}
....
我可以用这些 xpath 做一个列表并立即验证该列表是否存在于网页上吗?
有没有机器人框架功能可以做到这一点?谢谢
不,我们没有用于页面中多个检查元素的关键字。但是我们可以在用户关键字中创建该逻辑。请参阅下面的完整示例。
*** Settings ***
Library SeleniumLibrary 15 2
Library Collections
*** Variables ***
${BROWSER} Chrome
@{elements} xpath=//div[@id="error"] id=searchInput xpath=//button[@type="submit"]
*** Test Cases ***
Simple Test
Open Browser http://www.wikipedia.org ${BROWSER}
Comment Wait Until Element Is Visible id=searchInput # search input field
${result}= Page Should Contain Elements ${elements}
IF not ${result}
Fail Page did not contained expected elements
END
Input Text ${elements[0]} Robot Framework
Wait Until Element Is Visible ${elements[1]}
Click Button ${elements[1]}
Wait Until Page Contains Robot Framework
Capture Page Screenshot
[Teardown] Close All Browsers
*** Keywords ***
Page Should Contain Elements
[Arguments] ${elements}
@{results}= Create List
FOR ${element} IN @{elements}
${result}= Run Keyword And Ignore Error Page Should Contain Element ${element}
IF "${result[0]}" == "FAIL"
Append To List ${results} ${element}
END
END
${ret}= Evaluate len(${results}) == 0
Return From Keyword If ${ret} True
FOR ${element} IN @{results}
Log Fail: Page should have contained element ${element} but it did not WARN
END
Return From Keyword False
我是 Robot Framework 的新手,所以我创建了一个测试用例来验证目标网页上是否存在大量元素,所以我的问题是:
Page Should Contain Element ${text_field1}
Page Should Contain Element ${text_field2}
Page Should Contain Element ${text_field3}
....
我可以用这些 xpath 做一个列表并立即验证该列表是否存在于网页上吗? 有没有机器人框架功能可以做到这一点?谢谢
不,我们没有用于页面中多个检查元素的关键字。但是我们可以在用户关键字中创建该逻辑。请参阅下面的完整示例。
*** Settings ***
Library SeleniumLibrary 15 2
Library Collections
*** Variables ***
${BROWSER} Chrome
@{elements} xpath=//div[@id="error"] id=searchInput xpath=//button[@type="submit"]
*** Test Cases ***
Simple Test
Open Browser http://www.wikipedia.org ${BROWSER}
Comment Wait Until Element Is Visible id=searchInput # search input field
${result}= Page Should Contain Elements ${elements}
IF not ${result}
Fail Page did not contained expected elements
END
Input Text ${elements[0]} Robot Framework
Wait Until Element Is Visible ${elements[1]}
Click Button ${elements[1]}
Wait Until Page Contains Robot Framework
Capture Page Screenshot
[Teardown] Close All Browsers
*** Keywords ***
Page Should Contain Elements
[Arguments] ${elements}
@{results}= Create List
FOR ${element} IN @{elements}
${result}= Run Keyword And Ignore Error Page Should Contain Element ${element}
IF "${result[0]}" == "FAIL"
Append To List ${results} ${element}
END
END
${ret}= Evaluate len(${results}) == 0
Return From Keyword If ${ret} True
FOR ${element} IN @{results}
Log Fail: Page should have contained element ${element} but it did not WARN
END
Return From Keyword False