I have a set of tests that are loaded dynamically using the ClassData
decorator:
using Xunit;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Interactions;
using System.Collections.Generic;
namespace reviewWebApp.UITests
{
public class ticketFieldWebAppShould
{
[Trait("Category", "Smoke")]
[Xunit.Theory]
[ClassData(typeof(repositories.readForms))]
public void LoadForms(string formNo , List<string> elemList)
{
using(IWebDriver driver = new ChromeDriver())
{
driver.Navigate().GoToUrl("http://localhost:61851/");
DemoHelper.Pause();
driver.SwitchTo().Alert().SendKeys(formNo);
driver.SwitchTo().Alert().Accept();
Actions action = new Actions(driver);
DemoHelper.Pause();
action.KeyDown(Keys.Control);
action.KeyDown(Keys.Alt);
action.Build().Perform();
driver.SwitchTo().Alert().SendKeys(elemList[0]);
driver.SwitchTo().Alert().Accept();
driver.SwitchTo().Alert().Accept();
}
}
}
}
The class that has the data is in a separate file:
using System.Collections.Generic;
using System.Collections;
namespace reviewWebApp.UITests.repositories
{
public class readForms : IEnumerable<object[]>
{
public IEnumerator<object[]> GetEnumerator()
{
for (int i = 1; i < 3; i++)
{
yield return new object[] { "t"+ i, new List<string> { "f", "" } };
}
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
}
Since the for loop goes twice I would expect the number of tests to be 2 distinct tests in the test explorer.
However, in the test explorer, I see 1 test that will open chrome twice.
The problem is that if a test fails I would not know where or which, since there is only a single test. Is it possible to decompose the code in two distinct tests dynamically loaded?