英文:
Selenium doesn't close any browsers until ALL tests are complete
问题
我正在做类似下面的事情,使用多个测试类,但是 [ClassCleanup] 直到所有测试都运行完毕才会被调用。
因此,每个类都启动一个浏览器,所有的浏览器都保持打开状态,直到所有测试都完成,然后它们都关闭。
这是否是预期行为?
有人可以评论一下他们的测试是否也有相同的情况?
是否有一种方法可以在测试类完成时强制关闭浏览器?
[ClassCleanup]
public static void ClassCleanup()
{
driver.Quit();
}
我不知道这是否是 Selenium 应该工作的方式,还是我有一些挂起的资源导致浏览器无法在最后关闭?
我不能使用 [TestCleanup],因为这样做会导致无法在同一测试类中运行多个测试(因为它会在第二个测试运行之前关闭)。
英文:
I'm doing something like this (below) with multiple Test Classes but [ClassCleanup] is not called until ALL tests run.
Because of this each class starts up a browser and ALL of the browsers remain open until ALL of the tests are completed, and then they ALL close down.
Is this expected?
Could someone comment if their tests do the same thing?
Is there a way to force a browser to close when the test class is done?
[ClassCleanup]
public static void ClassCleanup()
{
driver.Quit();
I dont know if this is just how Selenium is supposed to work, or if I have some sort of hanging resource that doesn't allow the browser to close until the end?
I cannot use [TestCleanup] because then I cannot have multiple tests in the same test class (as it will close before the 2nd test will run)
答案1
得分: 0
我终于找到一个有效的示例
只需将
[ClassCleanup]
替换为
[ClassCleanup(ClassCleanupBehavior.EndOfClass)]
英文:
I finally found an example that works
Simply replaced
[ClassCleanup]
with
[ClassCleanup(ClassCleanupBehavior.EndOfClass)]
答案2
得分: -1
你可以使用 [TestInitialize]
作为每个测试用例的设置,使用 [TestCleanup]
作为拆卸。
在你的代码中,它在类后面运行(所有测试用例)。
因此完整的代码如下:
设置:
[TestInitialize()]
public void InitializeTest() {
// 你的驱动程序初始化代码
}
以及,拆卸:
[TestCleanup]
public void Cleanup() {
driver.Quit();
}
英文:
you can use [TestInitialize]
as setUp and [TestCleanup]
as Teardown of each test case.
In your code, it runs after class(all test cases)
So full code:
Setup:
[TestInitialize()]
public void InitializeTest() {
//your driver initilazation code
}
and, Teardown:
[TestCleanup]
public void Cleanup() {
driver.Quit();
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论