0

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??

Codejunky
  • 632
  • 1
  • 6
  • 15
  • In fact Selenium doesn't care if it's ajax or anything else. Can you show the HTML example of the button that is submitting that request? – Stan E Apr 07 '15 at 09:56
  • Yes of course here it is: – Codejunky Apr 07 '15 at 10:07
  • So, why do you think it's not submitted? Have you tried waiting the response? If the overall test is like above, it will not wait for anything and will close the browser (the browser will have no time for processing thee request) – Stan E Apr 07 '15 at 10:11
  • Yes @Stanjer I tried waiting for it for about 30 seconds but that doesn't work either – Codejunky Apr 07 '15 at 10:12
  • Then not sure about the problem. probably providing the whole test will make anything more clear. – Stan E Apr 07 '15 at 10:15
  • Well here is a link to a past bin containing the whole test http://pastebin.com/cXXRe5XG I'll appreciate it if you can find what I am missing – Codejunky Apr 07 '15 at 10:18

0 Answers0