Forum Discussion

blearyeye4's avatar
blearyeye4
Occasional Contributor
13 years ago

Capture screen shot in script

I'm using JScript. I write my scripts from scratch (usually not using recording). At times, I want to take a screen shot for the log. How can I do that?



Also, can I specify that I always want screen shots for log checkpoints and errors?
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    For your first question, simply "Log.Picture(Object)" will take such a screenshot.



    As for your second question, there are two things.  There's an option in your Project Properties under the Playback (Tools | Current Project Properties | Playback) for "Post image on error".  Anytime an error is logged using either Log.Error or generated by some other method, a screenshot will be written to the log capturing the whole desktop.  For checkpoints, you can use the OnLogCheckpoint event handler to control what happens when you execute a checkpoint result to the log.
  • blearyeye4's avatar
    blearyeye4
    Occasional Contributor
    It looks like Log.Picture is used to add an existing picture to the log. I don't see how to generate a screen shot.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    As per the help:



    [quote] Alternatively, this can be an object that has the Picture method which returns the desired Picture object.[/quote\



    So, if you do the following 



    function Yada()

    {

        Log.Picture(Sys.Desktop, "My Desktop")

    }




    This will take a picture of your current desktop.  The same could be for any object that is visible on screen as TestComplete usually wraps it with a "Picture" method that will be called to capture the screenshot.



    So, say I have a button on a web page, I could call



    function yada()

    {

         Log.Picture(Aliases.iexplore.page("*").MyPanel.MyButton, "My button screenshot")

    }
  • Hi,


    To capture screenshots for test operations during the test run, you can also use the Test Visualizer feature. To enable Test Visualizer, use the Visualizer properties of your test project.

  • blearyeye4's avatar
    blearyeye4
    Occasional Contributor
    Thanks to both of you. Looks like that's just what I need.
  • samuel_1's avatar
    samuel_1
    Occasional Contributor

    Hi


    i enabled the "post image on error" option


    and on TC it does post image in log


    but


    on TE it does as well but the link is not working, or the path to the picture is wrong


    what to do?


  • Hi Samuel,





    I have just checked this scenario in TestExecute 8.70, and it works just fine - I see the pictures in the Test Log exported by TestExecute.





    What TestExecute version are you using?

    Could you try using version 8.70, and let me know the results?

    If the problem persists in version 8.70, could you post here is a simple test project demonstrating the problematic behavior?
  • Here is my code for taking a screenshot. Its in C# but that will run in a Jscript project (or pretty easy to convert).

    It will screenshot the entire desktop if you just call it without any parameters (ie takeScreenshoot();) or you can pass in any reference to a mapped object etc to have it screenshot just that.  It will also log a message before it places the screenshot in the log.  The syntax actually came from the help files somewhere (cant remember where - I dont think it was on the pages about logging or taking screenshots)



    function takeScreenshot(objectToScreenshot)

      {

      

      if(objectToScreenshot==null)

        {

        Log["Checkpoint"]("Taking a screenshot of the entire desktop")

        Sys["Clipboard"] = Sys["Desktop"]["Picture"]();

        Log["Picture"](Sys["Clipboard"]);

        }

      else

        {

        Log["Message"]("Taking a picture of " + objectToScreenshot)

        Log["Picture"](objectToScreenshot);

        }

      }