1

I'm writing tests in C# using Selenium and Nunit. They're written for Chrome and sample test is starting fine, opening browser, navigating to page and testing properly. After passing(or failing) the test it should (the browser )close but it doesn't and i do not know why. Here's the code and Im hoping someone will point me to the right way.

  public void Test1()
    {
        IWebDriver driver = new ChromeDriver();
        ChromeOptions options = new ChromeOptions();
        options.AddArguments("start-maximized");
        options.AddArguments("--disable-extensions");
        driver = new ChromeDriver(options);
        driver.Navigate().GoToUrl("https://name-of-the-site.com/");
        string check = driver.Title;
        Console.WriteLine("Site title");
        Console.WriteLine(check);
        String expectedTitle = "name of the site";
        StringAssert.AreEqualIgnoringCase(expectedTitle, check);
        if (check == expectedTitle)
        {
            Console.WriteLine("Title Confirmed");
        }
        else
        {
            Console.WriteLine("Title Not Confirmed");
        }
        Assert.Pass();
        driver.Close();
        driver.Quit();   }

Thanks in advance

1 Answer 1

1

You need to add an TearDown with the code to close and quit to run after, like this:

[TearDown]
   public void QuitBrowserAndCloseConnection() { 
    driver.Close();
    driver.Quit();
} 

This is necessary to force to run this code if the test pass or fail.

Sign up to request clarification or add additional context in comments.

1 Comment

I have an issue with extra browser starting up when testing and remaining after tests but thats another problem lol

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.