
webratlink locator for selenium does not find links by id or name
Reported by dstar | April 17th, 2009 @ 12:17 PM
The webratlink locator for selenium only finds links by text, which means that the click_link API differs for selenium and non-selenium tests. The following patch finds links by ID as well, and adding name support should be trivial.
This may not be the best solution (it might be better to not add the evalregexp: prefix in adjust_if_regexp (and remove the leading and trailing slashes if it is a regexp) and instead have the first argument to PatternMatcher.matches be 'evalregexp:/'+locator+'/', so that the lastIndexOf and substring calls aren't needed), but it was good enough to allow my tests to work, which was all I needed.
diff --git
a/lib/webrat/selenium/location_strategy_javascript/webratlink.js
b/lib/webrat/selenium/location_strategy_javascript/web
index ad71957..4578291 100644
---
a/lib/webrat/selenium/location_strategy_javascript/webratlink.js
+++
b/lib/webrat/selenium/location_strategy_javascript/webratlink.js @@
-3,7 +3,14 @@ var candidateLinks =
$A(links).select(function(candidateLink) { return
PatternMatcher.matches(locator, getText(candidateLink)); }); if
(candidateLinks.length == 0) { - return null; + var
last_char_of_locator = locator.lastIndexOf('/'); + var locator_id =
locator.substring(11,last_char_of_locator); + var
candidate_link_by_id = inDocument.getElementById(locator_id); + if
(candidate_link_by_id == null) { + return null; + } else { + return
candidate_link_by_id; + } } candidateLinks =
candidateLinks.sortBy(function(s) { return s.length * -1; });
//reverse length sort return candidateLinks.first();
Comments and changes to this ticket
-
gaffo April 22nd, 2009 @ 01:02 PM
- Tag changed from patch, selenium to patch, selenium, verify
- State changed from new to awaiting-patch
dstar, could you attach the patch as an actual file, pasting it in corrupts it.
-
Larry Diehl May 29th, 2009 @ 03:19 PM
I added a fix for this with tests too, see the the comments here:
https://webrat.lighthouseapp.com/projects/10503/tickets/254-unify-c... -
Bryan Helmkamp June 1st, 2009 @ 01:02 PM
- State changed from awaiting-patch to resolved
(from [b6d26480ea424b2c6dd26105b030bb77be33861f]) [#221 state:resolved] added attribution http://github.com/brynary/webrat/commit/b6d26480ea424b2c6dd26105b03...
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Ruby Acceptance Testing for Web applications.
People watching this ticket
Attachments
Referenced by
-
221 webratlink locator for selenium does not find links by id or name (from [b6d26480ea424b2c6dd26105b030bb77be33861f]) [#221 s...