From b93e1cd5b55b085cc1e83b382dd388e344c6cfd3 Mon Sep 17 00:00:00 2001 From: Rob Holland Date: Wed, 9 Dec 2009 09:34:42 +0000 Subject: [PATCH] Add drag API (subject to change), fix bug in has_content? --- lib/capybara/dsl.rb | 2 +- lib/capybara/session.rb | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/capybara/dsl.rb b/lib/capybara/dsl.rb index 437ddfb4..21d13e81 100644 --- a/lib/capybara/dsl.rb +++ b/lib/capybara/dsl.rb @@ -47,7 +47,7 @@ module Capybara end SESSION_METHODS = [ - :visit, :body, :click_link, :click_button, :fill_in, :choose, :has_xpath?, :has_css?, + :visit, :body, :click_link, :click_button, :drag, :fill_in, :choose, :has_xpath?, :has_css?, :check, :uncheck, :attach_file, :select, :has_content?, :within, :within_fieldset, :within_table, :save_and_open_page, :find_field, :find_link, :find_button, :field_labeled diff --git a/lib/capybara/session.rb b/lib/capybara/session.rb index 84e84c4b..12015376 100644 --- a/lib/capybara/session.rb +++ b/lib/capybara/session.rb @@ -44,6 +44,14 @@ module Capybara find_button(locator).click end + def drag(source_locator, target_locator) + source = find(source_locator).first + raise Capybara::ElementNotFound, "drag source '#{source_locator}' not found on page" unless source + target = find(target_locator).first + raise Capybara::ElementNotFound, "drag target '#{target_locator}' not found on page" unless target + source.drag_to(target) + end + def fill_in(locator, options={}) find_field(locator, :text_field, :text_area, :password_field).set(options[:with]) end @@ -73,7 +81,7 @@ module Capybara end def has_content?(content) - has_xpath?("//*[contains(.,#{sanitized_xpath_string(content)})]") + has_xpath?("[contains(.,#{sanitized_xpath_string(content)})] | //*[contains(.,#{sanitized_xpath_string(content)})]") end def has_xpath?(path, options={})