Multithreading 使用MSTEST和Selenium进行并行web测试时线程中止
我已经走到了最后一英里了 通过更改Local.testsettings中的parallelTestCount设置,我的测试项目中同时运行了多个测试:Multithreading 使用MSTEST和Selenium进行并行web测试时线程中止,multithreading,selenium,automated-tests,mstest,selenium-grid,Multithreading,Selenium,Automated Tests,Mstest,Selenium Grid,我已经走到了最后一英里了 通过更改Local.testsettings中的parallelTestCount设置,我的测试项目中同时运行了多个测试: <Execution parallelTestCount="5"> <TestTypeSpecific /> <AgentRule name="Execution Agents"> </AgentRule> </Execution> 我创建了5个线程来创建
<Execution parallelTestCount="5">
<TestTypeSpecific />
<AgentRule name="Execution Agents">
</AgentRule>
</Execution>
我创建了5个线程来创建RemoteWebDriver
实例并登录到我的网站
Dim desiredCapabilities As Remote.DesiredCapabilities = Remote.DesiredCapabilities.Chrome()
Dim size As String = "--window-size={0},{1}"
size = String.Format(size, browserWidth, browserHeight)
Dim position As String = "--window-position={0},{1}"
position = String.Format(position, browserWidth * index, 0)
desiredCapabilities.SetCapability("chrome.switches", {size, position})
driver = New Remote.RemoteWebDriver(New System.Uri("http://localhost:4444/wd/hub"), desiredCapabilities)
...
...code to use driver to log into web site
我加入线程,以便在它们全部登录之前测试不会开始。我创建了一个DriverPoolManger类,将可用的web驱动程序分配给等待测试。每当我检查驱动程序是否可用或更改其状态时,我都会使用ReaderWriterLock:
_readerWriterLock.AcquireWriterLock(Threading.Timeout.Infinite)
_locks(index) = False
_readerWriterLock.ReleaseWriterLock()
此时,它并行运行测试一段时间,然后失败,原因是:
Type is not resolved for member 'OpenQA.Selenium.WebDriverException,WebDriver, Version=2.16.0.0, Culture=neutral, PublicKeyToken=1c2bd1631853048f'.
经过一些研究后,解决方案是将它要查找的DLL复制到一个名为“C:\Program Files(x86)\Microsoft Visual Studio 10.0\Common7\IDE\UnitTestAssemblies”的新文件夹中,然后更新QTAgent32.exe.config以将其列在privatePath中:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="PrivateAssemblies;PublicAssemblies;DataCollectors;DataCollectors\x64;PrivateAssemblies\DataCollectors;PrivateAssemblies\DataCollectors\x64;UnitTestAssemblies;"/>
</assemblyBinding>
我将在没有驱动程序池的情况下尝试它,但这意味着启动一个新的驱动程序并登录每个测试。我在多线程方面没有太多的经验,而且VS中的并行测试似乎存在很多问题。我的驱动程序池可能会导致这种情况吗
更新:
我删除了我的驱动程序池,但这个问题仍然存在。我几乎放弃了,但下面是解决方案: mstest/Noiseolation 这就完全消除了qtagent32.exe,从那以后我就再也没有遇到过问题
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="PrivateAssemblies;PublicAssemblies;DataCollectors;DataCollectors\x64;PrivateAssemblies\DataCollectors;PrivateAssemblies\DataCollectors\x64;UnitTestAssemblies;"/>
</assemblyBinding>
(QTAgent32.exe, PID 8444, Thread 15) Unit Test Adapter threw exception: System.Threading.ThreadAbortException: Thread was being aborted.
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.RunTestMethod()
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.ExecuteTest()
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestExecuter.Execute(UnitTestResult result)
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestRunner.ExecuteSingleTest(UnitTestExecuter executer, UnitTestElement test, ITestContext testContext, UnitTestAdapterContext userContext, Boolean isLoadTest)
at Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestRunner.Run(UnitTestElement test, ITestContext testContext, Boolean isLoadTest, Boolean useMultipleCpus)