I've passed the last 5 hours trying to find a solution that's been bugging me since yesterday. I am writing some BDD tests using behave and selenium to test the product addition functionality of my web app. So to add a product the user have to click on a button which will launch a dialog box containing the form that will allow him to fill in the details of the product he wants to add. When the user clicks on submit the dialog box disappears and a JS code updates a datatables table with the new product using an Ajax request. When I launch my test selenium finds the product addition form and fill in the details I provided, the problem is that when it clicks on submit basically nothing happens, my JS code isn't executed. Here's the behave code that submits the form:
@when(u'I click on Add new product')
def subscribe_click(context):
context.browser.find_element_by_id('add-submit').click()
and what follows is the JS function that really handles the form submission
function submitEditForm(form, upload_data)
{
data_serialized = $(form).serializeArray();
data = {
'csrf_token': data_serialized[0].value,
'name': data_serialized[1].value,
'description': data_serialized[2].value,
'price': data_serialized[3].value,
'image': upload_data.data ? upload_data.data.image : ""
};
$.ajax({
type: "PUT",
url: "/api/products/"+row_data[0],
data: data,
dataType: "json",
success: function(data) {
$("#edit-frm").fadeToggle("fast");
new_data = [
data['name'],
data['description'],
data['price'],
data['image']
]
$('#myTable').dataTable().fnUpdate(data.data, row_index, undefined, 1);
},
error: function (resp) {
$("#edit-frm").fadeToggle("fast");
alertify.alert("There was a problem with your request please try again.")
}
});
}
So what I want to is: is selenium even capable of running Ajax requests? And if that's not the case what do I need to do so that my test works??