mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
Move fieldset, table and content into xpath class
This commit is contained in:
parent
8d44e8cb74
commit
39081f3c7d
2 changed files with 34 additions and 32 deletions
|
@ -78,7 +78,7 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_content?(content)
|
def has_content?(content)
|
||||||
has_xpath?("//*[contains(.,#{sanitized_xpath_string(content)})]")
|
has_xpath?(XPath.content(content).to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_xpath?(path, options={})
|
def has_xpath?(path, options={})
|
||||||
|
@ -107,13 +107,13 @@ module Capybara
|
||||||
end
|
end
|
||||||
|
|
||||||
def within_fieldset(locator)
|
def within_fieldset(locator)
|
||||||
within "//fieldset[@id='#{locator}' or contains(legend,'#{locator}')]" do
|
within XPath.fieldset(locator).to_s do
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def within_table(locator)
|
def within_table(locator)
|
||||||
within "//table[@id='#{locator}' or contains(caption,'#{locator}')]" do
|
within XPath.table(locator).to_s do
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -170,27 +170,5 @@ module Capybara
|
||||||
def scopes
|
def scopes
|
||||||
@scopes ||= []
|
@scopes ||= []
|
||||||
end
|
end
|
||||||
|
|
||||||
def sanitized_xpath_string(string)
|
|
||||||
if string.include?("'")
|
|
||||||
string = string.split("'", -1).map do |substr|
|
|
||||||
"'#{substr}'"
|
|
||||||
end.join(%q{,"'",})
|
|
||||||
"concat(#{string})"
|
|
||||||
else
|
|
||||||
"'#{string}'"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def sanitized_xpath_string(string)
|
|
||||||
if string.include?("'")
|
|
||||||
string = string.split("'", -1).map do |substr|
|
|
||||||
"'#{substr}'"
|
|
||||||
end.join(%q{,"'",})
|
|
||||||
"concat(#{string})"
|
|
||||||
else
|
|
||||||
"'#{string}'"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,32 +27,44 @@ module Capybara
|
||||||
text_field(locator).password_field(locator).text_area(locator)
|
text_field(locator).password_field(locator).text_area(locator)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def content(locator)
|
||||||
|
append("//*[contains(.,#{s(locator)})]")
|
||||||
|
end
|
||||||
|
|
||||||
|
def table(locator)
|
||||||
|
append("//table[@id=#{s(locator)} or contains(caption,#{s(locator)})]")
|
||||||
|
end
|
||||||
|
|
||||||
|
def fieldset(locator)
|
||||||
|
append("//fieldset[@id=#{s(locator)} or contains(legend,#{s(locator)})]")
|
||||||
|
end
|
||||||
|
|
||||||
def text_field(locator)
|
def text_field(locator)
|
||||||
append("//input[@type='text'][@id='#{locator}' or @id=//label[contains(.,'#{locator}')]/@for]")
|
append("//input[@type='text'][@id=#{s(locator)} or @id=//label[contains(.,#{s(locator)})]/@for]")
|
||||||
end
|
end
|
||||||
|
|
||||||
def password_field(locator)
|
def password_field(locator)
|
||||||
append("//input[@type='password'][@id='#{locator}' or @id=//label[contains(.,'#{locator}')]/@for]")
|
append("//input[@type='password'][@id=#{s(locator)} or @id=//label[contains(.,#{s(locator)})]/@for]")
|
||||||
end
|
end
|
||||||
|
|
||||||
def text_area(locator)
|
def text_area(locator)
|
||||||
append("//textarea[@id='#{locator}' or @id=//label[contains(.,'#{locator}')]/@for]")
|
append("//textarea[@id=#{s(locator)} or @id=//label[contains(.,#{s(locator)})]/@for]")
|
||||||
end
|
end
|
||||||
|
|
||||||
def radio_button(locator)
|
def radio_button(locator)
|
||||||
append("//input[@type='radio'][@id='#{locator}' or @id=//label[contains(.,'#{locator}')]/@for]")
|
append("//input[@type='radio'][@id=#{s(locator)} or @id=//label[contains(.,#{s(locator)})]/@for]")
|
||||||
end
|
end
|
||||||
|
|
||||||
def checkbox(locator)
|
def checkbox(locator)
|
||||||
append("//input[@type='checkbox'][@id='#{locator}' or @id=//label[contains(.,'#{locator}')]/@for]")
|
append("//input[@type='checkbox'][@id=#{s(locator)} or @id=//label[contains(.,#{s(locator)})]/@for]")
|
||||||
end
|
end
|
||||||
|
|
||||||
def select(locator)
|
def select(locator)
|
||||||
append("//select[@id='#{locator}' or @id=//label[contains(.,'#{locator}')]/@for]")
|
append("//select[@id=#{s(locator)} or @id=//label[contains(.,#{s(locator)})]/@for]")
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_field(locator)
|
def file_field(locator)
|
||||||
append("//input[@type='file'][@id='#{locator}' or @id=//label[contains(.,'#{locator}')]/@for]")
|
append("//input[@type='file'][@id=#{s(locator)} or @id=//label[contains(.,#{s(locator)})]/@for]")
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
@ -61,6 +73,18 @@ module Capybara
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
# Sanitize a String for putting it into an xpath query
|
||||||
|
def s(string)
|
||||||
|
if string.include?("'")
|
||||||
|
string = string.split("'", -1).map do |substr|
|
||||||
|
"'#{substr}'"
|
||||||
|
end.join(%q{,"'",})
|
||||||
|
"concat(#{string})"
|
||||||
|
else
|
||||||
|
"'#{string}'"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def append(path)
|
def append(path)
|
||||||
XPath.new(*[@paths, path].flatten)
|
XPath.new(*[@paths, path].flatten)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue