mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Use Android Test Orchestrator to have a clean state for each test
fixes flaky/broken espresso tests
This commit is contained in:
@@ -66,7 +66,6 @@ public class PromoVideoTest extends ScreenshotTest {
|
||||
@Override
|
||||
protected void inject(BriarUiTestComponent component) {
|
||||
component.inject(this);
|
||||
accountManager.deleteAccount();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.junit.ClassRule;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.test.ext.junit.rules.ActivityScenarioRule;
|
||||
import tools.fastlane.screengrab.FalconScreenshotStrategy;
|
||||
import tools.fastlane.screengrab.Screengrab;
|
||||
import tools.fastlane.screengrab.locale.LocaleTestRule;
|
||||
@@ -26,6 +27,10 @@ public abstract class ScreenshotTest extends UiTest {
|
||||
@Inject
|
||||
protected Clock clock;
|
||||
|
||||
protected void screenshot(String name, ActivityScenarioRule<?> rule) {
|
||||
rule.getScenario().onActivity(activity -> screenshot(name, activity));
|
||||
}
|
||||
|
||||
protected void screenshot(String name, Activity activity) {
|
||||
try {
|
||||
Screengrab.screenshot(name, new FalconScreenshotStrategy(activity));
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
import androidx.test.ext.junit.rules.ActivityScenarioRule;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.uiautomator.UiDevice;
|
||||
import androidx.test.uiautomator.UiObject;
|
||||
@@ -22,26 +22,22 @@ import static androidx.test.espresso.action.ViewActions.click;
|
||||
import static androidx.test.espresso.action.ViewActions.typeText;
|
||||
import static androidx.test.espresso.assertion.ViewAssertions.matches;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.isEnabled;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withId;
|
||||
import static androidx.test.espresso.matcher.ViewMatchers.withText;
|
||||
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
|
||||
import static org.briarproject.bramble.api.plugin.LanTcpConstants.ID;
|
||||
import static org.briarproject.briar.android.ViewActions.waitUntilMatches;
|
||||
import static org.briarproject.briar.android.util.UiUtils.needsDozeWhitelisting;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class SetupDataTest extends ScreenshotTest {
|
||||
|
||||
@Rule
|
||||
public IntentsTestRule<SetupActivity> testRule =
|
||||
new IntentsTestRule<SetupActivity>(SetupActivity.class) {
|
||||
@Override
|
||||
protected void beforeActivityLaunched() {
|
||||
super.beforeActivityLaunched();
|
||||
accountManager.deleteAccount();
|
||||
}
|
||||
};
|
||||
public ActivityScenarioRule<SetupActivity> testRule =
|
||||
new ActivityScenarioRule<>(SetupActivity.class);
|
||||
|
||||
@Override
|
||||
protected void inject(BriarUiTestComponent component) {
|
||||
@@ -59,7 +55,7 @@ public class SetupDataTest extends ScreenshotTest {
|
||||
onView(withId(R.id.nickname_entry))
|
||||
.perform(waitUntilMatches(withText(USERNAME)));
|
||||
|
||||
screenshot("manual_create_account", testRule.getActivity());
|
||||
screenshot("manual_create_account", testRule);
|
||||
|
||||
onView(withId(R.id.next))
|
||||
.check(matches(isDisplayed()))
|
||||
@@ -73,7 +69,7 @@ public class SetupDataTest extends ScreenshotTest {
|
||||
.check(matches(isDisplayed()))
|
||||
.perform(typeText(PASSWORD));
|
||||
onView(withId(R.id.next))
|
||||
.check(matches(isDisplayed()))
|
||||
.check(matches(allOf(isDisplayed(), isEnabled())))
|
||||
.perform(click());
|
||||
|
||||
// White-list Doze if needed
|
||||
@@ -94,14 +90,6 @@ public class SetupDataTest extends ScreenshotTest {
|
||||
lifecycleManager.waitForStartup();
|
||||
assertTrue(accountManager.hasDatabaseKey());
|
||||
createTestData();
|
||||
|
||||
// close expiry warning
|
||||
onView(withId(R.id.expiryWarning))
|
||||
.perform(waitUntilMatches(isDisplayed()));
|
||||
onView(withId(R.id.expiryWarningClose))
|
||||
.check(matches(isDisplayed()));
|
||||
onView(withId(R.id.expiryWarningClose))
|
||||
.perform(click());
|
||||
}
|
||||
|
||||
private void createTestData() {
|
||||
|
||||
@@ -14,7 +14,6 @@ import org.junit.runner.RunWith;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.test.espresso.contrib.DrawerActions;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.rule.ActivityTestRule;
|
||||
|
||||
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
@@ -38,8 +37,8 @@ import static org.junit.Assume.assumeTrue;
|
||||
public class SettingsActivityScreenshotTest extends ScreenshotTest {
|
||||
|
||||
@Rule
|
||||
public ActivityTestRule<SettingsActivity> testRule =
|
||||
new ActivityTestRule<>(SettingsActivity.class);
|
||||
public CleanAccountTestRule<SettingsActivity> testRule =
|
||||
new CleanAccountTestRule<>(SettingsActivity.class);
|
||||
|
||||
@Override
|
||||
protected void inject(BriarUiTestComponent component) {
|
||||
|
||||
Reference in New Issue
Block a user