【发布时间】:2020-02-18 16:05:33
【问题描述】:
我在网页上查找损坏的链接时遇到了问题。我也在使用 RequestsLibrary。现在我可以找到所有链接,但现在可以根据响应代码验证它们。
Get All Link Tests
[Tags] Regression
[Setup] Log To Console Test for total links present on landing page started...
${base_url}= Get Base Url
open browser about:blank ${browser}
go to ${base_url}
${ALL_LINKS_COUNT} get element count xpath://a
log to console ${ALL_LINKS_COUNT}
@{LINK_ITEMS} create list
: FOR ${index} IN RANGE 1 ${ALL_LINKS_COUNT}+1
\ log ${index}
\ ${link_text} get text xpath:(//a)[${index}]
\ ${href} Get Element Attribute xpath:(//a)[${index}] href
\ log ${link_text}
\ log to console ("The link text is "${link_text}" & href is "${href}" ${INDEX})
\ ${link_length} Get Length ${link_text}
\ Run Keyword If ${linklength}>1 Append To List ${LinkItems} ${href}
Log Many ${LINK_ITEMS}
Remove Values From List ${href} javascript:void(0) \#
${link_items_length} Get Length ${LINK_ITEMS}
@{errors_msg} Create List
: FOR ${index} IN RANGE ${link_items_length}
\ ${resp} Get Request ${LINK_ITEMS[${index}]}
\ ${code} Run Keyword And Return Status Should Be Equal As Strings ${resp.status_code} 200
\ Run Keyword Unless ${code} Append To List ${errors_msg} error :${LINK_ITEMS[${index}]} | ${resp.status_code}
${check} Run Keyword And Return Status Lists Should Be Equal ${errors_msg} ${EMPTY}
Run Keyword Unless ${check} Fail Link \ assertion Failed with msg:\n@{errors_msg}
我现在遇到的错误是 “RequestsLibrary.Get Request 预期 2 到 7 个参数,得到 1 个。” 我也尝试过使用 create session 进行操作,但随后它失败并显示消息 "**Link assertion Failed with msg: []"**
【问题讨论】:
标签: selenium selenium-webdriver robotframework