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

Merge pull request #948 from benlovell/add_element_disabled

Add element disabled?
This commit is contained in:
Jonas Nicklas 2013-02-15 13:32:31 -08:00
commit f17b37bdba
8 changed files with 62 additions and 2 deletions

View file

@ -57,6 +57,10 @@ module Capybara
raise NotImplementedError
end
def disabled?
raise NotImplementedError
end
def path
raise NotSupportedByDriverError
end

View file

@ -142,6 +142,16 @@ module Capybara
synchronize { base.selected? }
end
##
#
# Whether or not the element is disabled.
#
# @return [Boolean] Whether the element is disabled
#
def disabled?
synchronize { base.disabled? }
end
##
#
# An XPath expression describing where on the page the element can be found

View file

@ -108,6 +108,15 @@ module Capybara
native[:checked]
end
##
#
# Whether or not the element is disabled.
#
# @return [Boolean] Whether the element is disabled
def disabled?
native[:disabled]
end
##
#
# Whether or not the element is selected.

View file

@ -68,6 +68,10 @@ class Capybara::RackTest::Node < Capybara::Driver::Node
string_node.selected?
end
def disabled?
string_node.disabled?
end
def path
native.path
end

View file

@ -70,6 +70,10 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
selected and selected != "false"
end
def disabled?
!native.enabled?
end
alias :checked? :selected?
def find(locator)

View file

@ -81,6 +81,14 @@ Capybara::SpecHelper.spec "node" do
end
end
describe "#disabled?" do
it "should extract disabled node" do
@session.visit('/form')
@session.find('//input[@id="customer_name"]').should be_disabled
@session.find('//input[@id="customer_email"]').should_not be_disabled
end
end
describe "#visible?" do
it "should extract node visibility" do
@session.first('//a').should be_visible

View file

@ -9,8 +9,19 @@
<option>Mr</option>
<option>Miss</option>
</select>
</p>
<p>
<label for="customer_name">Customer Name
<input type="text" name="form[customer_name]" value="Blah" id="customer_name" disabled="disabled"/>
</label>
</p>
<p>
<label for="customer_email">Customer Email
<input type="text" name="form[customer_email]" value="ben@ben.com" id="customer_email"/>
</label>
</p>
<p>
<label for="form_other_title">Other title</label>

View file

@ -10,6 +10,11 @@ describe Capybara do
<p>Yes it is</p>
</div>
<form>
<input type="text" name="bleh" disabled="disabled"/>
<input type="text" name="meh"/>
</form>
<div id="footer" style="display: none">
<p>c2010</p>
<p>Jonas Nicklas</p>
@ -77,13 +82,18 @@ describe Capybara do
end
it "allows finding elements and extracting the path" do
string.find('//input').value.should == 'bar'
string.find('//div/input').value.should == 'bar'
string.find('//select').value.should == 'Capybara'
end
it "allows finding elements and checking if they are visible" do
string.find('//h1').should be_visible
string.find('//input').should_not be_visible
string.find('//div/input').should_not be_visible
end
it "allows finding elements and checking if they are disabled" do
string.find('//form/input[@name="bleh"]').should be_disabled
string.find('//form/input[@name="meh"]').should_not be_disabled
end
end
end