Knowledge Base Article

Home Page > Knowledge Base > Rapise

Article Capture Screenshots During Playback

by Jim R. on Friday, February 20, 2015

When playing back a test it is useful to be able to capture the screen as its current state so that the cause of any test failures can be more easily deduced.

Current Versions of Rapise

With versions 1.4 and later of Rapise you can instruct Rapise to capture screenshots during either recording or playback by simply changing the “Screen Capture” settings of your test:

  • Capture Execution: Set this to True if you want to save screen images for each recognized object during playback.
  • Capture Recording: Set this to True if you want to save screen images for each action during recording.
  • Include in Report: Set this to True to include the saved images in the execution report during playback.
  • Widget Only: Set this to True to only save the widget area in the screenshot, as opposed to the whole window.

Each screenshot is saved to the report file (by means of Tester.Message). For each playback session the sub-folder is created with name: <test name>/Reports/YYYY-MM-DD_HH-mm-ss. The contents of this folder are: the index file, Report.html and a sequence of image files named StepNNN.png.

If you are using RapiseLauncher to execute tests remotely using SpiraTest then the captured screenshots can also be uploaded automatically into SpiraTest so that you have a permanent record of the test execution including associated screenshots.

Rapise v1.3.x or Older

The Rapise API allow you to easily capture page screenshots during test playback. To do this put the following snippet of code into your <testname>.user.js file:

 
 

var g_ses_withoutScreenshots;

if(typeof(SeS)!="undefined")

{

      g_ses_withoutScreenshots = SeS;

}

var g_saveHtml = true;

var g_objectStepId = 1;

var g_reportHtmlPath = null;

 

function SeSWithScreenshots(/**String*/ obj, /**params*/params) /**SeSObject*/

{

            var img = new ActiveXObject("SeSWrappers.Utils.ImageWrapper");

 

            var res = g_ses_withoutScreenshots(obj, params);

 

            if(!g_reportHtmlPath)

            {

                        var d = new Date();

                        var strDateTime = d.getFullYear()+"-"+(d.getMonth() + 1)+"-"+d.getDate()+"_"+d.getHours()+"-"+d.getMinutes()+"-"+d.getSeconds();

 

                        g_reportHtmlPath = Global.GetFullPath('Reports\\'+strDateTime);

 

                        g_helper.CreateFolder(g_reportHtmlPath);

 

                        g_helper.FileWrite(g_reportHtmlPath+"\\Save.html", "<h1>Report</h1>\n");

                        Tester.Message('Screen flow', new SeSReportLink(g_reportHtmlPath+"\\Save.html"));

            }

 

            if(!res||res.IsMissing)

            {

                        var /**HWNDWrapper*/desktopWnd = g_util.GetDesktopWindow();

 

                        img.Capture(desktopWnd.PosX, desktopWnd.PosY, desktopWnd.PosWidth, desktopWnd.PosHeight);

                        Tester.Message('Object not found: '+obj, new SeSReportImage(img, "Desktop"), {screen: g_objectStepId});

 

                        if(g_saveHtml)

                        {

                                    var strImgName = "Step"+g_objectStepId+".png";

                                    g_helper.FileWrite(g_reportHtmlPath+"\\Save.html", "<h3>"+g_objectStepId+" Object not found:"+obj+"</h3>\n<img src='"+strImgName+"'/>\n");

                                    img.Save(g_reportHtmlPath+"\\"+strImgName);

                        }

 

            } else {

                        var /**HWNDWrapper*/topWnd = res.getDesktopWindow();

 

                        img.Capture(topWnd.PosX, topWnd.PosY, topWnd.PosWidth, topWnd.PosHeight);

                        Tester.Message('Object found: '+obj, new SeSReportImage(img, obj.object_id), {screen: g_objectStepId});

 

                        if(g_saveHtml)

                        {

                                    var strImgName = "Step"+g_objectStepId+".png";

                                    g_helper.FileWrite(g_reportHtmlPath+"\\Report.html", "<h3>"+g_objectStepId+" Object found:"+obj+"</h3>\n<img src='"+strImgName+"'/>\n");

                                    img.Save(g_reportHtmlPath+"\\"+strImgName);

                        }

            }

            g_objectStepId++;

 

            return res;

}

 

if(typeof(SeS)!="undefined")

{

    SeS=SeSWithScreenshots;

}

 
 

How Screenshot Capture Works

Each time object recognition is performed (by means of the SeS function) during test playback, the screenshot is automatically taken. If the object recognition is successful then the screenshot is taken for the current application window only. If it is not successful then the screenshot is taken of the whole screen.

Each screenshot is saved to the report file (by means of Tester.Message). For each playback session the sub-folder is created with name: <test name>/Reports/YYYY-MM-DD_HH-mm-ss. The contents of this folder are: the index file, Report.html and a sequence of image files named StepNNN.png.

This function may be extended in a number of different ways. For example, it is possible to modify the function to only capture screenshots when a given object is not found in the application under test.

 

Attachments
Article Info
Last Updated: 2/20/2015
Article ID: KB120
# Views: 1150
Powered by KronoDesk v1.1.0.15 | © Copyright Inflectra Corporation 2011-2016 | Licensed to Inflectra Corporation.