selenium 尝试并行运行测试时出现WebDriver异常

cyej8jka  于 2022-12-18  发布在  其他
关注(0)|答案(1)|浏览(159)

我在TestFixture级别设置了[Parallelizable(ParallelScope.Children)],当我运行fixture中的所有测试时:

  • 打开4个浏览器示例
  • 一个最大化并加载到登录页面
  • 其他3个没有最大化,但导航到登录页面
  • 1个测试同时注入了来自所有4个测试的所有登录凭据
  • 3项测试失败,并显示以下消息:
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.

下面是fixture中一个测试的例子。其他测试基本上是相同的,只是针对不同的页面:

[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);
        }

以下是我的设置和拆卸步骤,以供参考:

[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();
        }

有人知道我做错了什么吗?很明显,我试图并行运行它们,然后没有正确处理它们。
提前感谢!!!

2hh7jdfx

2hh7jdfx1#

结果是我需要在基类static(duh)中创建驱动程序,并在页面[ThreadStatic]中创建所有_drivers。
我希望这能帮助别人在未来,因为它把我逼疯了!

相关问题