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
|
||||
|
||||
def has_content?(content)
|
||||
has_xpath?("//*[contains(.,#{sanitized_xpath_string(content)})]")
|
||||
has_xpath?(XPath.content(content).to_s)
|
||||
end
|
||||
|
||||
def has_xpath?(path, options={})
|
||||
|
@ -107,13 +107,13 @@ module Capybara
|
|||
end
|
||||
|
||||
def within_fieldset(locator)
|
||||
within "//fieldset[@id='#{locator}' or contains(legend,'#{locator}')]" do
|
||||
within XPath.fieldset(locator).to_s do
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
||||
def within_table(locator)
|
||||
within "//table[@id='#{locator}' or contains(caption,'#{locator}')]" do
|
||||
within XPath.table(locator).to_s do
|
||||
yield
|
||||
end
|
||||
end
|
||||
|
@ -170,27 +170,5 @@ module Capybara
|
|||
def scopes
|
||||
@scopes ||= []
|
||||
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
|
||||
|
|
|
@ -26,33 +26,45 @@ module Capybara
|
|||
def fillable_field(locator)
|
||||
text_field(locator).password_field(locator).text_area(locator)
|
||||
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)
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
def to_s
|
||||
|
@ -60,6 +72,18 @@ module Capybara
|
|||
end
|
||||
|
||||
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)
|
||||
XPath.new(*[@paths, path].flatten)
|
||||
|
|
Loading…
Reference in a new issue