在 FunkLoad 中测试发布到表单

发布于 2024-12-11 10:44:48 字数 760 浏览 0 评论 0原文

我正在尝试使用 FunkLoad 测试 Web 应用程序的功能。

正在测试的页面只是一个登录表单 - 提供电子邮件和密码,如果成功,它会重定向到索引页面;如果不成功,则会抛出错误。

我有以下代码:

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())

无论是有效的电子邮件 ID/密码还是错误的电子邮件 ID/密码,测试都会抛出 200 作为返回代码并保留在同一登录页面中。

如何使用 FunkLoad 测试表单中的发布?

(顺便说一句,当我使用 mechanize 脚本测试此网页时,我可以登录然后路由到正确的索引页面)

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挖个坑埋了你 2024-12-18 10:44:48

设置 funkload 代理记录器并使用浏览器登录您的站点,如 funkload 文档中所述: http://funkload .nu​​xeo.org/recorder.html

然后您可以轻松检查通过 POST 发送的内容。您可能会按照您的想法发送其他参数。在下面的示例中,我正在测试使用 crsfmiddleware 的 django 登录,并且还有一个 redirect_to 参数,以便服务器知道登录成功后重定向到哪里。该测试并不真正使用表单,它只是发送浏览器在有人这样做时会发送的内容。如果你想测试真实的表单功能,最好的方法是使用像 selenium 这样的东西。

我必须添加手动提取 crsftoken,因为它会随每个请求而变化,并添加一个断言来检查它是否返回到登录页面,但除此之外,此测试就像为我自动生成的记录器一样:

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/")

这适用于以下形式:

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文