0

I'm having trivial question but what is the main different between static and non static driver/ NUnit hooks?

I'm having a code:

 [TestClass]
    public class SectionsTests
    {
        private static Driver _driver;
        private static MainPage _mainPage;
        private static CartPage _cartPage;

        [ClassInitialize]
        public static void ClassInitialize(TestContext testContext)
        {
            _driver = new LoggingDriver(new WebDriver());
            _driver.Start(Browser.Chrome);
            _mainPage = new MainPage(_driver);
            _cartPage = new CartPage(_driver);
        }

        [ClassCleanup]
        public static void ClassCleanup()
        {
            _driver.Quit();
        }

        [TestInitialize]
        public void TestInitialize()
        {
            _mainPage.Open();
        }

        [TestMethod]
        public void OpenBlogPage()
        {
            _mainPage.MainMenuSection.OpenBlogPage();
        }

I'm facing different approaches, sometimes I see that QA's are using static hooks/ driver and some of those are using non static. What is the best approach to be taken?

Kermi
  • 227
  • 1
  • 13
  • Please tag your questions correctly in consideration of those of us who only follow certain tags. Your code does not use NUnit but appears to be using vstest framework. – Charlie Oct 30 '20 at 03:06
  • Does this answer your question? [C# static vs instance methods](https://stackoverflow.com/questions/4765290/c-sharp-static-vs-instance-methods) – Greg Burghardt Oct 30 '20 at 12:19

0 Answers0