Reputation: 577
I want to run the test n times from beginning i.e. quit the driver and run the setup again. But retry attribute does not quit the driver, it just run the test case again.
[TestFixture(typeof(ChromeDriver))]
public class TestWithMultipleBrowsers<TWebDriver> where TWebDriver : IWebDriver, new()
{
#region Setup
private IWebDriver driver;
[TestFixtureSetUp]
public void CreateDriver()
{
if (typeof(TWebDriver).Name == "ChromeDriver")
{
driver = new ChromeDriver(@"C:\ChromeDriver");
}
else
{
driver = new TWebDriver();
}
}
[TestFixtureTearDown]
public void FixtureTearDown()
{
if (driver != null) driver.Quit();
}
[Test,Retry(2)]
[TestCase("jobsearch")]
[TestCase("employer")]
public void GoogleTest(string search)
{
driver.Navigate().GoToUrl("http://www.google.com/");
IWebElement query = driver.FindElement(By.Name("q"));
query.SendKeys(search + Keys.Enter);
Thread.Sleep(1000);
Assert.AreEqual(search + " - Google Search", driver.Title);
}
#endregion
}
Upvotes: 2
Views: 2890
Reputation: 511
I want to run the test n times from beginning i.e. quit the driver and run the setup again.
The reason the CreateDriver
method isn't being called again is because you're using the [TestFixtureSetUp]
attribute which only runs once for a [TestFixture]
. If you want to run a setup method before each test, use the [Setup]
attribute instead.
Same goes for the [TestFixtureTearDown]
attribute. If that should occur after each test, you should use the [TearDown]
attribute instead.
Upvotes: 3