Testing posting to forms in FunkLoad

1.4k Views Asked by At

I am trying to test functionality of a web-application using FunkLoad.

The page under testing is just a login form - give email and pwd and if successful it redirects to a index page; if not successful it throws an error.

I have the below code:

self.get(server_url + "/login", description="Get /init/default/login")
params=[['email', '[email protected]'],
        ['password', 'xxxxx'],
        ['_formname','login'],
        ]
ret=self.post('%s/login' % server_url,
          params=params,
          description="Testing login functionality")

self.logd(self.getBody())

Whether it is a valid email id/pwd or a wrong one, the test throws a 200 as a return code and stays in the same login page.

How do I test posting in forms using FunkLoad?

(BTW, when I tested this web page with a mechanize script, I could login and then routed to the correct index page)

Thank you

1

There are 1 best solutions below

1
On

Setup the funkload proxy recorder and login into your site using your browser as described in the funkload docs: http://funkload.nuxeo.org/recorder.html

Then you easily check exactly what you are sending via POST. You might be sending other params as you think. In the following example, I am testing a django login that uses the crsfmiddleware, and also has a redirect_to param so the server knows where to redirect to if the login was successful. The test doesn't really use the form, it just sends what the browser would send if someone did. If you want to test real form functionality, the best way is to use something like selenium.

I had to add to extract the crsftoken manually as it changes with every request, and an assert to check that it doesn't return to a login page, but besides that, this test is just like the recorder autogenerated for me:

def test_LoginTest(self):
    # The description should be set in the configuration file
    server_url = self.server_url
    # begin of test ---------------------------------------------

    # /tmp/tmpMFahey_funkload/watch0001.request
    self.get(server_url + "/",
        description="Get /")
    # /tmp/tmpMFahey_funkload/watch0002.request
    reply = self.get(server_url + "/company/config/dashboard/",
        description="Get /company/config/dashboard/")

    csrftoken = extract_token(self.getBody(), "name='csrfmiddlewaretoken' value='", "' />")
    # /tmp/tmpMFahey_funkload/watch0005.request
    self.post(server_url + "/accounts/manager/login/?next=/company/config/dashboard/", params=[
        ['csrfmiddlewaretoken', csrftoken],
        ['redirect_to', '/company/config/dashboard/'],
        ['email', 'user'],
        ['password', '****']],
        description="Post /accounts/manager/login/")

    self.assert_("login" not in self.getLastUrl(), "Error in login")

    # /tmp/tmpMFahey_funkload/watch0008.request
    self.get(server_url + "/accounts/manager/logout/",
        description="Get /accounts/manager/logout/")

This works for the following form:

<form method="post" action="">
<input type='hidden' name='csrfmiddlewaretoken' value='bb7d67ced4a2c6ee44eba811d44c936d' />
<input type="hidden" name="redirect_to" value="/company/config/dashboard/" id="id_redirect_to" />
<input id="id_email" type="text" class="formtxt fom_size1" name="email" maxlength="100" />
<input id="id_password" type="password" class="formtxt fom_size1" name="password" />
<button class="formbtn" type="submit">Validate</button>