lib/prickle/capybara.rb in prickle-0.0.3 vs lib/prickle/capybara.rb in prickle-0.0.4

- old
+ new

@@ -1,16 +1,18 @@ require_relative 'capybara/element' +require_relative 'exceptions' +require_relative 'core_ext/symbol' module Prickle module Capybara class << self attr_accessor :wait_time, :image_dir end - def capture_screen name=Time.now.strftime("%Y%m%d-%H.%M.%s") + def capture_screen name=screenshot_name page.driver.browser.save_screenshot Capybara.image_dir + name + ".jpg" end def click_by_name name find_by_name(name).click @@ -35,15 +37,17 @@ def popup_message page.driver.browser.switch_to.alert.text end def popup_message_contains? message - raise Capybara::MessageNotContainedInPopup, Error.new.not_contained_in_popup(message) unless popup_message.eql? message + raise Exceptions::MessageNotContainedInPopup.new(message) unless popup_message.eql? message end private + TIME_FORMATTER = "%Y%m%d-%H.%M.%s" + def method_missing method, *args if method =~ /(^.*)_contains_text\?$/ element($1, :name => args.first).contains_text? args[1] elsif method =~ /^click_(.*)_by_name$/ element($1, :name => args.first).click @@ -52,7 +56,12 @@ else super end end + def screenshot_name + Time.now.strftime(TIME_FORMATTER) + end + end + end