Move over another ajax test from selenium to stories.

This commit is contained in:
Luke Melia 2008-06-23 00:36:05 -04:00
parent 6f760c768e
commit adde38eecb
3 changed files with 82 additions and 5 deletions

View file

@ -10,8 +10,13 @@ module Webrat
@selenium.open(url)
end
def fills_in(label_text, options)
@selenium.type("webrat=#{label_text}", "#{options[:with]}")
def fills_in(field_identifier, options)
locator = if field_identifier == :current
"css=:focus"
else
"webrat=#{Regexp.escape(field_identifier)}"
end
@selenium.type(locator, "#{options[:with]}")
end
def response_body
@ -25,11 +30,16 @@ module Webrat
wait_for_result(options[:wait])
end
def clicks_link(link_text, options = {})
def clicks_link(link_text, options = {})
@selenium.click("webratlink=#{link_text}")
wait_for_result(options[:wait])
end
def clicks_link_within(selector, link_text, options = {})
@selenium.click("webratlinkwithin=#{selector}|#{link_text}")
wait_for_result(options[:wait])
end
def wait_for_result(wait_type)
if wait_type == :ajax
wait_for_ajax
@ -55,8 +65,8 @@ module Webrat
def wait_for_ajax_and_effects
wait_for_ajax
wait_for_effects
end
end
def selects(option_text, options = {})
id_or_name_or_label = options[:from]
@ -130,6 +140,24 @@ module Webrat
return candidateLinks.first();
JS
@selenium.add_location_strategy('webratlinkwithin', <<-JS)
var locatorParts = locator.split('|');
var cssAncestor = locatorParts[0];
var linkText = locatorParts[1];
var matchingElements = cssQuery(cssAncestor, inDocument);
var candidateLinks = matchingElements.collect(function(ancestor){
var links = ancestor.getElementsByTagName('a');
return $A(links).select(function(candidateLink) {
return PatternMatcher.matches(linkText, getText(candidateLink));
});
}).flatten().compact();
if (candidateLinks.length == 0) {
return null;
}
candidateLinks = candidateLinks.sortBy(function(s) { return s.length * -1; }); //reverse length sort
return candidateLinks.first();
JS
@selenium.add_location_strategy('webratselectwithoption', <<-JS)
var optionElements = inDocument.getElementsByTagName('option');
var locatedOption = $A(optionElements).find(function(candidate){