Selenium:how to create test evidence report with NUnit

时光总嘲笑我的痴心妄想 提交于 2019-12-13 01:05:11

问题


I was wondering how one would create proper test evidence of Selenium UI tests.

I was thinking about screenshots but they do not actually cover everything you have done as it is difficult to determine when to screenshot. (Every click or every wait or every pageload).

Another option I thought about was screen recording, but this makes it rather difficult to work with parallelism as you record the whole screen and not a specific chrome window.

However, you could possibly also take a screenshot every second via the webdriver and turn this into a video. Then one would have to work with a separate thread which can be quite challenging considering the condition you have to provide to stop the thread from taking screenshots. Else the test will run forever.

As I was not able to draw a convincing conclusion based on my own thoughts about creating a test evidence report for UI tests I was hoping someone could explain to me how to properly do this.


回答1:


I had similar issue and I've introduced in my automation framework ExtentReports + klov server with Testrail as tool for test-management.

I think that nobody would ask of You to show testcases via video or screenshot, but if that is necessary, You can check out several libraries for taking 'video', because this is not actual video, than rather bunch of screenshots that are mashed into one video.

What has actually proven really good investment of time is to take fallen tests cases screenshot and attach it in testcase result (Testrail, Bugzila, Extentreports whatever).

Actualy if using selenium/appium You can check this repo [https://github.com/groupon/Selenium-Grid-Extras] they make 'video' like mentioned and stored on local hub/node.

But best menthod that has been real good method was report with detail steps of each testcase:

Screenshot testcase with detailed steps and action:




回答2:


The way I handled the reporting in my application goes in the line of what Kovacic said. I also used ExtentReports as a way to generate metrics and having a step by step record of what happened.

I created a method reponsible for recording a step ( clicked that, navigated there, asserting that... ) with the option of taking a screenshot if needed, and another one for starting a new test.

Then , it's a matter of calling those methods in the PageObject style testing framework and pretty much having those method called in every action made by your framework.

To better illustrate here are some implementation examples (c#) :

Log a step method

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

Screenshot capture method

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

Example of call in the framework

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

A NunitTest using the whole system

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

Example of generated Report

Hope this helps



来源:https://stackoverflow.com/questions/50227415/seleniumhow-to-create-test-evidence-report-with-nunit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!