mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Fix and specs for find_by_id; Moved DSL_METHODS to session where they are added.
This commit is contained in:
parent
741c153cb4
commit
2722b4257d
5 changed files with 31 additions and 10 deletions
|
@ -46,15 +46,8 @@ module Capybara
|
||||||
Capybara.current_session
|
Capybara.current_session
|
||||||
end
|
end
|
||||||
|
|
||||||
SESSION_METHODS = [
|
|
||||||
:visit, :current_url, :body, :click_link, :click_button, :drag, :fill_in,
|
Session::DSL_METHODS.each do |method|
|
||||||
:choose, :has_xpath?, :has_css?, :check, :uncheck, :attach_file, :select,
|
|
||||||
:has_content?, :within, :within_fieldset, :within_table,
|
|
||||||
:save_and_open_page, :find, :find_field, :find_link, :find_button,
|
|
||||||
:field_labeled, :all, :wait_for, :wait_for_condition, :evaluate_script,
|
|
||||||
:click, :wait_until
|
|
||||||
]
|
|
||||||
SESSION_METHODS.each do |method|
|
|
||||||
class_eval <<-RUBY, __FILE__, __LINE__+1
|
class_eval <<-RUBY, __FILE__, __LINE__+1
|
||||||
def #{method}(*args, &block)
|
def #{method}(*args, &block)
|
||||||
page.#{method}(*args, &block)
|
page.#{method}(*args, &block)
|
||||||
|
|
|
@ -36,7 +36,7 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_by_id(id)
|
def find_by_id(id)
|
||||||
find(Xpath.for_css("##{id}"))
|
find(XPath.for_css("##{id}"))
|
||||||
end
|
end
|
||||||
|
|
||||||
def all(locator, options = {})
|
def all(locator, options = {})
|
||||||
|
|
|
@ -2,6 +2,15 @@ module Capybara
|
||||||
class Session
|
class Session
|
||||||
include Searchable
|
include Searchable
|
||||||
|
|
||||||
|
DSL_METHODS = [
|
||||||
|
:visit, :current_url, :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, :find_field, :find_link, :find_button, :find_by_id,
|
||||||
|
:field_labeled, :all, :wait_for, :wait_for_condition, :evaluate_script,
|
||||||
|
:click, :wait_until
|
||||||
|
]
|
||||||
|
|
||||||
attr_reader :mode, :app
|
attr_reader :mode, :app
|
||||||
|
|
||||||
def initialize(mode, app)
|
def initialize(mode, app)
|
||||||
|
|
18
spec/dsl/find_by_id_spec.rb
Normal file
18
spec/dsl/find_by_id_spec.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
module FindByIdSpec
|
||||||
|
shared_examples_for "find_by_id" do
|
||||||
|
describe '#find_by_id' do
|
||||||
|
before do
|
||||||
|
@session.visit('/with_html')
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should find any element by id" do
|
||||||
|
@session.find_by_id('red').tag_name.should == 'a'
|
||||||
|
@session.find_by_id('hidden_via_ancestor').tag_name.should == 'div'
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return nil if no element with id is found" do
|
||||||
|
@session.find_by_id('nothing_with_this_id').should be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -32,6 +32,7 @@ shared_examples_for "session" do
|
||||||
it_should_behave_like "find_button"
|
it_should_behave_like "find_button"
|
||||||
it_should_behave_like "find_field"
|
it_should_behave_like "find_field"
|
||||||
it_should_behave_like "find_link"
|
it_should_behave_like "find_link"
|
||||||
|
it_should_behave_like "find_by_id"
|
||||||
it_should_behave_like "find"
|
it_should_behave_like "find"
|
||||||
it_should_behave_like "has_content"
|
it_should_behave_like "has_content"
|
||||||
it_should_behave_like "has_css"
|
it_should_behave_like "has_css"
|
||||||
|
|
Loading…
Add table
Reference in a new issue