对于使用NUnit和Allure进行报告的Selenium自动化测试,我目前还是个新手。
我已经成功地完成了一些简单的web自动化测试场景,并且能够在Allure上很好地显示结果。
转到更高级的场景,我正在考虑递归地执行基于多个数据集的测试(在CSV/Excel中)。我读到过,这可以通过TestCaseSource实现。
我的第一次尝试是通过命令行dotnet test --logger:trx运行.csproject来生成报告。在此尝试中,所有TestCaseSource都被触发,但只有第一个被标记到TestClass。
EasyFormDemo.cs中的测试:
[Test, TestCaseSource(typeof(ModelTestCaseSource), "GetTestCaseDaysCSV", new object[] { "../netcoreapp3.1/data.csv" })]
public void formDemo3(DataDays dataDays)
{
driver.Url = "https://www.seleniumeasy.com/test/basic-first-form-demo.html";
string sendkey = dataDays.Day;
IWebElement msg = driver.FindElement(By.Id("user-message"));
msg.SendKeys(sendkey);
IWebElement btn = driver.FindElement(By.XPath("//button[text()='Show Message']"));
btn.Click();
string display = driver.FindElement(By.Id("display")).Text;
Assert.AreEqual(sendkey, display);
}ModelTestCaseSource.cs:
public static IEnumerable<TestCaseData> GetTestCaseDaysCSV(string path)
{
DataTable dt = CSVReader.ConvertCSVtoDataTable(path);
foreach (DataRow row in dt.Rows)
{
var dataDays = new DataDays();
dataDays.Day = row["Day"].ToString();
yield return new TestCaseData(new object[] { dataDays });
}
}(无法直接上传图片,抱歉)
通过命令行运行测试的诱人报告图像:Allure Report Image via command line
从图中可以看出,只有formDemo3的第一个TestCaseSource连接到了TestSelenium.easyFormDemo。formDemo3的TestCaseSource的其余部分被单独附加到底部。
然后我看了看更多关于NUnit.Allure nuget包的内容。我导入了nuget并相应地配置了AllureParentSuite和AllureSuite。
EasyFormDemo.cs中的测试:
[AllureParentSuite("FormDemo")]
.
.
.
[Test, TestCaseSource(typeof(ModelTestCaseSource), "GetTestCaseDaysCSV", new object[] { "../netcoreapp3.1/data.csv" })]
[AllureSuite("FormDemo3")]
public void formDemo3(DataDays dataDays)
{
driver.Url = "https://www.seleniumeasy.com/test/basic-first-form-demo.html";
string sendkey = dataDays.Day;
IWebElement msg = driver.FindElement(By.Id("user-message"));
msg.SendKeys(sendkey);
IWebElement btn = driver.FindElement(By.XPath("//button[text()='Show Message']"));
btn.Click();
string display = driver.FindElement(By.Id("display")).Text;
Assert.AreEqual(sendkey, display);
}然后,我通过Visual Studio测试查看器触发了该项目。现在的问题是,尽管所有的TestCaseSource都被触发了,但只有第一个TestCaseSource会被捕获到Allure报告中。
使用AllureSuite运行的诱人报告图像:Allure Report Image via AllureSuite
任何帮助都将非常感谢,因为我目前无法找到任何链接/帮助这一点。
发布于 2021-06-10 05:40:52
理想情况下,您应该从TestCaseSource生成IEnumerable。
在使用TestCaseSource时,为报告生成唯一的测试名称是很重要的。更重要的是,一个好的报告名称会让你的报告看起来很棒。
TestCaseSource usage
public static IEnumerable<TestCaseData> TestCaseSource() =>
MyTestCaseSourceFunction();
[TestCaseSource(nameof(TestCaseSource))]
public void CanDiscoverEndPoints(string param1)构建TestCaseData
Return an IEnumerable<TestCaseData> for your purpose.
new TestCaseData("parameter value")
{
TestName = $"MyTestName-{apiRoot}{api}{op.Operation.Method}"
}https://stackoverflow.com/questions/66544384
复制相似问题