[英]C# Selenium driver - close all web pages after finish
[SetUp]
public void Setup()
{
//open web page
}
[Test]
public void Test()
{
//test stuff
}
C# selenium driver has two methods, you can set up for example opening browser and going to specific web page, and then testing specific elements, so you don't have to write opening part in each test method. C# selenium驱动有两种方法,可以设置例如打开浏览器,进入特定的web页面,然后在每个方法中测试具体的元素,所以你不必写打开部分。
But then all these web pages will stay open until you close them manually.但是所有这些 web 页面将保持打开状态,直到您手动关闭它们。 Is there an equivalent for
Setup
that runs after test has been completed, so you can close browser automatically?测试完成后是否有等效的
Setup
运行,以便您可以自动关闭浏览器?
Here is a way you can close each browser after the test finishes (assuming you are using Nunit
and not MSTest
, which it appears you are).这是一种可以在测试完成后关闭每个浏览器的方法(假设您使用的是
Nunit
而不是MSTest
,看起来您就是这样)。 You would place this at the bottom, after all your tests:在所有测试之后,您会将其放在底部:
[TearDown]
public void TearDown()
{
if (driver != null)
{
driver.Dispose();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.