Which is the best way to take a screenshot when one scenario fails using Robotium and Cucumber?
I have tried (without success, because it doesn't execute runTest method) with this:
import cucumber.api.CucumberOptions;
import cucumber.api.java.After;
import cucumber.api.java.Before;
@CucumberOptions(features = "features", tags = {"~@ignore"})
public class CustomInstrumentationTestCase extends ActivityInstrumentationTestCase2<LaunchActivity> {
protected Solo solo;
public CustomInstrumentationTestCase() {
super(LaunchActivity.class);
}
@Before
public void before() throws Exception {
//...
}
@After
public void after() throws Exception {
//...
}
@Override
protected void runTest() throws Throwable {
try {
super.runTest();
} catch (Throwable t) {
final String testCaseName = String.format("%s.%s", getClass().getName(), getName());
solo.takeScreenshot(testCaseName);
Log.w("Boom! Screenshot!", String.format("Captured screenshot for failed test: %s", testCaseName));
throw t;
}
}
}
And I have set the permissions in the manifest:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Your testclass seems fine. The runTest() methode is used to catch errors and failures and as a result make a screenshot.
To your class simply add a test like this:
Than run the test and you will find a screenshot.
Greetings
EDIT: Test for Screenshot: