The tools being used:
- Cucumber
- Capybara
- selenium-webdriver
- Firefox
- OS/X or Unix
We have a web application with some javascript that has onChange event handlers. One example is entering a date in a text field (overlayed with a date picker widget). When the field changes, the form is automatically submitted through AJAX and the results list is filtered using that date.
Unfortunately, for now (?) and perhaps only when driving Firefox, selenium-webdriver (aka Selenium 2) doesn’t fire the onChange event when you enter some text into a field. You need to leave the field (blur) for the onChange event to fire. Blah.
As an aside, Simon Stewart let me know that Firefox fires the event if the window is active. Alas, this is a) not reliable (I have seen it work and fail), and b) not achievable in an automated parallel test run where multiple browsers are hammering away (we also wisely use Sandro’s awesome specjour).
Fortunately, we are using a date picker widget. To simulate the behaviour in a way that is pretty much what the user would usually do, we click the field (letting the date picker widget get activated), fill in the date with the value we want to testwith (date picker uses key events to jump to the right month in the calendar), and then we click the day link in the date picker.
The user doesn’t “click” or “tab” anywhere else. They just type the date, or click it in the date picker widget. They remain on the date field and the form auto-submits. You may find this annoying and a silly thing to do. I may agree with you. The users of this application do not.
The following code as a step definition for When I pick a "start_date" of "2010-09-21" works great. Events are fired and waiting for readiness is obeyed.
When /^I pick a "([^"]*)" of "([^"]*)"$/ do |field, text|
find_field(field).click
fill_in(field, :with => text) # Make calendar jump to correct month
within(".ui-datepicker-calendar") do
day = text.to_date.day.to_s
click_link(day)
end
end
I have a strong feeling akephalos would be fine, but we happen to be running on Ruby Enterprise Edition on OS/X which is unreliable in the area of inter-process communication with Ruby object marshalling (needed for akephalos to communicate between it’s C Ruby and JRuby components).
I also believe it would be fine on another browser. Possibly also with Firefox on Windows, but then we’d be running Ruby on Windows: frying pan -> fire.