How to screencast automated tests using Java? [closed]
Asked Answered
H

6

12

I am currently working on automating my tests using Selenium with TestNg and Java. I am able to take screenshot while the tests are running, but there are some situations where the test passes when ideally it should have failed.

So, Is there any java tool that can help in recording the running Selenium tests?

Basically, I want to add screen-cast to my framework. I searched a lot on web/SO but could not find any relevant resources. Any help or suggestion is welcome.

Hueston answered 20/11, 2015 at 14:58 Comment(3)
ok 2 questons. Do you mean record a video by screencast ? Are you using grid ?Crofter
Yes. Record the video. Not using the grid, but using an in-house framework.Hueston
Not quite an answer to your question, but sort of an alternative idea. From my experience, even seeing test run interactively may not help, because you don't see why something happened or didn't happen (i.e. you see UI, but not DOM of the HTML). And secondly, it's hard to synch up what script is doing with screen recording, you can only assume. So what I found more helpful is 1 - saving contents of the HTML at various problematic stages (driver.getPageSource()); and 2 - investing into logging that makes it clear what test is doing at every moment and why it takes this or the other pathGuilford
C
4

You can use java code record your Test video, for this code to run you also need to add jar file to your project : Reference : Road to automation

@BeforeSuite
        public void startRecording() throws Exception {    

           GraphicsConfiguration gc = GraphicsEnvironment
                   .getLocalGraphicsEnvironment()
                   .getDefaultScreenDevice()
                   .getDefaultConfiguration();

               this.screenRecorder = new ScreenRecorder(gc,
                   new Format(MediaTypeKey, MediaType.FILE, MimeTypeKey, MIME_AVI),
                   new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE,
                        CompressorNameKey, ENCODING_AVI_TECHSMITH_SCREEN_CAPTURE,
                        DepthKey, 24, FrameRateKey, Rational.valueOf(15),
                        QualityKey, 1.0f,
                        KeyFrameIntervalKey, 15 * 60),
                   new Format(MediaTypeKey, MediaType.VIDEO, EncodingKey, "black",
                        FrameRateKey, Rational.valueOf(30)),
                   null);
       this.screenRecorder.start();

    }

    @AfterSuite
    public void stopRecording() throws Exception {
      this.screenRecorder.stop();
    }
Cyst answered 1/12, 2015 at 10:46 Comment(0)
T
3

An another option would be to run your tests remotely on BrowserStack or Sauce Labs - both services have test run Video Recording available.

Tetrameter answered 24/11, 2015 at 15:2 Comment(1)
We already used Saucelabs to run tests remotely, but they end up being costly for regular test suite runs.Hueston
S
2

One approach would be to do screenshot after each step and then combining them into a video. The answers to this questions provide a couple of candidate libraries for this task.

Another idea would be to actually do a screencast while performing the test, using some browser plugin. But I'm not sure how one would start the recording process. It might be possible to send the short cut for start/stop recording with selenium, but I'm not sure if that would work. For such plugins I can't offer more than a google search

Selfdetermination answered 24/11, 2015 at 10:54 Comment(2)
Thanks for the link. I used Xuggler to create a video, but it is not integrating well with my framework due to multiple screenshot taken. Can you also suggest some tool that itself record video?Hueston
Updated my answer to reflect what little I can offer in that directionSelfdetermination
H
2

You could check out Selenium-Grid-Extras, created and used by Groupon. They've build a framework which is capable of doing what your describing using Selenium Grid. I tried it myself once and seemed to work fine. Maybe it's something that would suit your needs.

Heartrending answered 25/11, 2015 at 15:55 Comment(1)
I would give it a try. But, I am looking for a screencast tool, not exactly a new framework. Thanks anyways.Hueston
S
1

I will take thebobblob's answer little further. I recetly configured selenium grid-hub environment with groupon's Selenium-Grid_Extras and it works like charm. There are few questions that you need to answer while setting up the nodes/hub for the first time. After running java -jar Selenium-Grid-Extras-Jar.jar at some point it asks you the number of video you want to record which is by default 20. After, the test run all the recording are accessible through hub:port as shown here

Taking it to little further, you can control the recording from your test using groupon api. You have the flexibility. There is an open issue but it gives you the option to manipulate that as well through rest service

Sancho answered 1/12, 2015 at 5:11 Comment(0)
S
0

You can use a Robot class to take a screen shot automaticaly from your java code when you need it. It is part of java standard library.

Create the Robot at the beginnig of your test:

Rectangle screen =  new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
Robot robot = new Robot();

Then when you need to take a screenshot (every step in your test) just call:

    BufferedImage capture = robot.createScreenCapture(screen);
    ImageIO.write(capture, "jpg", new File("c:/some_distinct_name_designating_test_phase_and_number.jpg"));
Snitch answered 1/12, 2015 at 9:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.