public
Description: Webrat - Ruby Acceptance Testing for Web applications
Homepage: http://www.brynary.com/uploads/webrat/rdoc/index.html
Clone URL: git://github.com/brynary/webrat.git
Implemented clicks_link_within for selenium session.
lukemelia (author)
Sun Jun 22 21:37:31 -0700 2008
commit  cfdd66784e2f963eb8c6f1e6a0c597c4744f2646
tree    b105038ad620c65ad7ea868114240852123c55bf
parent  6074ec3e3514687ebc30e55ee443f0bb138fad85
...
10
11
12
13
14
 
 
 
15
16
17
...
29
30
31
 
 
 
 
 
32
33
34
...
130
131
132
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
134
135
...
10
11
12
 
 
13
14
15
16
17
18
...
30
31
32
33
34
35
36
37
38
39
40
...
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
0
@@ -10,8 +10,9 @@ module Webrat
0
       @selenium.open(url)
0
     end
0
     
0
- def fills_in(label_text, options)
0
- @selenium.type("webrat=#{Regexp.escape(label_text)}", "#{options[:with]}")
0
+ def fills_in(field_identifier, options)
0
+ locator = "webrat=#{Regexp.escape(field_identifier)}"
0
+ @selenium.type(locator, "#{options[:with]}")
0
     end
0
     
0
     def response_body
0
@@ -29,6 +30,11 @@ module Webrat
0
       @selenium.click("webratlink=#{link_text}")
0
       wait_for_result(options[:wait])
0
     end
0
+
0
+ def clicks_link_within(selector, link_text, options = {})
0
+ @selenium.click("webratlinkwithin=#{selector}|#{link_text}")
0
+ wait_for_result(options[:wait])
0
+ end
0
 
0
     def wait_for_result(wait_type)
0
       if wait_type == :ajax
0
@@ -130,6 +136,24 @@ module Webrat
0
         return candidateLinks.first();
0
       JS
0
       
0
+ @selenium.add_location_strategy('webratlinkwithin', <<-JS)
0
+ var locatorParts = locator.split('|');
0
+ var cssAncestor = locatorParts[0];
0
+ var linkText = locatorParts[1];
0
+ var matchingElements = cssQuery(cssAncestor, inDocument);
0
+ var candidateLinks = matchingElements.collect(function(ancestor){
0
+ var links = ancestor.getElementsByTagName('a');
0
+ return $A(links).select(function(candidateLink) {
0
+ return PatternMatcher.matches(linkText, getText(candidateLink));
0
+ });
0
+ }).flatten().compact();
0
+ if (candidateLinks.length == 0) {
0
+ return null;
0
+ }
0
+ candidateLinks = candidateLinks.sortBy(function(s) { return s.length * -1; }); //reverse length sort
0
+ return candidateLinks.first();
0
+ JS
0
+
0
       @selenium.add_location_strategy('webratselectwithoption', <<-JS)
0
         var optionElements = inDocument.getElementsByTagName('option');
0
         var locatedOption = $A(optionElements).find(function(candidate){

Comments

    No one has commented yet.