简体   繁体   中英

I am trying to run all tests in visual studio, but when I run the the tests the first one will pass, but all the others will fail

As above when I run all tests the only that passes is the 1st one, 

I get the following stack trace.

Message: Initialization method QtpTest.ChromeTest7.Initiliize threw
exeption.OpenQa.selenium.WebdriverException:
OpenQa.selenium.WebDriverException: invalid session id

TestBase.cs

namespace QtpTest
{  
    [TestClass]
    public class TestBase
    {
        [TestInitialize()]        
        public void Initialize()
        {
            Browser.Initialize();          
        }

        [TestCleanup]
        public void Cleanup()
        {
            Browser.Close();        
        }   
    }
}

I think That after the 1st test when it goes back to test initioalize the session id is either wrong or missing.

Though there is little to go off of here, I have had this issue in the past when running test in parallel.

We were experiencing the same issue you are facing where the first test would run and the rest would fail.

This was due to sharing the chromedriver.exe having access issues (file in use by another program).

I have a suggestion to try and resolve this since i am unsure if you are running in parallel or not as well as how you are creating your driver.

  1. Try and not only do Browser.Close(), but due Browser.Quit(); Browser.Close() simply closes the browser window. Browser Quit, quits the task as well(session) and allows you to instantiate a new instance of the browser for the subsequent test which gives you a new session.

What i think is happening is by just doing browser.Quit() your session id is set to the first test, and when you go onto the next test a new session id is generated but they do not match causing the executing test to have invalid session id.

Similar to what is being outline in this post

https://developer.mozilla.org/en-US/docs/Web/WebDriver/Errors/InvalidSessionID '

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM