在 FunkLoad 中测试发布到表单
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置 funkload 代理记录器并使用浏览器登录您的站点,如 funkload 文档中所述: http://funkload .nuxeo.org/recorder.html
然后您可以轻松检查通过 POST 发送的内容。您可能会按照您的想法发送其他参数。在下面的示例中,我正在测试使用 crsfmiddleware 的 django 登录,并且还有一个 redirect_to 参数,以便服务器知道登录成功后重定向到哪里。该测试并不真正使用表单,它只是发送浏览器在有人这样做时会发送的内容。如果你想测试真实的表单功能,最好的方法是使用像 selenium 这样的东西。
我必须添加手动提取 crsftoken,因为它会随每个请求而变化,并添加一个断言来检查它是否返回到登录页面,但除此之外,此测试就像为我自动生成的记录器一样:
这适用于以下形式:
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:
This works for the following form: