I have the below class, how can I invoke the constructor of the class explicitly?
[TestFixture(typeof(ChromeDriver))]
public class BaseWebDriver<TWebDriver> where TWebDriver : IWebDriver, new()
{
public IWebDriver Driver { get; set; }
public WebDriverWait wait;
public BaseWebDriver()
{
Driver = new TWebDriver();
}
[OneTimeSetUp]
public virtual void SetupTest()
{
// Go to the login page
Driver.Navigate().GoToUrl("LoginUrl");
}
[OneTimeTearDown]
public virtual void TearDownTest()
{
Driver.Quit();
Driver.Dispose();
Console.WriteLine("***TearDown***\n");
}
public void restartBrowser()
{
Driver.Quit();
//Here I have to call the constructor of the class to open the browser again
}
}
Is it possible to call the constructor from a derived class? I am new to generics, so kindly help.
As Andrew said, Driver = new TWebDriver() works. Thanks.
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.