[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.
But then all these web pages will stay open until you close them manually. Is there an equivalent for Setup
that runs after test has been completed, so you can close browser automatically?
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). You would place this at the bottom, after all your tests:
[TearDown]
public void TearDown()
{
if (driver != null)
{
driver.Dispose();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.