Hi All,
I am not sure what’s wrong in the below Get Request, when i run the script in Get Request link appended.
Issue : GET Request : url=http://127.0.0.1:5000//http://127.0.0.1:5000/index.html
Please see the below code and the Report screenshot.
I am stuck here! Really appreciate for the help.
*** Settings ***
Library Selenium2Library
Library Collections
Library RequestsLibrary
*** Variables ***
{url3} http://127.0.0.1:5000/
{BROWSER} chrome
*** Test Cases ***
BrokenLinksTest-ForPracticeSelenium-2ndPage
Open Browser {url3} {BROWSER}
Maximize Browser Window
VerifyAllLinksOn2ndPage
Close Browser
VerifyAllLinksOn2ndPage
Comment Count Number Of Links on the Page
{AllLinksCount}= get element count xpath://a
Comment Log links count
Log {AllLinksCount}
Comment Create a list to store link texts
@{LinkItems} Create List
Comment Loop through all links and store links value that has length more than 1 character
: FOR {INDEX} IN RANGE 1 {AllLinksCount}-1
\ Log ${INDEX}
\ ${link_text}= Get Text xpath=(//a)[${INDEX}] #<-- for what ? -->
\ ${href}= Get Element Attribute xpath=(//a)[${INDEX}] href
\ Log ${link_text}
\ log to console ("The link text is "${link_text}" & href is "${href}" ${INDEX})
\ ${linklength} Get Length ${link_text} #<-- you are checking text not href ? -->
\ Run Keyword If ${linklength}>1 Append To List ${LinkItems} ${href}
Log Many ${LinkItems}
Remove Values From List ${LinkItems} javascript:void(0) #<-- don't forget checking content on list -->
${linkitems_length} Get Length ${LinkItems}
Log Many ${LinkItems}
@{errors_msg} Create List
Create Session secondpage http://127.0.0.1:5000/
:FOR ${INDEX} IN RANGE ${linkitems_length}
\ Log Many ${LinkItems[${INDEX}]}
\ ${ret} get request secondpage ${LinkItems[${INDEX}]} \
\ log to console ${ret}
\ log ${ret}
\ ${code} Run Keyword And Return Status Should Be Equal As Strings ${ret.status_code} 200
#\ log to console "Gonna link" ${LinkItems[${INDEX}]}
\ click link {LinkItems[{INDEX}]}
#\ Capture Page Screenshot
#\ Click Link link={LinkItems[{INDEX}]}
\ Run Keyword Unless {code} Append To List {errors_msg} error :{LinkItems[{INDEX}]} | {ret.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}
Sleep 1
Thanks,
Raj