Using ruby to validate web pages

Hi, just wondering if anybody can tell me what's wrong with this code:

# the Watir gem
require 'rubygems'

# the Watir controller
require 'watir'

# set variables
validator = "http://validator.w3.org/"
url1 = "http://www.google.com"
url2 = "http://pingmag.jp/2008/01/17/chimpom/"
url3 = "http://www.google.com/"

# open the IE browser
ie = Watir::IE.new

puts "Beginning validation"

ie.goto validator

ie.text_field(:id, "uri").set(url1)

puts "Checking URL #1....."

ie.button(:value, "Check").click

if ie.text.include? "This Page Is Valid"
    puts "URL#1 validates!"
    else
        "URL#1 does not validate!"

        end

ie.goto validator

ie.text_field(:id, "uri").set(url2)

puts "Checking URL #2....."

ie.button(:value, "Check").click

if ie.text.include? "This Page Is Valid"
    puts "URL#2 validates!"
    else
        "URL #2 does not validate!"

    end

ie.goto validator

ie.text_field(:id, "uri").set(url3)

puts "Checking URL #3....."

ie.button(:value, "Check").click

if ie.text.include? "This Page Is Valid"
    puts "URL#3 validates!"
    else
        "URL #3 does not validate!"

end

    puts "End of validation"

I get results for URL's #2 and #3, only the 'Checking URL....' and 'End
of validation' messages.

···

--
Posted via http://www.ruby-forum.com/.

Hi, just wondering if anybody can tell me what's wrong with this code:

# the Watir gem
require 'rubygems'

# the Watir controller
require 'watir'

# set variables
validator = "http://validator.w3.org/"
url1 = "http://www.google.com"
url2 = "http://pingmag.jp/2008/01/17/chimpom/"
url3 = "http://www.google.com/"

# open the IE browser
ie = Watir::IE.new

puts "Beginning validation"

ie.goto validator

ie.text_field(:id, "uri").set(url1)

puts "Checking URL #1....."

ie.button(:value, "Check").click

if ie.text.include? "This Page Is Valid"
    puts "URL#1 validates!"
    else
        "URL#1 does not validate!"

        end

ie.goto validator

ie.text_field(:id, "uri").set(url2)

puts "Checking URL #2....."

ie.button(:value, "Check").click

if ie.text.include? "This Page Is Valid"
    puts "URL#2 validates!"
    else
        "URL #2 does not validate!"

    end

ie.goto validator

ie.text_field(:id, "uri").set(url3)

puts "Checking URL #3....."

ie.button(:value, "Check").click

if ie.text.include? "This Page Is Valid"
    puts "URL#3 validates!"
    else
        "URL #3 does not validate!"

end

    puts "End of validation"

I get results for URL's #2 and #3, only the 'Checking URL....' and 'End
of validation' messages.

Your are missing the "puts" before the "URL # does not validate"

···

On Jan 18, 8:54 am, Kate Bond <bondk...@googlemail.com> wrote:

--
Posted viahttp://www.ruby-forum.com/.

lrlebron@gmail.com wrote:

url1 = "http://www.google.com"
ie.text_field(:id, "uri").set(url1)
        end
    puts "URL#2 validates!"

I get results for URL's #2 and #3, only the 'Checking URL....' and 'End
of validation' messages.

Your are missing the "puts" before the "URL # does not validate"

If you had 200 pages to validate, you'd have to correct 200 lines of
code.
Consider this (untested, I don't know Watir):

require 'watir'

# set variables
validator = "http://validator.w3.org/&quot;
urls =
urls << "http://www.google.com"
urls << "http://pingmag.jp/2008/01/17/chimpom/&quot;
urls << "http://www.google.com/&quot;

# open the IE browser
ie = Watir::IE.new
puts "Beginning validation"
ie.goto validator # maybe this should be in the block.

urls.each do|url|
  puts "Checking " + url
  ie.text_field(:id, "uri").set(url)
  ie.button(:value, "Check").click
  if ie.text.include? "This Page Is Valid"
    puts url + " validates!"
  else
    url + " does not validate!" #!! This line needs a 'puts' !!
  end
end
ie.close #or something like it
puts "End of validation"

Both the the list of urls and the code handling this list are now much
easier to maintain.

Regards,

Siep

···

On Jan 18, 8:54 am, Kate Bond <bondk...@googlemail.com> wrote:

--
Posted via http://www.ruby-forum.com/\.

Siep,

Wow! Had to add 'goto validator' to the block but otherwise worked a
treat... Thanks very much! :slight_smile:

# the Watir gem
require 'rubygems'

# the Watir controller
require 'watir'

# set variables
validator = "http://validator.w3.org/"
urls =[]
urls << "http://www.catnic.com/"
urls << "http://pingmag.jp/2008/01/17/chimpom/"
urls << "http://www.google.com/"

# open the IE browser
ie = Watir::IE.new
puts "Beginning validation"

urls.each do|url|
  puts "Checking " + url
  ie.goto validator # maybe this should be in the block.
  ie.text_field(:id, "uri").set(url)
  ie.button(:value, "Check").click
  if ie.text.include? "This Page Is Valid"
    puts url + " validates!"
  else
    puts url + " does not validate!" #!! This line needs a 'puts' !!
  end
end
ie.close #or something like it
puts "End of validation"

I'm very new to Ruby (programming in general, actually) but I wonder if
there is a way to incorporate this into a webpage? This might not seem
much but is going to make my job as a tester a little easier!

···

--
Posted via http://www.ruby-forum.com/.