lib/gmail_test/assertions/gmail.rb in gmail_test-0.0.5 vs lib/gmail_test/assertions/gmail.rb in gmail_test-0.0.6
- old
+ new
@@ -1,41 +1,71 @@
+# These assertions are compatible with gmail with english language set in settings.
+# They do tests using html basic view for gmail.
module Assertions
module Gmail
+ def assert_logged_in(email,password)
+ visit "http://gmail.com"
+ fill_in "Email", :with => email
+ fill_in "Passwd", :with => password
+ assert_appears("#loading") do
+ click_button "Sign in"
+ end
+ wait_until { has_css?("iframe#canvas_frame") }
+ assert_basic_html_view
+ wait_until{ has_css?("#guser b.gb4", :text => email) }
+ end
- def assert_logged_in(email,password)
- visit "http://gmail/com"
- fill_in "Email", :with => email
- fill_in "Passwd", :with => password
- assert_appears("#loading") do
- click_button "Sign in"
- end
- wait_until { has_no_css?("#loading") }
- within_frame "canvas_frame" do
- wait_until { has_css?("#gbi4m1", :text => email) }
- end
- end
+ def assert_logged_out
+ click_link "Sign out"
+ assert has_css?("#gaia_loginform")
+ end
- def assert_logged_out
- within_frame "canvas_frame" do
- find("#gbi4m1").click
- click_link "Sign out"
- end
- switch_to_main_window
- wait_until { assert has_css?(".signin-box #gaia_loginform") }
- end
+ def assert_email_sent(subject,body,to,cc)
+ find("a",:text => "Compose Mail").click
+ wait_until { has_css?("textarea[name='to']") }
+ fill_in("to", :with => to)
+ fill_in("cc", :with => cc)
+ fill_in("subject", :with => subject)
+ fill_in("body", :with => body)
+ assert_appears("b", :text => "Your message has been sent.") do
+ find("input[name='nvp_bu_send']").click
+ end
+ end
- def assert_email_sent(subject,body,to)
- switch_to_main_window/
- find("div", :text => "Compose mail").click
- within_frame "canvas_frame" do
- wait_until { assert has_css?("textarea[name='to']") }
- end
- end
+ def assert_email_received(from,subject,&block)
+ start_time = Time.now
+ wait_time = 20
+ success = false
- protected
+ begin
+ visit "http://mail.google.com/?ui=html"
+ within("form[name='f'] table.th tbody tr:nth-child(1)") do
+ if find("td:nth-child(2)").text =~ Regexp.new(from) && find("td:nth-child(3)").text =~ Regexp.new(subject)
+ success = true
+ else
+ raise "timeout"
+ end
+ end
+ rescue
+ assert false if (Time.now - start_time) >= wait_time
+ sleep 3
+ retry
+ end
- def switch_to_main_window
- page.driver.browser.switch_to.window page.driver.browser.window_handles.first
- end
+ if block
+ within("form[name='f'] table.th tbody tr:nth-child(1)") do
+ find("td:nth-child(3) a").click
+ end
+ wait_until { find("table.h tr:first").text =~ /#{subject}/ }
+
+ body = all("div.msg").last.text
+ block.call(body)
+ end
+ end
+
+ def assert_basic_html_view()
+ visit "http://mail.google.com/?ui=html"
+ find("td#bm b", :text => "basic HTML")
+ end
end
end