c# - 引诱报告中TestCaseSource的分组
问题描述
我目前是使用 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 通过命令行运行测试: 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 Report 中。
使用 AllureSuite 运行的 Allure 报告图像:通过 AllureSuite的 Allure 报告图像
任何帮助将不胜感激,因为我目前无法找到任何链接/帮助。
解决方案
理想情况下,您应该从您的 TestCaseSource 生成 IEnumerable。
使用 TestCaseSource 时,生成唯一的测试名称以使报告工作很重要。更重要的是,一个好的报表名称会让你的报表看起来很棒。
TestCaseSource 用法
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}"
}
推荐阅读
- javascript - 在不同页面上使用变量更改图像 src 的正确方法是什么?
- firebase - 在flutter中从firebase下载数据
- typescript - “DocumentData”类型的参数不可分配给“never”类型的参数
- go - 类型 clientv3.Config 没有字段或方法用户名
- python - 使用 selenium 从 Firefox 自动下载 zip 文件
- reactjs - 如何在反应路由器的 URL 中间嵌入 :id 参数
- angular - 将 Angular 11 迁移到 12:更新 @angular-builders/custom-webpack 后找不到模块“webpack”错误
- python - 从多个 jpg 图像创建 Dicom
- java - 如何使用 IBMJSSE2 默认提供程序从 SSLContext 获取所有 TLS 会话?
- elasticsearch - 根据 Contition 获取最小值和最大值