gpt4 book ai didi

selenium - 我应该在每次基于 Selenium 的自动化测试后退出浏览器吗?

转载 作者:行者123 更新时间:2023-12-01 11:14:12 25 4
gpt4 key购买 nike

我正在尝试使我的 selenium 测试尽可能原子且彼此独立,因此我决定在每次测试运行后退出浏览器并创建一个新的 Webdriver 实例。这种方法对我来说更有意义,并且通过讨论这个问题的几个线程得到了加强。e. G。 This answer to a related question:

You are closing the webdriver after one particular test. This is a good approach but you will need to start a new webdriver for each new test that you want to run.

但是,我也遇到过这样的观点,即在每次测试后退出浏览器是不必要且无效的。e. G。 Part of this blog about Selenium:

It’s not good practice to load a browser before each test. Rather, it is much better to load a browser before all tests and then close it after all tests are executed, as this will save resources and test execution time.

由于我对这一切都很陌生,因此我很难在这两者之间做出选择。到目前为止,我的测试的执行时间并不是一个真正的问题(因为我只有少数几个),但是当我开始扩展我的测试套件时,我担心它可能会成为一个问题。

最佳答案

直接回答,实际上没有明确的规则可以在执行时退出重用相同的浏览器客户端 测试 使用 Selenium。也许该决定将基于测试用例先决条件

如果您的测试 是独立的,明智的做法是quit()当前的 WebdriverBrowser Client 实例,并在每次测试运行后创建 WebdriverBrowser Client 的新实例这将启动一个新的和干净的 WebDriver/Browser Client 组合,如 closing browser after test pass 中所述。 .

虽然这会导致一些开销产生新的 WebDriver/Browser Client 组合,但这可能会提供急需的缓冲 CPU内存 使用情况,如以下内容所述:

Incase,测试不是独立的,测试基于相同的sessioncookies 等参数,重用相同的 WebDriver/Browser Client 很有意义。

关于selenium - 我应该在每次基于 Selenium 的自动化测试后退出浏览器吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55138341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com