作者: | 来源:互联网 | 2023-10-12 10:42
WhatsthebestpracticefortcreatingwebdriverinstancesinSelenium-webdriver?Oncepertestmeth
What's the best practice fort creating webdriver instances in Selenium-webdriver? Once per test method, per test class or per test run?
在Selenium-webdriver中创建webdriver实例的最佳实践是什么?每个测试方法,每个测试类或每次测试运行一次?
They seem to be rather (very!) expensive to spin up, but keeping it open between tests risks leaking information between test methods.
它们似乎相当(非常)昂贵,但在测试之间保持开放可能会在测试方法之间泄漏信息。
Or is there an alternative - is a single webdriver instance a single browser window (excluding popups), or is there a method for starting a new window/session from a given driver instance?
或者是否有另一种选择 - 单个webdriver实例是单个浏览器窗口(不包括弹出窗口),还是有一种从给定驱动程序实例启动新窗口/会话的方法?
Thanks Matt
谢谢马特
2 个解决方案
6
If your goal of automated integration testing is to have reproducible tests, then I would recommend a new webdriver instance for every test execution.
如果您的自动化集成测试的目标是进行可重复的测试,那么我建议每个测试执行一个新的webdriver实例。
Each test should stand alone, independent from any other test or side-effects.
每项测试都应该独立,独立于任何其他测试或副作用。
Personally the only thing I find more frustrating than a hard to reproduce bug, is a non-deterministic test that you don't trust.
就个人而言,我唯一觉得比难以复制的bug更令人沮丧的是,你不信任的非确定性测试。
(This becomes even more crucial for managing the test data itself, particularly when you look at tests which can modify persistent application state, like CRUD operations.)
(这对于管理测试数据本身更为重要,特别是当您查看可以修改持久应用程序状态的测试时,例如CRUD操作。)
Yes, additional test execution time is costly, but it is better then spending the time debugging your tests.
是的,额外的测试执行时间是昂贵的,但最好是花时间调试测试。
Some possible solutions to help offset this penalty is to roll your testing directly into your build process, going beyond Continuous Build to Continuous Integration approach.
一些可能的解决方案可以帮助抵消这种损失,将测试直接推送到构建过程中,超越了持续构建到持续集成的方法。
Also try to limit the scope of your integration tests. If you have a lot of heavy integration tests, eating up execution time, try to refactor. Instead, increase the coverage of your more lightweight unit tests of the underlying service calls (where your business logic is).
还尝试限制集成测试的范围。如果你有很多繁重的集成测试,耗费执行时间,试着重构。相反,增加底层服务调用(业务逻辑所在的位置)的更轻量级单元测试的覆盖范围。