0

I used driver.Quit(); in TeardownTest method. But the browser is closed only if the test passed. If a test failed, the browser is still open. Why browser is not closed in this case?

We have Microsoft Visual team services builds, Visual Studio Test Agent is deployed to virtual machine. On the virtual machine is installed MS Agent for Visual studio 2015 Update 3. This problem, with closing the browser, happens only on virtual machine. If I run tests from Visual Studio on local machine, browser is closed if test passed or failed, in this case it works.

7
  • 1
    Edit your question what you have tried. Add your code and error which shows your eclipse after running the code. Apr 10, 2017 at 12:30
  • For example, if some element is not found, a test failed and the browser remains open. But if all steps of test methods are OK, a test passed and the browser is closed.
    – Majkl
    Apr 10, 2017 at 12:42
  • 1
    I am guessing you are not handling exceptions properly?
    – Yu Zhang
    Apr 10, 2017 at 12:49
  • 1
    How are you firing your tests? If you are using Test Explorer in Visual Studio, check to ensure you are not running your tests in debug mode. Also, can you tell us what test runner you are using? MSTest, NUnit, etc. Apr 10, 2017 at 14:55
  • 2
    Also the code for your setUp and tearDown would be great to answer this question. Apr 10, 2017 at 17:47

3 Answers 3

2

If you are catching any exceptions, call driver.quit() within those catch blocks to close the browser when a test fails. If there is a common point that all failing tests run through, I would put driver.quit() there instead of every catch block(ie. a reporting or logging method).

0

We too faced the similar issue and a quick search on internet lead me here.

Then I examined the detailed log and found out that a report saving activity was throwing an exception in the [TearDown] and hence the driver.Quit(); statement wasn't invoked.

It was referring a folder which wasn't there in the build system where as it is there in development environment!

So as a few people mentioned above, the issue is the exception but it seems it could come in different ways!

I wonder is it a good practice to save the report in TearDown action!

-1
 [TearDown]
        public void RunAfterEveryTest()
        {

            driver.Quit();
        }

Seems to be you are using NUnit, So please check the code you have for the trardown is same as the above code.

Or please share the code ..

2
  • jUnit? The question is tagged with C# think you are mistaken. Maybe NUnit or MStest, but certainly not jUnit :) Apr 10, 2017 at 17:47
  • Yeah should be Nunit,Becouse the word "TearDown" is directly connecting with Junit, MStest it has only "TestCleanup". i edit my answer .
    – ChathuD
    Apr 11, 2017 at 2:30

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.