(Please bear with me, I have very long mail and lots issue).

Hi,
I am trying to automate sending mails using GMail. I have 3 scenarios.

(Please refer to the actual code at the bottom of the mail).

Case 1: Works fine (not actually, ruby exits after iteration, but I will
discuss it in another thread).

for 1 to 50
login
sendmail
logout

Case 2: Fails to set value for the to,subject and mailbody fields after few 
iteration.

login
for 1 to 50
sendmail
logout

In this case after sending the first, few mails, it shows the 
to,subject,mailbody fields. The exists? test passes for these controls. 

However setting the values on these controls does not reflect the 
value in ie. Also, flash method does not flash it. When I read the 
value from these controls, I can read them. 

One interesting thing that I noted is, if I set
the value in ie directly and then read the control, I dont get
the new value, but what I get is the old value.

Have I found a bug? Isn't watir refreshing the new DOM tree after
sending the mail? 

#Case 3 (Works fine, but after few iteration I get exception)

login
for 1 to 50
sendmail
click on starred mails #just to ensure the DOM is refreshed
logout

This case works fine, I can set all the value and send mails
successfully. This case also strengthens my doubt that watir
is probably not refreshing the DOM in 2nd case. But this case
fails after few iteration with following exception

c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.1.1164/./watir.rb:1819:in 
`method_missing': unknown property or method `readyState' (WIN32OLERuntimeError)
    HRESULT error code:0x80070005
      Access is denied. from 
c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.1.1164/./watir.rb:1819:in `wait'
        from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.1.1164/./watir.rb:224:in 
`wait'
        from c:/ruby/lib/ruby/gems/1.8/gems/watir-1.5.1.1164/./watir.rb:2575:in 
`click'
        from try.rb:53:in `SendMailGmail'
        from try.rb:70
        from try.rb:69:in `each'
        from try.rb:69

Any ideas?
Thanks,
Devyani

===================CODE STARTS HERE=============
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__

require 'watir'   # the watir controller

module R_Gmail

def InitializeR_Gmail(ie)
  @ie = ie
end

def LoginGmail(propertyValueMap)
  test_site = "http://www.gmail.com";
  begin
    @ie.goto(test_site)
  rescue Exception  => ex
    puts "In err   "  + ex.message
  end # end begine block
  sleep(2)
  if (@ie.text_field(:name, "Email").exists?())
    @ie.text_field(:name, "Email").set(propertyValueMap["login"])
  end
  if (@ie.text_field(:name, "Passwd").exists?())
    @ie.text_field(:name, "Passwd").set(propertyValueMap["password"])
  end
  begin
    @ie.button(:name, "signIn").click()
  rescue Exception  => ex
    puts "In err IE btn  "  + ex.message
  end # end begine block
  sleep(2)
end

def LogOutGmail()
  @ie.frame(:name, "main").frame(:id, "v1").link(:text, "Sign out").click
end

def SendMailGmail(mailTo, mailSubject, mailBody)
  puts "In SendMailGmail function"
  @ie.send_keys("c")
  sleep(2)
  if (@ie.frame(:name, "main").frame(:id, "v2").text_field(:id, 
"to_compose").exists?())
    puts "Mail To Address - #{mailTo}"
    @ie.frame(:name, "main").frame(:id, "v2").text_field(:id, 
"to_compose").set(mailTo)
  end  
  if (@ie.frame(:name, "main").frame(:id, "v2").text_field(:name, 
"subject").exists?())
    puts "Mail Subject - #{mailSubject}"
    @ie.frame(:name, "main").frame(:id, "v2").text_field(:name, 
"subject").set(mailSubject)
  end
  if (@ie.frame(:name, "main").frame(:id, "v2").div(:id, 
"hc_compose").exists?())
    puts "Mail Body - #{mailBody}"
    @ie.frame(:name, "main").frame(:id, "v2").div(:id, 
"hc_compose").document.innerHTML=mailBody
  end
  @ie.frame(:name, "main").frame(:id, "v2").button(:id, "snd").click 
  @ie.frame(:name, "main").wait()
  sleep(3)
end # end function SendMail

end # end module R_Gmail

include R_Gmail
ie = Watir::IE.new
ie.set_fast_speed()
InitializeR_Gmail(ie)
propertyValueMap1 = Hash.new
propertyValueMap1["login"] = <Enter valid user id>
propertyValueMap1["password"] = <Enter password>

#Case 1
for i in (1..50)
LoginGmail(propertyValueMap1)
SendMailGmail("[EMAIL PROTECTED]", "Subject", "mailBody")
@ie.send_keys("gs")
LogoutGmail()
end

#Case 2
LoginGmail(propertyValueMap1)
for i in (1..50)
SendMailGmail("[EMAIL PROTECTED]", "Subject", "mailBody")
end
LogoutGmail

#Case 3
LoginGmail(propertyValueMap1)
for i in (1..50)
SendMailGmail("[EMAIL PROTECTED]", "Subject", "mailBody")
@ie.send_keys("gs")
end
LogoutGmail
===================CODE ENDS HERE=============

Message was edited by: devya
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to