简体   繁体   English

我正在尝试在Visual Studio中运行所有测试,但是当我运行测试时,第一个测试将通过,但所有其他测试将失败

[英]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 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. 我认为在第一次测试后返回测试初始化​​会话ID是错误的还是丢失了。

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). 这是由于共享存在访问问题(另一个程序正在使用文件)的chromedriver.exe。

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(),而且还要执行Browser.Quit();。 Browser.Close() simply closes the browser window. Browser.Close()只是关闭浏览器窗口。 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. 我认为正在发生的事情是通过只做browser.Quit()您的会话ID设置为第一个测试,并且当您进入下一个测试时,会生成一个新的会话ID,但它们不匹配,导致正在执行的测试无效会话ID。

Similar to what is being outline in this post 类似于这篇文章中概述的内容

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 单元测试在Visual Studio中“全部运行”但单独传递时失败 - Unit Tests Fail when “Run All” in Visual Studio but passes individually 单元测试在“全部运行”时失败,但在单次运行时通过 - Unit tests fail on Run All but pass when are run single 运行所有测试时单元测试失败,但在调试时通过 - Unit Tests failing when I Run All Tests but pass when I Debug 在Visual Studio中运行所有打开的测试 - Run all open tests in Visual Studio Flurl&HttpTest:单元测试在全部运行时失败,但在单独运行时通过 - Flurl & HttpTest: Unit tests fail when Run All, but pass when run individually 当我运行所有测试时,不会调用 ClassInitialize - ClassInitialize doesn't get called when I run all tests Visual Studio不会在测试类中运行所有单元测试 - Visual Studio does not run all the unit tests in a test class 如果一次运行一个单元测试则传递正常,如果运行“解决方案中的所有测试”,则为FileLoadException - Unit Tests pass fine if run one at a time, FileLoadException if run “All Tests in Solution” 如何使用Microsoft Visual Studio 2012运行负载测试? - How do I run load tests with Microsoft Visual Studio 2012? 如何在visual studio之外运行SpecFlow测试 - How can I run SpecFlow tests outside of visual studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM