Skip to content
Matous Jobanek edited this page Sep 30, 2015 · 14 revisions

Not just API

In this repository you can find just high level API for implementing a whatever screenshooter you like. In the same time we are providing you two implementations, which differs in the platforms they are intended to be used for:

Configuration

Here you can find common configuration for all screenshooters. Some implementations has their specifics, to see them, please visit documentation for the particular screenshooter from above.

  1. First step is to add particular screenshooter on the CLASS PATH. See documentation for your favorite screenshooter for more details.

  2. Then following arquillian.xml properties are supported within screenshooter qualifier:

Configuration Property Description Default Value

takeBeforeTest

take a screenshot before testing begin (e.g. when testing web app, it is just after page is loaded)

false

takeAfterTest

take a screenshot as the last action in the test execution (even if the test fails)

false

takeWhenTestFailed

take a screenshot only when the test failed

true

rootDir

folder where all screenshots will be placed

target

screenshotType

type of taken image

PNG

Test method-level configuration

While taking screenshots, besides screenshooter configuration in arquillian.xml, you can specify your preferencies regarding of screenshot taking directly on methods by Screenshot annotation put on particular test method. Doing so will override your global configuration in arquillian.xml. Lets see an example:

Configuration in arquillian.xml:

<extension qualifier="screenshooter">
    <property name="takeBeforeTest">false</property>
    <property name="takeAfterTest">false</property>
    <property name="takeWhenTestFailed">false</property>
</extension>

Possible test case with supressed configuration by Screenshot annotation:

@RunWith(Arquillian.class)
@RunAsClient
public class TestCase
{
    @Test
    @Screenshot(
        takeBeforeTest = true,
        takeAfterTest = true,
        takeWhenTestFailed = false)
    public void test01()
    {
        // screenshots will be taken before and after test
    }

    @Test
    @Screenshot // takeWhenTestFailed is by default true
    public void test02()
    {
        // suppose this test fails so screenshot will be taken
    }

    @Test
    public void test03()
    {
        // configuration taken from arquillian.xml
    }
}

Blurring screenshots

Sometimes for privacy reasons, it may be required to blur screenshots. Arquillian Recorder has @Blur annotation to set that screenshot should be blurred.

With @Blur you can set the level of blurring you want to apply: NONE, LOW (default), MEDIUM or HIGH.

The annotation can be place only in one test method to blur only screenshots taken during that test execution or at class level to blur all screenshots.

An example of usage:

pubic class TestClass
{

    @Blur(BlurLevel.LOW)
    public void test()
    {

    }
}

Manually taking screenshots

Screenshots can be taken also manually. Screenshots are taken via injected Screenshooter into test method (or test class). You take screenshots like follows:

@ArquillianResource Screenshooter screenshooter;

@Test
public void test()
{
  //same testing here
  screenshooter.takeScreenshot();
  //some testing over here as well;
}

Screenshot is saved by default to target/ directory. You can set where to save all subsequently taken screenshots by calling, for example

screenshooter.setScreenshotTargetDir("target/some_dir");

You can take screenshots of different formats. Default format is PNG. You can take PNG, GIF, JPEG, BMP and WBMP. The format of the screenshot is specified when you take screenshot like

screenshooter.takeScreenshot(ScreenshotType.GIF)

File name of screenshot is by default a random string. You can name it like

screenshooter.takeScreenshot("myScreenshot", ScreenshotType.GIF);
screenshooter.takeScreenshot("myScreenshot2"); // taken as PNG

You can set the format of screenshots you want to take explicitly. From that point, all screenshots will be of that format when not specified otherwise.

screenshooter.setScreensthotType(ScreenshotType.BMP);
// all screenshots will be by default BMP images from now on