C# 如何在Specflow/Selenium/C/NUnit上实现并行执行?
我有一个按顺序运行测试的现有项目,我正在尝试实现并行执行 我最初将这些属性添加到AssemblyInfo.csC# 如何在Specflow/Selenium/C/NUnit上实现并行执行?,c#,selenium,C#,Selenium,我有一个按顺序运行测试的现有项目,我正在尝试实现并行执行 我最初将这些属性添加到AssemblyInfo.cs [assembly: Parallelizable(ParallelScope.Fixtures)] [assembly: LevelOfParallelism(2)] 为了看到正在尝试并行执行,我必须创建两个特性,每个特性都有一个测试,然后在VisualStudio的测试资源管理器中运行它们。这试图同时运行每个功能中的每个测试 我将其中一个测试设置为在Chrome中运行,另一个在F
[assembly: Parallelizable(ParallelScope.Fixtures)]
[assembly: LevelOfParallelism(2)]
为了看到正在尝试并行执行,我必须创建两个特性,每个特性都有一个测试,然后在VisualStudio的测试资源管理器中运行它们。这试图同时运行每个功能中的每个测试
我将其中一个测试设置为在Chrome中运行,另一个在Firefox中运行。这也是webdriver调用浏览器实例的顺序
Chrome先打开,然后Firefox打开——但是Chrome是孤立的,测试只在Firefox中进行
我相信这是因为我的webdriver是静态的,所以Firefox正在劫持Chrome使用的线程。我已经读到我不能使用静态webdriver进行并行测试,所以我尝试使用非静态webdriver
似乎我现在必须在方法之间传递驱动程序,以确保所有操作都在该特定实例上执行
在以非静态方式实现webdriver之后,我首先尝试确保运行单个测试,然后再尝试并行运行所有测试
但我遇到了一个障碍。在以下测试中,当第二步开始时,驱动器复位为空:
Scenario Outline: C214 Log in
Given I launch the site for <profile> and <environment> and <parallelEnvironment>
When I log in to the Normal account
Then I see that I am logged in
Examples:
| profile | environment | parallelEnvironment |
| single | Chrome75 | |
#| single | Firefox67 | |
BaseSteps.cs
using OpenQA.Selenium;
namespace OurAutomation.Steps
{
public class BaseSteps : SetUp
{
public IWebDriver driver;
public void DriverSetup(string profile, string environment, string parallelEnvironment)
{
driver = InitialiseDriver(profile, environment, parallelEnvironment);
}
}
}
LaunchTestSteps.cs
using OurAutomation.BaseMethods;
using OurAutomation.Pages;
using TechTalk.SpecFlow;
namespace OurAutomation.Steps
{
[Binding]
public class LaunchTestSteps : BaseSteps
{
[Given(@"I launch the site for (.*) and (.*) and (.*)")]
public void ILaunchTheSite(string profile, string environment, string parallelEnvironment)
{
DriverSetup(profile, environment, parallelEnvironment);
new Common().LaunchSite(driver);
new Core().Wait(10, "seconds");
}
}
}
还有更多,但不确定是否需要完整的套件来解决这个问题。就我的致命错误而言,这也许是显而易见的 经过大量的ado之后,我找到了一种方法,它使我能够剥离出必要的代码,以便使用ThreadLocal实现并行测试。您好,您使用selenium grid了吗?您是否有任何与selenium网格并行运行的移动测试的指针?
using OurAutomation.BaseMethods;
using OurAutomation.Pages;
using TechTalk.SpecFlow;
namespace OurAutomation.Steps
{
[Binding]
public class LaunchTestSteps : BaseSteps
{
[Given(@"I launch the site for (.*) and (.*) and (.*)")]
public void ILaunchTheSite(string profile, string environment, string parallelEnvironment)
{
DriverSetup(profile, environment, parallelEnvironment);
new Common().LaunchSite(driver);
new Core().Wait(10, "seconds");
}
}
}