Selenium:how 使用 NUnit 创建测试证据报告
Selenium:how to create test evidence report with NUnit
我想知道如何创建 Selenium UI 测试的适当测试证据。
我正在考虑屏幕截图,但它们实际上并没有涵盖您所做的一切,因为很难确定何时进行屏幕截图。 (每次点击或每次等待或每次页面加载)。
我考虑过的另一个选择是屏幕录制,但这使得在录制整个屏幕而不是特定屏幕时很难并行处理 chrome window.
但是,您也可以通过网络驱动程序每秒截屏一次,然后将其制作成视频。然后必须使用一个单独的线程,考虑到您必须提供的条件来阻止线程截取屏幕截图,这可能非常具有挑战性。否则测试将永远 运行。
由于我无法根据自己关于为 UI 测试创建测试证据报告的想法得出令人信服的结论,所以我希望有人能向我解释如何正确地做到这一点。
我有类似的问题,我在我的自动化框架 ExtentReports + klov 服务器中引入了 Testrail 作为测试管理工具。
我认为没有人会要求您通过视频或屏幕截图来展示测试用例,但如果有必要,您可以查看几个库以获取 'video',因为这不是实际视频,而不是将一堆屏幕截图融合到一个视频中。
实际证明真正值得投入时间的是截取失败的测试用例截图并将其附加到测试用例结果中(Testrail、Bugzila、Extentreports 等等)。
实际上如果使用 selenium/appium 你可以检查这个 repo
[https://github.com/groupon/Selenium-Grid-Extras] 他们制作 'video' 就像提到的那样并存储在本地 hub/node。
但是真正好的方法的最佳方法是报告每个测试用例的详细步骤:
带有详细步骤和操作的屏幕截图测试用例:
我在申请中处理报告的方式与 Kovacic 所说的一致。
我还使用 ExtentReports 作为生成指标并逐步记录发生的事情的方法。
我创建了一个负责记录步骤的方法(点击那个,导航到那里,断言...),如果需要可以选择截屏,另一个用于开始新测试。
然后,就是在 PageObject 样式测试框架中调用这些方法,并且几乎在您的框架执行的每个操作中调用这些方法。
为了更好地说明这里有一些实现示例 (c#):
记录一个步骤方法
public void LogStep(Status status,string MessageToLog, bool hasScreenshot)
{
//we leave the possibility of taking the screenshot with the step or not
if (hasScreenshot)
{
Test.Log(logstatus, messageToLog)
.AddScreenCaptureFromPath(GetScreenshot());
}
else
Test.Log(logstatus, messageToLog);
}
截屏方法
public static string GetScreenshot()
{
ITakesScreenshot ts;
//Browser.Driver here is the instance of the Driver you want to take screenshots with
ts = (ITakesScreenshot)Browser.Driver;
var screenshot = ts.GetScreenshot();
// Here just input the name you want your screenshot to have, with path
var screenshotPath = ScreenShotFolder + @"\" + _screenshotcount + ".bmp";
screenshot.SaveAsFile(screenshotPath);
// I've introduced a variable to keep track of the screenshot count (optional)
return (ScreenShotFolder.Substring(_reportRoot.Length) +"/"+ _screenshotcount + ".bmp");
}
框架调用示例[=43=]
public void BlockAccount()
{
try
{
_blockAccBtn.Click();
_confirmBtn.Click();
ExtentReportGenerator.LogStep(Status.Info, "Blocking Account");
}
catch (NoSuchElementException)
{
ExtentReportGenerator.LogStep(Status.Fail, "Could not find block button", true);
}
}
使用整个系统的NunitTest
[TestCase, Order(1)]
public void CanBlockCard()
{
//Creates a new test in the report
ExtentReportGenerator.Test = ExtentReportGenerator.Extent.CreateTest(GetCurrentMethod());
//Each one of these calls to the framework has logged steps
CashlessPages.CashlessAffiliationsPage.AccessAccount(1, 1);
CashlessPages.CashlessAccountsPage.BlockAccount();
Assert.IsTrue(CashlessPages.CashlessAccountsPage.IsAccBlocked());
}
生成的报告示例
希望对您有所帮助
我想知道如何创建 Selenium UI 测试的适当测试证据。
我正在考虑屏幕截图,但它们实际上并没有涵盖您所做的一切,因为很难确定何时进行屏幕截图。 (每次点击或每次等待或每次页面加载)。
我考虑过的另一个选择是屏幕录制,但这使得在录制整个屏幕而不是特定屏幕时很难并行处理 chrome window.
但是,您也可以通过网络驱动程序每秒截屏一次,然后将其制作成视频。然后必须使用一个单独的线程,考虑到您必须提供的条件来阻止线程截取屏幕截图,这可能非常具有挑战性。否则测试将永远 运行。
由于我无法根据自己关于为 UI 测试创建测试证据报告的想法得出令人信服的结论,所以我希望有人能向我解释如何正确地做到这一点。
我有类似的问题,我在我的自动化框架 ExtentReports + klov 服务器中引入了 Testrail 作为测试管理工具。
我认为没有人会要求您通过视频或屏幕截图来展示测试用例,但如果有必要,您可以查看几个库以获取 'video',因为这不是实际视频,而不是将一堆屏幕截图融合到一个视频中。
实际证明真正值得投入时间的是截取失败的测试用例截图并将其附加到测试用例结果中(Testrail、Bugzila、Extentreports 等等)。
实际上如果使用 selenium/appium 你可以检查这个 repo [https://github.com/groupon/Selenium-Grid-Extras] 他们制作 'video' 就像提到的那样并存储在本地 hub/node。
但是真正好的方法的最佳方法是报告每个测试用例的详细步骤:
带有详细步骤和操作的屏幕截图测试用例:
我在申请中处理报告的方式与 Kovacic 所说的一致。 我还使用 ExtentReports 作为生成指标并逐步记录发生的事情的方法。
我创建了一个负责记录步骤的方法(点击那个,导航到那里,断言...),如果需要可以选择截屏,另一个用于开始新测试。
然后,就是在 PageObject 样式测试框架中调用这些方法,并且几乎在您的框架执行的每个操作中调用这些方法。
为了更好地说明这里有一些实现示例 (c#):
记录一个步骤方法
public void LogStep(Status status,string MessageToLog, bool hasScreenshot)
{
//we leave the possibility of taking the screenshot with the step or not
if (hasScreenshot)
{
Test.Log(logstatus, messageToLog)
.AddScreenCaptureFromPath(GetScreenshot());
}
else
Test.Log(logstatus, messageToLog);
}
截屏方法
public static string GetScreenshot()
{
ITakesScreenshot ts;
//Browser.Driver here is the instance of the Driver you want to take screenshots with
ts = (ITakesScreenshot)Browser.Driver;
var screenshot = ts.GetScreenshot();
// Here just input the name you want your screenshot to have, with path
var screenshotPath = ScreenShotFolder + @"\" + _screenshotcount + ".bmp";
screenshot.SaveAsFile(screenshotPath);
// I've introduced a variable to keep track of the screenshot count (optional)
return (ScreenShotFolder.Substring(_reportRoot.Length) +"/"+ _screenshotcount + ".bmp");
}
框架调用示例[=43=]
public void BlockAccount()
{
try
{
_blockAccBtn.Click();
_confirmBtn.Click();
ExtentReportGenerator.LogStep(Status.Info, "Blocking Account");
}
catch (NoSuchElementException)
{
ExtentReportGenerator.LogStep(Status.Fail, "Could not find block button", true);
}
}
使用整个系统的NunitTest
[TestCase, Order(1)]
public void CanBlockCard()
{
//Creates a new test in the report
ExtentReportGenerator.Test = ExtentReportGenerator.Extent.CreateTest(GetCurrentMethod());
//Each one of these calls to the framework has logged steps
CashlessPages.CashlessAffiliationsPage.AccessAccount(1, 1);
CashlessPages.CashlessAccountsPage.BlockAccount();
Assert.IsTrue(CashlessPages.CashlessAccountsPage.IsAccBlocked());
}
生成的报告示例
希望对您有所帮助