Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
using ruby to validate web pages
Kate Bond
1/18/2008 2:54:00 PM
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....
url1 = "
http://www.google...
url2 = "
http://pingmag.jp/2008/01/17/chim...
url3 = "
http://www.google....
# 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-...
.
3 Answers
lrlebron@gmail.com
1/23/2008 6:15:00 PM
0
On Jan 18, 8:54 am, Kate Bond <bondk...@googlemail.com> wrote:
> 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....
> url1 = "
http://www.google...
> url2 = "
http://pingmag.jp/2008/01/17/chim...
> url3 = "
http://www.google....
>
> # 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"
> --
> Posted via
http://www.ruby-...
.
Siep Korteling
1/23/2008 10:36:00 PM
0
lrlebron@gmail.com wrote:
> On Jan 18, 8:54 am, Kate Bond <bondk...@googlemail.com> wrote:
>> url1 = "
http://www.google...
>> 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....
urls =[]
urls << "
http://www.google...
urls << "
http://pingmag.jp/2008/01/17/chim...
urls << "
http://www.google....
# 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
--
Posted via
http://www.ruby-...
.
Kate Bond
1/24/2008 11:29:00 AM
0
Siep,
Wow! Had to add 'goto validator' to the block but otherwise worked a
treat... Thanks very much! :)
# the Watir gem
require 'rubygems'
# the Watir controller
require 'watir'
# set variables
validator = "
http://validator.w3....
urls =[]
urls << "
http://www.catnic....
urls << "
http://pingmag.jp/2008/01/17/chim...
urls << "
http://www.google....
# 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-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
using ruby to validate web pages
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password