如何使用django和selenium/grid模拟并行多用户可用性测试? [英] how to emulate parallel multi-user usability testing with django and selenium/grid?

查看:47
本文介绍了如何使用django和selenium/grid模拟并行多用户可用性测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用 LiveServerTestCase ,但我想模拟并行多用户测试.我认为我不需要真正的负载测试,因为我的应用程序主要是中等/低流量的网站和内部Web应用程序,因此我宁愿避免使用JMeter之类的额外工具.

I can get my Selenium tests running fine for one user/ sequentially on Django 1.4 using LiveServerTestCase, but I would like to emulate parallel multi-user testing. I don't think I need real load testing, since my apps are mostly moderate/low traffic web-sites and internal web-apps, so I would prefer to avoid extra tools like JMeter.

我已经开始设置 Selenium Grid ,但是不确定如何保持测试独立并且仍然可以与多个用户一起运行多个测试.我假设测试用例应该在同一数据库上同时为不同的用户运行-但是每个测试都会删除并创建一个新的数据库,所以我不知道这是怎么可能的.

I've started out setting up Selenium Grid but am not sure how to keep my tests independent and still run multiple tests with multiple users. I assume the test cases should be run for different users on the same DB simultaneously - but each test drops and creates a new DB, so I don't understand how that is possible.

我不想注册 BrowserMob 之类的服务.

And I don't want to sign up for a service like BrowserMob.

推荐答案

我想我已经明白了,但是欢迎更多(可能更优雅)的解决方案.

I think I figured this out but welcome more (potentially more elegant) solutions.

我正在同时进行干净"和肮脏"测试.干净"测试只是普通的Selenium测试,它会在每次测试后设置并拆除数据库.通过向我的子类DjangoTestSuiteRunner传递选项来运行脏"测试,该选项告诉它是否设置或拆除数据库,还传递用户ID,例如:

I'm running both "clean" and "dirty" tests. The "clean" tests are just normal Selenium tests that set up and tear down the DB after every test. The "dirty" tests are run by passing options to my subclassed DjangoTestSuiteRunner which tell it whether or not to set up or tear down the DB, and also pass in a user id, like so:

python manage.py test myapp --testrunner=testrunner.MySeleniumTestRunner \ 
    --no_setup_db --no_teardown_db --user=1234 --liveserver=localhost:8081

然后我将这些命令中的大约10个用命令行连接在一起,并记录输出.

I then string together about 10 of these commands in a shell script and log the output.

唯一棘手的部分是以两种测试都考虑在内的方式编写测试.因此,例如,如果我只是在干净的测试中测试只是将产品添加到购物车中,并检查购物车中的商品以表示成功,那么我还需要添加一个条件来检查产品的可用性.因此,当我运行肮脏的测试时,如果只有四个产品可用,则前四个用户成功,因为该产品可用,并且我确认该产品已添加到他们的购物车中-但第五个用户通过了测试,因为当产品不可用时,我会检查是否进行了正确的错误处理等.

The only tricky part is writing your tests in a way that take into account both kinds of test. So, for example, if I'm testing simply adding a product to a shopping cart in my clean test and checking for the item in the cart to indicate success, then I also need to add a condition that checks for things like product availability. So when I run my dirty tests, if there are only four products available, then the first four users are successful because the product was available and I verified the product was added to their cart - but the fifth user also passes the test, because when the product is not available I check for proper error handling, etc.

我知道这不是单元测试,甚至对于功能测试来说可能不是标准的,但是我认为它可以很好地模拟并行多用户测试,而不会影响测试的独立性.

I know this isn't very unit-test like, and may be even rather non-standard for functional testing, but I think it emulates parallel multi-user testing pretty well, without compromising test independence.

这篇关于如何使用django和selenium/grid模拟并行多用户可用性测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆