1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Merge pull request #1000 from twalpole/readonly

Readonly attribute support for text and textarea elements
This commit is contained in:
Jonas Nicklas 2013-03-10 07:10:16 -07:00
commit 0c5f68998c
4 changed files with 19 additions and 4 deletions

View file

@ -27,7 +27,7 @@ class Capybara::RackTest::Node < Capybara::Driver::Node
elsif input_field?
set_input(value)
elsif textarea?
native.content = value.to_s
native.content = value.to_s unless self[:readonly]
end
end
@ -160,7 +160,7 @@ private
end
native.remove
else
native['value'] = value.to_s
native['value'] = value.to_s unless self[:readonly]
end
end

View file

@ -37,7 +37,8 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
path_names = value.to_s.empty? ? [] : value
native.send_keys(*path_names)
elsif tag_name == 'textarea' or tag_name == 'input'
driver.browser.execute_script "arguments[0].value = ''", native
#script can change a readonly element which user input cannot, so dont execute if readonly
driver.browser.execute_script "arguments[0].value = ''", native unless self[:readonly]
native.send_keys(value.to_s)
end
end

View file

@ -71,6 +71,18 @@ Capybara::SpecHelper.spec "node" do
@session.first('//input').set('')
@session.first('//input').value.should == ''
end
it "should not set if the text field is readonly" do
@session.first('//input[@readonly]').value.should == 'should not change'
@session.first('//input[@readonly]').set('changed')
@session.first('//input[@readonly]').value.should == 'should not change'
end
it "should not set if the textarea is readonly" do
@session.first('//textarea[@readonly]').value.should == 'textarea should not change'
@session.first('//textarea[@readonly]').set('changed')
@session.first('//textarea[@readonly]').value.should == 'textarea should not change'
end
end
describe "#tag_name" do

View file

@ -28,11 +28,13 @@
<p>
<input type="text" id="test_field" value="monkey"/>
<input type="text" readonly="readonly" value="should not change" />
<textarea id="normal">
banana</textarea>
<textarea id="additional_newline">
banana</textarea>
<textarea readonly="readonly">textarea should not change</textarea>
<a href="/redirect_back">BackToMyself</a>
<a title="twas a fine link" href="/redirect">A link came first</a>
<a title="a fine link" href="/with_simple_html">A link</a>