Screenshooter
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:
-
Arquillian Graphene screenshooter - desktop browser level screenshots of your web app, taken while running Graphene (aka WebDriver on steroids) functional tests
-
Arquillian Droidium screenshooter - mobile level screenshots both of your Android native and web apps, taken while running Droidium functional tests
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.
-
First step is to add particular screenshooter on the CLASS PATH. See documentation for your favorite screenshooter for more details.
-
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 |
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 } }
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() { } }
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