Skip to content

Instantly share code, notes, and snippets.

@smiklosovic
Last active December 19, 2015 15:09
Show Gist options
  • Save smiklosovic/5974532 to your computer and use it in GitHub Desktop.
Save smiklosovic/5974532 to your computer and use it in GitHub Desktop.
Initial idea how to get screenshots in tests, very handy in Arquillian Droidium environment.
@RunWith(Arquillian.class)
// when this annotation is omitted, images will be saved into
// default location, like target/screenshots
@SaveScreenShotsTo("target/my-screenshots/ArquillianScreenShooterTestCase/")
// when no @TakeScreenShots are specified on method, this one will be used by default
@TakeScreenShots(BeforeAsserts.class)
public class ArquillianScreenShooterTestCase {
@Drone WebDriver driver
@Deployment
public static Archive<?> getDeployment() {
// ShrinkWrap gets deployment
}
/**
* Screenshots will be taken and put into @SaveScreenShotsTo in some format
* (e.g.) some target/screenshots/SomeTestCase/test01/screenshot-#.png
* where # is a placeholder for a number of screenshot taken in the method.
*
* Screenshots will be taken before and after the calling of method from Assert class.
*/
@Test
@TakeScreenShots({BeforeAssert.class, AfterAssert.class})
public void test01() {
Assert.assertTrue("some test");
}
/**
* Just before asserts, annotation of @SaveScreenShotsTo overrides
* class annotation when specified.
*
*/
@Test
@TakeScreenShots(BeforeAssert.class)
@SaveScreenShotsTo("target/someOtherLocation/")
public void test02() {
Assert.assertFalse("some test");
}
}
@TadeasKriz
Copy link

I'd make it @TakeScreenShots instead of @GetScreenShots. But for everything else +1!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment