I get the following error when I run bundle exec rspec
for my feature test for a form:
Failure/Error: select('Boston Commons - Vacation English', :from => 'school_application_program')
Capybara::ElementNotFound:
Unable to find option "Boston Commons - Vacation English"
Here is the snippet of my scenario from my feature spec:
select('Boston Commons', :from => 'school_application_fls_center')
select('Boston Commons - Vacation English', :from => 'school_application_program')
The second line fails.
In my development environment I visit the same route that the scenario visits,
perform the previous selection, and then confirm that school_application_program
is the id of the <select>
tag and that the option name is the exact same as the one I am checking.
My only guess, is that for some reason, my javascript onchange
function is not properly populating the <select>
tag, but that doesn't make a whole lot of sense given that the feature spec should mirror the development environment exactly.
The onchange event is being bound to the <select>
tag immediately preceding school_application_program
and resets the options for school_application_program
Here is the javascript that populated my school_application_program
<select>
$("#school_application_fls_center").change(function(){
var center_id = document.getElementById("school_application_fls_center").value;
var formdata = {center: center_id};
$.ajax({
url: "/application/get_programs_for_center",
type: "POST",
datatype: 'json',
data: formdata,
success: function(response){
var options = $("#school_application_program");
removeOptions(document.getElementById("school_application_program"));
$.each(response.programs, function(i,item) {
options.append($("<option />").val(response.programs[i].id).text(response.programs[i].name));
});
}
});
});
This is a shot from my development environment, showing the form, after I have done the behavior that the spec does manually, at the point where the test fails.
All that was required was to enable Javascript via adding the
:js => true
flag when thescenario
was defined, like so: