Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I Just wanted to know, that how we can take a series of screenshots / a video recording for a screen using Selenium 2 / Web Driver with JAVA ?

Please provide the answer or the lick where I can get an idea about it ?

share|improve this question
    
Ok, I understand. Would you so kind to describe the search what you did before you ask? result of a simple search –  SayusiAndo Mar 5 at 12:17
1  
And to answer the rest of the question, Selenium/Webdriver does not provide an API for taking videos. You can use other software to take screen videos. For example, there's Camtasia for Windows/Mac. –  user246 Mar 5 at 12:42

2 Answers 2

Here is the method I use to take screenshots using webdriver:

 private void takeScreenShot(EPropertiesNames path, Integer... screenID)
{

    File directory = createFolder(path);
    try {
        // Toma la captura de imagen
        File imagen = ((TakesScreenshot) accesoWeb.getDriver()).getScreenshotAs(OutputType.FILE);
        StringBuilder sb = new StringBuilder(directory.getAbsolutePath());
        sb.append("\\");
        sb.append(testMethodName);
        if (screenID.length > 0) {
            sb.append("_");
            sb.append(screenID[0]);
        }
        sb.append(".png");
        FileUtils.copyFile(imagen, new File(sb.toString()));
        logger.info("Screenshot taken: " + testMethodName);
    } catch (IOException e) {
        logger.error("Error taking screenshot on error", e);
    }
}

private File createFolder(EPropertiesNames folderPath)
{
    String path = PropertiesManager.getInstance().getProperty(folderPath);
    File directoryDate = new File(path);
    try {
        if (!directoryDate.isDirectory()) {
            directoryDate.mkdirs();
        }
    } catch (Exception e) {
        logger.error("Error creating screenshot directory", e);
    }
    return directoryDate;
}

As for video recording never used it. I hope it helps.

Cheers.

share|improve this answer

Both Saucelabs and TestingBot provide a service which records your Selenium tests if you run them against their Selenium Grid. Both offer a number of free minutes per month, which might suffice your needs. You can view/download the video's straight after the test run is finished.

Although I don't know how their setup works, I think I can give you some idea's how to create something similar in your local environment.

  1. Start your test run from a build server (Jenkins for example)
  2. Let the build server start a Selenium server on the test node
  3. Let the build server start a screen recorder on the test node (With VLC for example)
  4. Start and run your (Java based) Selenium test against the test node
  5. Stop the recording on the test node
  6. Copy the recording to the build server so you can access it later on

For this you will need some infrastructure (servers) and some scripts to tie everything together, but its certainly not undoable.

Another option is to take a screenshot after each step/action and combine those screenshots into a video.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.