热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

每个测试方法都有新的WebDriver实例?-NewWebDriverinstancepertestmethod?

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 个解决方案

#1


14  

I've found that reusing browser instances between test methods has been a huge time saver when using real browsers, e.g. Firefox. When running tests with HtmlUnitDriver, there is very little benefit.

我发现在使用真实浏览器时,在测试方法之间重复使用浏览器实例可以节省大量时间,例如: Firefox浏览器。使用HtmlUnitDriver运行测试时,几乎没有什么好处。

Regarding the danger of indeterministic tests, it's a trade-off between totally deterministic tests and your time. Integration tests often involve trade-offs like these. If you want totally deterministic integration tests you should also be worrying about clearing the database/server state in between test runs.

关于不确定性测试的危险性,它是完全确定性测试与您的时间之间的权衡。集成测试通常涉及这些权衡。如果您想要完全确定性的集成测试,您还应该担心在测试运行之间清除数据库/服务器状态。

One thing that you definitely should do if you are going to reuse browser instances is to clear/store the COOKIEs between runs.

如果要重用浏览器实例,那么你应该做的一件事就是在运行之间清除/存储COOKIE。

driver.manage().deleteAllCOOKIEs();

I do that in a tearDown() method. Also if your application stores any data on the client side you'd need to clear that (maybe via JavascriptExecutor). To your application which is under test, it should look like a completely unrelated request after doing this, which really minimizes the risk of indeterministic behaviour.

我在tearDown()方法中这样做。此外,如果您的应用程序在客户端存储任何数据,您需要清除它(可能通过JavascriptExecutor)。对于正在测试的应用程序,在执行此操作后,它应该看起来像一个完全不相关的请求,这确实可以最大限度地降低不确定行为的风险。

#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).

还尝试限制集成测试的范围。如果你有很多繁重的集成测试,耗费执行时间,试着重构。相反,增加底层服务调用(业务逻辑所在的位置)的更轻量级单元测试的覆盖范围。


推荐阅读
  • 本文讨论了在使用sp_msforeachdb执行动态SQL命令时,当发生错误时如何捕获数据库名称。提供了两种解决方案,并介绍了如何正确使用'?'来显示数据库名称。 ... [详细]
  • 本文介绍了在使用Laravel和sqlsrv连接到SQL Server 2016时,如何在插入查询中使用输出子句,并返回所需的值。同时讨论了使用CreatedOn字段返回最近创建的行的解决方法以及使用Eloquent模型创建后,值正确插入数据库但没有返回uniqueidentifier字段的问题。最后给出了一个示例代码。 ... [详细]
  • 上图是InnoDB存储引擎的结构。1、缓冲池InnoDB存储引擎是基于磁盘存储的,并将其中的记录按照页的方式进行管理。因此可以看作是基于磁盘的数据库系统。在数据库系统中,由于CPU速度 ... [详细]
  • 本文介绍了数据库的存储结构及其重要性,强调了关系数据库范例中将逻辑存储与物理存储分开的必要性。通过逻辑结构和物理结构的分离,可以实现对物理存储的重新组织和数据库的迁移,而应用程序不会察觉到任何更改。文章还展示了Oracle数据库的逻辑结构和物理结构,并介绍了表空间的概念和作用。 ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • 本文介绍了Redis的基础数据结构string的应用场景,并以面试的形式进行问答讲解,帮助读者更好地理解和应用Redis。同时,描述了一位面试者的心理状态和面试官的行为。 ... [详细]
  • 使用Ubuntu中的Python获取浏览器历史记录原文: ... [详细]
  • 本文介绍了Oracle数据库中tnsnames.ora文件的作用和配置方法。tnsnames.ora文件在数据库启动过程中会被读取,用于解析LOCAL_LISTENER,并且与侦听无关。文章还提供了配置LOCAL_LISTENER和1522端口的示例,并展示了listener.ora文件的内容。 ... [详细]
  • 图解redis的持久化存储机制RDB和AOF的原理和优缺点
    本文通过图解的方式介绍了redis的持久化存储机制RDB和AOF的原理和优缺点。RDB是将redis内存中的数据保存为快照文件,恢复速度较快但不支持拉链式快照。AOF是将操作日志保存到磁盘,实时存储数据但恢复速度较慢。文章详细分析了两种机制的优缺点,帮助读者更好地理解redis的持久化存储策略。 ... [详细]
  • Oracle10g备份导入的方法及注意事项
    本文介绍了使用Oracle10g进行备份导入的方法及相关注意事项,同时还介绍了2019年独角兽企业重金招聘Python工程师的标准。内容包括导出exp命令、删用户、创建数据库、授权等操作,以及导入imp命令的使用。详细介绍了导入时的参数设置,如full、ignore、buffer、commit、feedback等。转载来源于https://my.oschina.net/u/1767754/blog/377593。 ... [详细]
  • WhenIusepythontoapplythepymysqlmoduletoaddafieldtoatableinthemysqldatabase,itdo ... [详细]
  • PDO MySQL
    PDOMySQL如果文章有成千上万篇,该怎样保存?数据保存有多种方式,比如单机文件、单机数据库(SQLite)、网络数据库(MySQL、MariaDB)等等。根据项目来选择,做We ... [详细]
  • 本文主要复习了数据库的一些知识点,包括环境变量设置、表之间的引用关系等。同时介绍了一些常用的数据库命令及其使用方法,如创建数据库、查看已存在的数据库、切换数据库、创建表等操作。通过本文的学习,可以加深对数据库的理解和应用能力。 ... [详细]
  • 在Oracle11g以前版本中的的DataGuard物理备用数据库,可以以只读的方式打开数据库,但此时MediaRecovery利用日志进行数据同步的过 ... [详细]
  • GreenDAO快速入门
    前言之前在自己做项目的时候,用到了GreenDAO数据库,其实对于数据库辅助工具库从OrmLite,到litePal再到GreenDAO,总是在不停的切换,但是没有真正去了解他们的 ... [详细]
author-avatar
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有