Created a magical ruby script that will download all the form objects from a webpage of your choosing and out put the results as a list of assert(@@ie.thing(how, with).exists?,'Could not find a thing') entries ready for your watir test script

git-svn-id: http://locode01.ad.dom/svn/WEBMIP/trunk@2939 248e525c-4dfb-0310-94bc-949c084e9493
This commit is contained in:
PriestJ
2007-12-04 18:33:22 +00:00
parent b0bd738dd4
commit 5325721f04

View File

@@ -0,0 +1,63 @@
#Grab screen bits
#requires
require 'watir'
#includes
include Watir
#
#Set the page you want WATIR to grab all the fields and buttons for here
#
MYPAGE = "http://loordv01/pls/apex/f?p=102:32"
@@ie = IE.new
@@ie.maximize
#set the speed of watir, we'd also set the speed of light but that's supposed to be a constant
@@ie.speed = :fast
@@ie.goto(MYPAGE)
@@ie.wait
@@ie.text_field( :id, 'P101_USERNAME' ).set( 'advantica' )
@@ie.text_field( :id, 'P101_PASSWORD' ).set( 'password' )
@@ie.button(:id, "login").click
@@ie.wait
#Get the ole object
doc = @@ie.document
i=0
doc.all.each do |n|
begin
if n.invoke("type").to_s == 'button'
davalue = n.invoke('value').to_s
puts "assert(@@ie.button(:value,'"+davalue+"').exists?,'Could not find "+davalue+" button')"
i=i+1
end
if n.invoke("type").to_s == 'text'or n.invoke("type").to_s == 'textarea'
davalue = n.invoke('id').to_s
puts "assert(@@ie.text_field(:id,'"+davalue+"').exists?,'Could not find "+davalue+" field')"
i=i+1
end
if n.invoke("type").to_s == 'select-one'
davalue = n.invoke('id').to_s
puts "assert(@@ie.select_list(:id,'"+davalue+"').exists?,'Could not find "+davalue+" select list')"
i=i+1
end
if n.invoke("type").to_s == 'checkbox'
davalue = n.invoke('id').to_s
puts "assert(@@ie.checkbox(:id,'"+davalue+"').exists?,'Could not find "+davalue+" checkbox')"
i=i+1
end
if n.invoke("type").to_s == 'radio'
davalue = n.invoke('id').to_s
puts "assert(@@ie.radio(:id,'"+davalue+"').exists?,'Could not find "+davalue+" radio button')"
i=i+1
end
if n.invoke("type").to_s == 'file'
davalue = n.invoke('id').to_s
puts "assert(@@ie.text_field(:id,'"+davalue+"').exists?,'Could not find "+davalue+" file upload field')"
i=i+1
end
rescue #if we invoke a type method that doesn't exist get the next element
next
end
end
puts "Found #{i} form element(s) on page #{MYPAGE}"