如何使用Robot Framework查找断开的链接 [英] How to find Broken Links using Robot Framework
问题描述
我在查找网页上断开的链接时遇到问题.我使用的是 RequestsLibrary .现在,我可以找到所有链接,但现在可以根据响应代码对其进行验证.
I'm facing an issue with finding the broken links on the webpage. I'm using RequestsLibrary for the same. Right now I'm able to find all the links but now able to verify them against the response code.
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 来执行此操作,但是随后失败,并显示一条消息"****链接断言失败,消息为msg: [] "**
The error that I'm getting right now is "RequestsLibrary.Get Request expected 2 to 7 arguments, got 1." I've tried doing it with create session also, but then it fails with a message "**Link assertion Failed with msg: []"**
推荐答案
您需要先执行Create Session
,然后将alias
用作Get Request
的第一个参数. RequestsLibrary文档说得很清楚.
You need to do that Create Session
first and then pass the alias
as the first parameter for Get Request
. RequestsLibrary documentation says it quite clear.
另一个错误消息表明您在@{errors_msg}
中有一个空列表.我想您需要在此处传递索引号.
The other error message shows that you have an empty list in @{errors_msg}
. I guess you need to pass the index number there.
这篇关于如何使用Robot Framework查找断开的链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!