From 5325721f04e14e38df9a49ce979a10116f10425d Mon Sep 17 00:00:00 2001 From: PriestJ Date: Tue, 4 Dec 2007 18:33:22 +0000 Subject: [PATCH] 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 --- tests/getallobjectsonscreen.rb | 63 ++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tests/getallobjectsonscreen.rb diff --git a/tests/getallobjectsonscreen.rb b/tests/getallobjectsonscreen.rb new file mode 100644 index 0000000..9abf2b0 --- /dev/null +++ b/tests/getallobjectsonscreen.rb @@ -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}" \ No newline at end of file