驱动程序是单例,我想并行运行测试,
注意:如果效果不佳则不使用单身
示例:
Singleton Class
public static class Driver
{
public static IWebDriver GetInstance()
{
if (driver == null)
{
driver = new ChromeDriver(//PATH);
}
return driver;
}
public static void SetNull()
{
driver = null;
}
}
TestCase(父类)
[TestFixture, Apartment(ApartmentState.MTA)]
[Parallelizable(ParallelScope.Self)]
public class TestCase
{
private IWebDriver driver;
[SetUp]
public void Initilize()
{
driver = Driver.GetInstance();
Driver.GetInstance().Navigate().GoToUrl(ConfigurationManager.AppSettings["url"]);
Driver.GetInstance().Manage().Window.Maximize();
}
[TearDown]
public void EndTest()
{
if (Driver.GetInstance() != null)
{
try
{
//Pending Logout
}
finally
{
Driver.GetInstance().Close();
Driver.GetInstance().Quit();
Driver.SetNull();
}
}
}
}
TESTCASE 1,2,3 ... N
[TestFixture, Apartment(ApartmentState.MTA)]
class TC85874_Login : TestCase
{
[Test, Apartment(ApartmentState.MTA)]
public void TC_85874_Login(string user, string password)
{
try
{
//CODE
}
catch (Exception e)
{
}
}
}
parallel: [assembly:LevelOfParallelism(3)]
装配 [装配:公寓(ApartmentState.MTA)]
我尝试 [Test,RequiresThread(ApartmentState.STA)] 和 RequiresThread属性 并且使用单例驱动程序
并行执行不正常注意:如果效果不佳则不使用单身
C#,Nunit 3