Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Screen capture during testing

Tags:

testing

wpf

This is an application for reviewing performance tests. Simple in concept, tricky to describe. Picture:

1) Recording interactions with a WPF program so the inputs can be played back.

2) Playing the inputs back while doing a continuous screen capture.

3) Capturing wall time as well as continuous CPU percentages during playback.

4) Repeating steps (2) and (3) lots of times.

5) Writing the relevant stuff out to files/db.

6) Reading it and putting it all in a fancy UI for easy review/analysis.

The killer for me is (2). I could use some guidance on a good, possibly commercial, screen capture SDK. I would also welcome the news that my whole problem already has a solution. And of course any thoughts on the overall idea would also be great.

Thanks.

Ed

like image 711
Edwward Avatar asked May 13 '10 19:05

Edwward


People also ask

Can online test detect screenshots?

That depends on the software installed on the computer, for all you know every key stroke is being recorded. The webcam might even be spying on you. Good reason to block cameras with something if you are on an unknown computer. If there is a mic it could be listening in on you.

Why is screenshot required in automation testing?

Why is Screenshot required in Automation testing? As we know, one of the primary purposes of automation testing is to reduce manual effort. Therefore, the use of a screenshot captured during automated test runs becomes very useful. You would not want to monitor your application every time the tests are executed.

What is screen capture used for?

To put it simply, screen capture is a type of clipping that enables users to display the contents on their computer screen on a video stream, webpage or document. Screen capture is a great feature if you want to be able to save a picture of your computer desktop and save it as a file on your computer.

How do I take a screenshot of a test complete?

To create a snapshot from the Object BrowserClick the Save Object Snapshot button on the Save/Load Snapshots toolbar. If the toolbar is hidden, right-click somewhere within the TestComplete toolbar or menu area and select Save/Load Snapshots from the pop-up list. This will open the Save Object Snapshot dialog.


2 Answers

If you are going to do development for this, you can setup Cucumber / SpecFlow using Windows Automation... and here's a sample in WPF of taking a screenshot of the App under test.

        /// <summary>
        /// Take screen shot
        /// </summary>
        /// <param name="left">left</param>
        /// <param name="top">top</param>
        /// <param name="width">width</param>
        /// <param name="height">height</param>
        /// <returns>screen shot in bytes</returns>
        public static byte[] TakeScreenShot(int left, int top, int width, int height)
        {
            // Set the bitmap object to the size of the screen
            var bmpScreenshot = new Bitmap(width, height,
                                                  PixelFormat.Format32bppArgb);

            // Create a graphics object from the bitmap
            var gfxScreenshot = Graphics.FromImage(bmpScreenshot);

            // Take the screenshot from the upper left corner to the right bottom corner
            gfxScreenshot.CopyFromScreen(left, top, 0, 0,
                                             new Size(width, height), CopyPixelOperation.SourceCopy);

            var buffer = new byte[bmpScreenshot.Size.Height * bmpScreenshot.Size.Width * 4];

            var stream = new MemoryStream(buffer);

            bmpScreenshot.Save(stream, ImageFormat.Png);

            return stream.ToArray();
        }
like image 195
Sean B Avatar answered Oct 02 '22 04:10

Sean B


You can do the screen capture in your own application using DirectShow.

See Video Capture for general details on how to do video capture using DirectShow and links to example code. To capture specifically from the screen you'll need the "Screen Capture filter" filter found in wmpsrcwp.dll, which is found in newer versions of Windows and can also be downloaded as part as the Windows Media Encoder.

Although UI Automation can be used to play back events, it cannot record. If you need to record system events, I recommend you use Windows Hooks for both recording and playback.

DirectShow is easiest to do in C++/CLR instead of C# because you can easily include C++ header files and make unmanaged calls, and Windows Hooks should only be done in native code.

like image 42
Ray Burns Avatar answered Oct 02 '22 04:10

Ray Burns