readonly support for :field selector (find_field) = Issue #1385
This commit is contained in:
parent
2eb8d31a17
commit
cc407e2fc5
|
@ -54,9 +54,10 @@ module Capybara
|
|||
#
|
||||
# @param [String] locator Which field to find
|
||||
#
|
||||
# @option options [Boolean] checked Only match checked field?
|
||||
# @option options [Boolean] unchecked Only match unchecked field?
|
||||
# @option options [Boolean] disabled (false) Only match disabled field?
|
||||
# @option options [Boolean] checked Match checked field?
|
||||
# @option options [Boolean] unchecked Match unchecked field?
|
||||
# @option options [Boolean] disabled (false) Match disabled field?
|
||||
# @option options [Boolean] readonly Match readonly field?
|
||||
# @option options [String] with Value of field to match on
|
||||
# @option options [String] type Type of field to match on
|
||||
# @return [Capybara::Node::Element] The found element
|
||||
|
@ -87,7 +88,7 @@ module Capybara
|
|||
# @macro waiting_behavior
|
||||
#
|
||||
# @param [String] locator Which button to find
|
||||
# @option options [Boolean] disabled (false) Only match disabled button?
|
||||
# @option options [Boolean] disabled (false) Match disabled button?
|
||||
# @return [Capybara::Node::Element] The found element
|
||||
#
|
||||
def find_button(locator, options={})
|
||||
|
|
|
@ -116,6 +116,7 @@ Capybara.add_selector(:field) do
|
|||
filter(:checked, boolean: true) { |node, value| not(value ^ node.checked?) }
|
||||
filter(:unchecked, boolean: true) { |node, value| (value ^ node.checked?) }
|
||||
filter(:disabled, default: false, boolean: true) { |node, value| not(value ^ node.disabled?) }
|
||||
filter(:readonly, boolean: true) { |node, value| not(value ^ node[:readonly]) }
|
||||
filter(:with) { |node, with| node.value == with.to_s }
|
||||
filter(:type) do |node, type|
|
||||
if ['textarea', 'select'].include?(type)
|
||||
|
@ -149,7 +150,7 @@ end
|
|||
|
||||
Capybara.add_selector(:link) do
|
||||
xpath { |locator| XPath::HTML.link(locator) }
|
||||
filter(:href) do |node, href|
|
||||
filter(:href) do |node, href|
|
||||
if href.is_a? Regexp
|
||||
node[:href].match href
|
||||
else
|
||||
|
|
|
@ -35,7 +35,7 @@ Capybara::SpecHelper.spec '#assert_current_path' do
|
|||
end
|
||||
end
|
||||
|
||||
Capybara::SpecHelper.spec '#assert_no_current_path?', focus: true do
|
||||
Capybara::SpecHelper.spec '#assert_no_current_path?' do
|
||||
before do
|
||||
@session.visit('/with_js')
|
||||
end
|
||||
|
|
|
@ -61,4 +61,21 @@ Capybara::SpecHelper.spec '#find_field' do
|
|||
end.to raise_error(Capybara::ElementNotFound)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'with :readonly option' do
|
||||
it "should find readonly fields when true" do
|
||||
expect(@session.find_field('form[readonly_test]', readonly: true)[:id]).to eq 'readonly'
|
||||
end
|
||||
|
||||
it "should not find readonly fields when false" do
|
||||
expect(@session.find_field('form[readonly_test]', readonly: false)[:id]).to eq 'not_readonly'
|
||||
end
|
||||
|
||||
it "should ignore readonly by default" do
|
||||
expect do
|
||||
@session.find_field('form[readonly_test]')
|
||||
end.to raise_error(Capybara::Ambiguous, /found 2 elements/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -161,7 +161,7 @@ New line after and before textarea tag
|
|||
<input type="checkbox" value="hamster" name="form[pets][]" id="form_pets_hamster" checked="checked"/>
|
||||
<label for="form_pets_hamster">Hamster</label>
|
||||
</p>
|
||||
|
||||
|
||||
<p>
|
||||
<input type="checkbox" name="form[valueless_checkbox]" id="valueless_checkbox" checked="checked"/>
|
||||
<label for="valueless_checkbox">Valueless Checkbox</label>
|
||||
|
@ -289,6 +289,11 @@ New line after and before textarea tag
|
|||
<button id="no_type">No Type!</button>
|
||||
<input type="button" disabled="disabled" value="Disabled button"/>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<input id="readonly" name="form[readonly_test]" readonly/>
|
||||
<input id="not_readonly" name="form[readonly_test]" />
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<input type="text" name="form[outside_input]" value="outside_input" form="form1"/>
|
||||
|
|
Loading…
Reference in New Issue