How to tear down selenium webdriver when the @tests are in different classes

I have about 5 different classes with JUnit tests (selenium tests). I need a way to teardown the webdriver at the end of the program. So I need to know where to put the @AfterClass and how to pass the driver to it so it can be closed.

I thought of creating a test suit and implement the &AfterClass tearDownClass() there. But I'm not sure how to pass the driver to it to close.


You can use below code

[OneTimeTearDown]
        public void SetupTestTeardown()
        {
            KillDriver();
            Assert.AreEqual("", verificationErrors.ToString());
        }

The OneTimeTearDown attribute is inherited from any base class. Therefore, if a base class has defined a OneTimeTearDown method, that method will be called after any test methods in the derived class.

You may define a OneTimeTearDown method in the base class and another in the derived class. NUnit will call base class OneTimeTearDown methods after those in the derived classes.


Add @BeforeClass to your superclass. Initiate the driver in that. Due to this, the test classes will also inherit the driver.

Add the driver teardown in your superclass in @AfterClass

链接地址: http://www.djcxy.com/p/52334.html

上一篇: 硒webdriver

下一篇: 如何在@tests在不同的课程中拆除硒webdriver