mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 14:02:49 +00:00
Capture screenshots of failing instrumented tests
This commit is contained in:
parent
fff81b0ee3
commit
1dcf56a0fa
5 changed files with 55 additions and 4 deletions
|
@ -37,6 +37,7 @@ import com.beemdevelopment.aegis.encoding.Hex;
|
|||
import com.beemdevelopment.aegis.importers.DatabaseImporter;
|
||||
import com.beemdevelopment.aegis.importers.DatabaseImporterException;
|
||||
import com.beemdevelopment.aegis.importers.GoogleAuthUriImporter;
|
||||
import com.beemdevelopment.aegis.rules.ScreenshotTestRule;
|
||||
import com.beemdevelopment.aegis.ui.PreferencesActivity;
|
||||
import com.beemdevelopment.aegis.util.IOUtils;
|
||||
import com.beemdevelopment.aegis.vault.VaultBackupManager;
|
||||
|
@ -56,6 +57,8 @@ import org.junit.After;
|
|||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.RuleChain;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -74,8 +77,10 @@ import dagger.hilt.android.testing.HiltAndroidTest;
|
|||
@HiltAndroidTest
|
||||
@SmallTest
|
||||
public class BackupExportTest extends AegisTest {
|
||||
private final ActivityScenarioRule<PreferencesActivity> _activityRule = new ActivityScenarioRule<>(PreferencesActivity.class);
|
||||
|
||||
@Rule
|
||||
public final ActivityScenarioRule<PreferencesActivity> activityRule = new ActivityScenarioRule<>(PreferencesActivity.class);
|
||||
public final TestRule testRule = RuleChain.outerRule(_activityRule).around(new ScreenshotTestRule());
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
|
|
@ -18,6 +18,7 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule;
|
|||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.filters.LargeTest;
|
||||
|
||||
import com.beemdevelopment.aegis.rules.ScreenshotTestRule;
|
||||
import com.beemdevelopment.aegis.ui.IntroActivity;
|
||||
import com.beemdevelopment.aegis.vault.VaultRepository;
|
||||
import com.beemdevelopment.aegis.vault.slots.BiometricSlot;
|
||||
|
@ -26,6 +27,8 @@ import com.beemdevelopment.aegis.vault.slots.SlotList;
|
|||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.RuleChain;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import dagger.hilt.android.testing.HiltAndroidTest;
|
||||
|
@ -34,8 +37,10 @@ import dagger.hilt.android.testing.HiltAndroidTest;
|
|||
@HiltAndroidTest
|
||||
@LargeTest
|
||||
public class IntroTest extends AegisTest {
|
||||
private final ActivityScenarioRule<IntroActivity> _activityRule = new ActivityScenarioRule<>(IntroActivity.class);
|
||||
|
||||
@Rule
|
||||
public final ActivityScenarioRule<IntroActivity> activityRule = new ActivityScenarioRule<>(IntroActivity.class);
|
||||
public final TestRule testRule = RuleChain.outerRule(_activityRule).around(new ScreenshotTestRule());
|
||||
|
||||
@Test
|
||||
public void doIntro_None() {
|
||||
|
|
|
@ -29,6 +29,7 @@ import com.beemdevelopment.aegis.otp.HotpInfo;
|
|||
import com.beemdevelopment.aegis.otp.SteamInfo;
|
||||
import com.beemdevelopment.aegis.otp.TotpInfo;
|
||||
import com.beemdevelopment.aegis.otp.YandexInfo;
|
||||
import com.beemdevelopment.aegis.rules.ScreenshotTestRule;
|
||||
import com.beemdevelopment.aegis.ui.MainActivity;
|
||||
import com.beemdevelopment.aegis.vault.VaultEntry;
|
||||
import com.beemdevelopment.aegis.vault.VaultRepository;
|
||||
|
@ -36,6 +37,8 @@ import com.beemdevelopment.aegis.vault.slots.PasswordSlot;
|
|||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.RuleChain;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -50,8 +53,10 @@ import dagger.hilt.android.testing.HiltAndroidTest;
|
|||
public class OverallTest extends AegisTest {
|
||||
private static final String _groupName = "Test";
|
||||
|
||||
private final ActivityScenarioRule<MainActivity> _activityRule = new ActivityScenarioRule<>(MainActivity.class);
|
||||
|
||||
@Rule
|
||||
public final ActivityScenarioRule<MainActivity> activityRule = new ActivityScenarioRule<>(MainActivity.class);
|
||||
public final TestRule testRule = RuleChain.outerRule(_activityRule).around(new ScreenshotTestRule());
|
||||
|
||||
@Test
|
||||
public void doOverallTest() {
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package com.beemdevelopment.aegis.rules;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import androidx.test.runner.screenshot.BasicScreenCaptureProcessor;
|
||||
import androidx.test.runner.screenshot.ScreenCapture;
|
||||
import androidx.test.runner.screenshot.ScreenCaptureProcessor;
|
||||
import androidx.test.runner.screenshot.Screenshot;
|
||||
|
||||
import org.junit.rules.TestWatcher;
|
||||
import org.junit.runner.Description;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class ScreenshotTestRule extends TestWatcher {
|
||||
@Override
|
||||
protected void failed(Throwable e, Description description) {
|
||||
super.failed(e, description);
|
||||
|
||||
String filename = description.getTestClass().getSimpleName() + "-" + description.getMethodName();
|
||||
|
||||
ScreenCapture capture = Screenshot.capture();
|
||||
capture.setName(filename);
|
||||
capture.setFormat(Bitmap.CompressFormat.PNG);
|
||||
|
||||
HashSet<ScreenCaptureProcessor> processors = new HashSet<>();
|
||||
processors.add(new BasicScreenCaptureProcessor());
|
||||
|
||||
try {
|
||||
capture.process(processors);
|
||||
} catch (IOException e2) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue