【问题标题】:Selenium:how to create test evidence report with NUnitSelenium:如何使用 NUnit 创建测试证据报告
【发布时间】:2018-05-08 06:42:06
【问题描述】:

我想知道如何为 Selenium UI 测试创建适当的测试证据。

我在考虑截屏,但它们实际上并没有涵盖您所做的所有事情,因为很难确定何时截屏。 (每次点击或每次等待或每次页面加载)。

我想到的另一个选项是屏幕录制,但是当您录制整个屏幕而不是特定的 chrome 窗口时,这使得并行处理变得相当困难。

但是,您也可以通过网络驱动程序每秒截取一次屏幕截图并将其转换为视频。然后必须使用单独的线程,考虑到您必须提供的条件以阻止线程截屏​​,这可能会非常具有挑战性。否则测试将永远运行。

由于我无法根据自己关于为 UI 测试创建测试证据报告的想法得出令人信服的结论,因此我希望有人可以向我解释如何正确执行此操作。

【问题讨论】:

    标签: selenium selenium-webdriver automated-tests nunit ui-testing


    【解决方案1】:

    我有类似的问题,我在我的自动化框架 ExtentReports + klov 服务器中引入了 Testrail 作为测试管理工具。

    我认为没有人会要求您通过视频或屏幕截图显示测试用例,但如果有必要,您可以查看几个库以获取“视频”,因为这不是实际视频,而是一堆截图被混合成一个视频。

    实际证明非常好的时间投资是获取失败的测试用例截图并将其附加到测试用例结果中(Testrail、Bugzila、Extentreports 等等)。

    实际上如果使用 selenium/appium 你可以查看这个 repo [https://github.com/groupon/Selenium-Grid-Extras] 他们制作提到的“视频”并存储在本地集线器/节点上。

    但真正好的方法的最佳方法是报告每个测试用例的详细步骤:

    带有详细步骤和操作的屏幕截图:

    【讨论】:

    • 非常感谢。 ExtentReports 正是我一直在寻找的。​​span>
    • 很高兴能帮上忙。谢谢
    【解决方案2】:

    我在申请中处理报告的方式与 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");
    }
    

    框架中的调用示例

      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());
        }
    

    生成的报告示例

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多