How to verify image properties using Ruby/Watir

April 25, 2009

An example to grab the first image loaded on a page and return the width and height.

$ie.goto(url)

width = $ie.image(:index,1).width
widthnum =  Integer(width) #Convert to integer.  #
if widthnum >50
f.puts “- SUCCESS: Width of image loaded: #{widthnum}”
else
f.puts “!!!!! WARNING: Did not find width for image on page !!!!!”
end

height = $ie.image(:index,1).height
heightnum = Integer(height) #Convert string to integer. #
if heightnum > 50 #height != nil (pixel version) #
f.puts “- SUCCESS: Height of image loaded: #{heightnum}”
else
f.puts “!!!!! WARNING: Did not find height for image on page !!!!!”
end

Previous post: Walk-in For Performance Testing @ L&T Infotech Chennai 0n 5th Dec 09

Next post: Replace character using Ruby/Watir