Features

Taking screenshots

During your Automated Testing, you can take screenshots of the current webpage by issuing a "Take Screenshot" command.
Depending on which framework/language binding you are using, the syntax might be a little bit different.

If you want to automatically take a screenshot for each step in your test, you can use the custom screenshot TestingBot capability.

Copy code
driver.save_screenshot("screenshot.png")
Copy code
driver = (RemoteWebDriver) new Augmenter().augment(driver);
File srcFile = (File) ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileHandler.copy(srcFile, new File("/location/to/screenshot.png"));
Copy code
file_put_contents('screenshot.png', $web_driver->takeScreenshot());
Copy code
driver.save_screenshot('screenshot.png')
Copy code
const fs = require('fs')

webdriver.WebDriver.prototype.saveScreenshot = function(filename) {
  return driver.takeScreenshot().then(function(data) {
      fs.writeFile(filename, data.replace(/^data:image\/png;base64,/,''), 'base64', function(err) {
          if(err) throw err
      })
  })
}

driver.saveScreenshot('screenshot.png')
Copy code
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;

namespace SeleniumTest
{
    public class ScreenShotRemoteWebDriver : RemoteWebDriver, ITakesScreenshot
    {
        public ScreenShotRemoteWebDriver(Uri uri, OpenQA.Selenium.Chrome.ChromeOptions dc)
          : base(uri, dc)
        {
        }

        public new Screenshot GetScreenshot()
        {
            Response screenshotResponse = this.Execute(DriverCommand.Screenshot, null);
            string base64 = screenshotResponse.Value.ToString();
            return new Screenshot(base64);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            ScreenShotRemoteWebDriver driver;
            OpenQA.Selenium.Chrome.ChromeOptions capability = new OpenQA.Selenium.Chrome.ChromeOptions();
            capability.AddAdditionalCapability("browserName", "Chrome", true);
            capability.AddAdditionalCapability("version", "latest", true);
            capability.AddAdditionalCapability("platform", "WIN10", true);
            capability.AddAdditionalCapability("key", "key", true);
            capability.AddAdditionalCapability("secret", "secret", true);
            capability.AddAdditionalCapability("chromeOptions", chromeOptions, true);
            
            driver = new ScreenShotRemoteWebDriver(
                new Uri("https://hub.testingbot.com/wd/hub/"), capability
            );
            driver.Navigate().GoToUrl("https://www.google.com/ncr");
            Console.WriteLine(driver.Title);

            IWebElement query = driver.FindElement(By.Name("q"));
            query.SendKeys("TestingBot");
            query.Submit();
            Console.WriteLine(driver.Title);

            ITakesScreenshot screenshotDriver = driver as ITakesScreenshot;
            Screenshot screenshot = screenshotDriver.GetScreenshot();
            screenshot.SaveAsFile("/tmp/screenshot.png", OpenQA.Selenium.ScreenshotImageFormat.Png);

            driver.Quit();
        }
    }
}