简体   繁体   中英

WebDriver exception when trying to run tests in parallel

I have [Parallelizable(ParallelScope.Children)] set at the TestFixture level. When I run all tests in the fixture:

  • 4 browser instances open
  • One maximises and loads to the login page
  • The other 3 don't maximise, but do navigate to the login page
  • The 1 test has all of the login credentials from all 4 tests injected simultaneously
  • The 3 tests fail with the message:
    OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:52502/session/a0a4621b5d62463e38bae7a206196295/element timed out after 60 seconds.
  ----> System.Threading.Tasks.TaskCanceledException : The operation was canceled.
  ----> System.IO.IOException : Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request..
  ----> System.Net.Sockets.SocketException : The I/O operation has been aborted because of either a thread exit or an application request.

Here is an example of one of the tests in the fixture. The others are basically the same but for different pages:

        [TestCase(MasterUserNames.actionManagementModuleOnly)]
        [TestCase(MasterUserNames.gembaIntelligenceModuleOnly)]
        [TestCase(MasterUserNames.oeeModuleOnly)]
        [TestCase(MasterUserNames.plantConnectionModuleOnly)]
        [TestCase(MasterUserNames.connectSystemsIntegrationModuleOnly)]
        [TestCase(MasterUserNames.recipesModuleOnly)]
        [TestCase(MasterUserNames.revenueModuleOnly)]
        public void access_to_manage_all_users_page_restricted_by_module(string user)
        {
            _loginPage.LogInAs(user);
            _manageAllUsersPage.GoToManageAllUsersPage(true);
            _manageAllUsersPage.AssertModuleAuthorisationLevelIsCorrectForPage(MasterPageNames.changeLog, user);
        }

For reference, here are my setup and teardown steps:

        [SetUp]
        public void BeforeEach()
        {
            new WebDriverManager.DriverManager().SetUpDriver(new ChromeConfig());
            driver = new ChromeDriver();
            Console.WriteLine($"These tests were run against {_loginPage.GetUrl(MasterPageNames.host)}");

            _loginPage.GoToLoginPage();
            driver.Manage().Window.Maximize();
        }

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

Does anyone have any clue what it is that I'm doing wrong? It's clearly trying to run them in parallel, and then failing to handle it correctly.

Thanks in advance!!!

It turned out that I needed to make the driver in my base class static (duh) and make all of the _drivers on my pages [ThreadStatic] .

I hope this can help someone else in future because it drove me nuts!

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