Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 50 lines (44 sloc) 1.718 kb
ba28a2a @jferris Fix focus/blur event compatibility with Selenium while filling out forms
jferris authored
1 require 'spec_helper'
2
3 describe Capybara::Webkit, 'compatibility with selenium' do
4 include AppRunner
5
6 it 'generates the same events as selenium when filling out forms' do
7 run_application_for_html(<<-HTML)
8 <html><body>
9 <form onsubmit="return false">
10 <label for="one">One</label><input type="text" name="one" id="one" />
11 <label for="two">Two</label><input type="text" name="two" id="two" />
12 <input type="submit" value="Submit" id="submit" />
13 </form>
14 <script type="text/javascript">
15 window.log = [];
16 var recordEvent = function (event) {
17 log.push(event.target.id + '.' + event.type);
18 };
19 var elements = document.getElementsByTagName("input");
20 var events = ["mousedown", "mouseup", "click", "keyup", "keydown",
21 "keypress", "focus", "blur"];
22 for (var i = 0; i < elements.length; i++) {
23 for (var j = 0; j < events.length; j++) {
24 elements[i].addEventListener(events[j], recordEvent);
25 }
26 }
27 </script>
28 </body></html>
29 HTML
30
31 compare_events_for_drivers(:reusable_webkit, :selenium) do
32 visit "/"
33 fill_in "One", :with => "some value"
a4eb401 @jferris Improve focus handling by relying on Javascript focus()
jferris authored
34 fill_in "One", :with => "a new value"
ba28a2a @jferris Fix focus/blur event compatibility with Selenium while filling out forms
jferris authored
35 fill_in "Two", :with => "other value"
36 click_button "Submit"
37 end
38 end
39
40 def compare_events_for_drivers(first, second, &block)
41 events_for_driver(first, &block).should == events_for_driver(second, &block)
42 end
43
44 def events_for_driver(name, &block)
45 session = Capybara::Session.new(name, AppRunner.app)
46 session.instance_eval(&block)
47 session.evaluate_script("window.log")
48 end
49 end
Something went wrong with that request. Please try again.