2012-07-09 20:34:09 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Capybara::Webkit, 'compatibility with selenium' do
|
|
|
|
include AppRunner
|
|
|
|
|
2014-07-08 23:55:06 -04:00
|
|
|
it 'generates the same events as selenium when filling out forms', selenium_compatibility: true do
|
2012-07-09 20:34:09 -04:00
|
|
|
run_application_for_html(<<-HTML)
|
|
|
|
<html><body>
|
|
|
|
<form onsubmit="return false">
|
|
|
|
<label for="one">One</label><input type="text" name="one" id="one" />
|
|
|
|
<label for="two">Two</label><input type="text" name="two" id="two" />
|
2013-03-20 23:54:39 -04:00
|
|
|
<label for="three">Three</label><input type="text" name="three" id="three" readonly="readonly" />
|
2014-06-18 18:00:34 -04:00
|
|
|
<label for="textarea">Textarea</label>
|
|
|
|
<textarea name="textarea" id="textarea"></textarea>
|
2012-07-09 20:34:09 -04:00
|
|
|
<input type="submit" value="Submit" id="submit" />
|
|
|
|
</form>
|
|
|
|
<script type="text/javascript">
|
|
|
|
window.log = [];
|
|
|
|
var recordEvent = function (event) {
|
|
|
|
log.push(event.target.id + '.' + event.type);
|
|
|
|
};
|
|
|
|
var elements = document.getElementsByTagName("input");
|
|
|
|
var events = ["mousedown", "mouseup", "click", "keyup", "keydown",
|
2013-03-20 23:20:14 -04:00
|
|
|
"keypress", "focus", "blur", "input", "change"];
|
2012-07-09 20:34:09 -04:00
|
|
|
for (var i = 0; i < elements.length; i++) {
|
|
|
|
for (var j = 0; j < events.length; j++) {
|
|
|
|
elements[i].addEventListener(events[j], recordEvent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</body></html>
|
|
|
|
HTML
|
|
|
|
|
|
|
|
compare_events_for_drivers(:reusable_webkit, :selenium) do
|
|
|
|
visit "/"
|
|
|
|
fill_in "One", :with => "some value"
|
2012-07-10 23:53:57 -04:00
|
|
|
fill_in "One", :with => "a new value"
|
2012-07-09 20:34:09 -04:00
|
|
|
fill_in "Two", :with => "other value"
|
2013-03-20 23:54:39 -04:00
|
|
|
fill_in "Three", :with => "readonly value"
|
2014-06-18 18:00:34 -04:00
|
|
|
fill_in "Textarea", :with => "last value"
|
2012-07-09 20:34:09 -04:00
|
|
|
click_button "Submit"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def compare_events_for_drivers(first, second, &block)
|
|
|
|
events_for_driver(first, &block).should == events_for_driver(second, &block)
|
|
|
|
end
|
|
|
|
|
|
|
|
def events_for_driver(name, &block)
|
|
|
|
session = Capybara::Session.new(name, AppRunner.app)
|
|
|
|
session.instance_eval(&block)
|
|
|
|
session.evaluate_script("window.log")
|
|
|
|
end
|
|
|
|
end
|