Search code examples
rubywatirwatir-webdriver

verify multiple links are directed to right page


I'm new to ruby. using watir i'm written scripts to check multiple links are being directed to the right page as below.

Link= ["Link", "Link1"]
Link.each do |LinkValue|      @browser.link(:text=>LinkValue).wait_until_present.click
fail unless @browser.text.include? LinkValue
@browser.back   
end
  1. maintaining Linktext in an array
  2. iterating with each linktext
  3. verify
  4. navigate to the previous page to start verifying with next linktext.

But the script is not working. it is not executing after first value


Solution

  • Link= ["Link", "Link1"]
    result=[]
    Link.each do |LinkValue|
      if @browser.link(:text => LinkValue).exists?
        @browser.link(:text => LinkValue).click
        if @browser.url.eql?'ExpectedUrlhere'
          result=[LinkValue,'success']
        else
          result=[LinkValue,'failure']
        end
        @browser.back
      end
    end
    
    p result
    

    This might help.