mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-08-03 18:56:44 -04:00
replace ActivityTestRule with BaristaRule and remove all thread.sleep() statements
This commit is contained in:
parent
a23c7d6af9
commit
87239ce67a
@ -29,6 +29,7 @@ import android.test.suitebuilder.annotation.LargeTest;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewParent;
|
import android.view.ViewParent;
|
||||||
|
import com.schibsted.spain.barista.interaction.BaristaSleepInteractions;
|
||||||
import com.schibsted.spain.barista.rule.BaristaRule;
|
import com.schibsted.spain.barista.rule.BaristaRule;
|
||||||
import org.hamcrest.Description;
|
import org.hamcrest.Description;
|
||||||
import org.hamcrest.Matcher;
|
import org.hamcrest.Matcher;
|
||||||
@ -59,6 +60,8 @@ import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
|||||||
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
import static android.support.test.espresso.matcher.ViewMatchers.withText;
|
||||||
import static org.hamcrest.Matchers.allOf;
|
import static org.hamcrest.Matchers.allOf;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
|
import static org.hamcrest.core.IsNull.notNullValue;
|
||||||
|
import static org.kiwix.kiwixmobile.testutils.TestUtils.TEST_PAUSE_MS;
|
||||||
|
|
||||||
@LargeTest
|
@LargeTest
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
@ -84,40 +87,13 @@ public class HelpActivityTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHelpActivity() {
|
public void testHelpActivity() {
|
||||||
|
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
|
||||||
activityTestRule.launchActivity();
|
onView(withId(R.id.get_started)).check(matches(notNullValue()));
|
||||||
|
onView(withId(R.id.get_started)).perform(click());
|
||||||
|
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
|
||||||
ViewInteraction appCompatButton = onView(
|
|
||||||
allOf(withId(R.id.get_started), withText("Get started"),
|
|
||||||
childAtPosition(
|
|
||||||
childAtPosition(
|
|
||||||
withId(android.R.id.content),
|
|
||||||
0),
|
|
||||||
1),
|
|
||||||
isDisplayed()));
|
|
||||||
appCompatButton.perform(click());
|
|
||||||
|
|
||||||
// Added a sleep statement to match the app's execution delay.
|
|
||||||
// The recommended way to handle such scenarios is to use Espresso idling resources:
|
|
||||||
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
|
|
||||||
try {
|
|
||||||
Thread.sleep(10000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
|
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
|
||||||
|
|
||||||
// Added a sleep statement to match the app's execution delay.
|
|
||||||
// The recommended way to handle such scenarios is to use Espresso idling resources:
|
|
||||||
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
|
|
||||||
try {
|
|
||||||
Thread.sleep(10000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewInteraction appCompatTextView = onView(
|
ViewInteraction appCompatTextView = onView(
|
||||||
allOf(withId(R.id.title), withText("Help"),
|
allOf(withId(R.id.title), withText("Help"),
|
||||||
childAtPosition(
|
childAtPosition(
|
||||||
@ -128,14 +104,8 @@ public class HelpActivityTest {
|
|||||||
isDisplayed()));
|
isDisplayed()));
|
||||||
appCompatTextView.perform(click());
|
appCompatTextView.perform(click());
|
||||||
|
|
||||||
// Added a sleep statement to match the app's execution delay.
|
|
||||||
// The recommended way to handle such scenarios is to use Espresso idling resources:
|
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
|
||||||
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
|
|
||||||
try {
|
|
||||||
Thread.sleep(20000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewInteraction textView = onView(
|
ViewInteraction textView = onView(
|
||||||
allOf(withText("Help"),
|
allOf(withText("Help"),
|
||||||
@ -159,14 +129,8 @@ public class HelpActivityTest {
|
|||||||
isDisplayed()));
|
isDisplayed()));
|
||||||
imageButton.check(matches(isDisplayed()));
|
imageButton.check(matches(isDisplayed()));
|
||||||
|
|
||||||
// Added a sleep statement to match the app's execution delay.
|
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
|
||||||
// The recommended way to handle such scenarios is to use Espresso idling resources:
|
|
||||||
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
|
|
||||||
try {
|
|
||||||
Thread.sleep(40000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewInteraction appCompatImageButton = onView(
|
ViewInteraction appCompatImageButton = onView(
|
||||||
allOf(withContentDescription("Navigate up"),
|
allOf(withContentDescription("Navigate up"),
|
||||||
@ -179,14 +143,8 @@ public class HelpActivityTest {
|
|||||||
isDisplayed()));
|
isDisplayed()));
|
||||||
appCompatImageButton.perform(click());
|
appCompatImageButton.perform(click());
|
||||||
|
|
||||||
// Added a sleep statement to match the app's execution delay.
|
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
|
||||||
// The recommended way to handle such scenarios is to use Espresso idling resources:
|
|
||||||
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
|
|
||||||
try {
|
|
||||||
Thread.sleep(10000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewInteraction textView2 = onView(
|
ViewInteraction textView2 = onView(
|
||||||
allOf(withText("Wikipedia"),
|
allOf(withText("Wikipedia"),
|
||||||
@ -208,14 +166,8 @@ public class HelpActivityTest {
|
|||||||
isDisplayed()));
|
isDisplayed()));
|
||||||
webView.check(matches(isDisplayed()));
|
webView.check(matches(isDisplayed()));
|
||||||
|
|
||||||
// Added a sleep statement to match the app's execution delay.
|
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
|
||||||
// The recommended way to handle such scenarios is to use Espresso idling resources:
|
|
||||||
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
|
|
||||||
try {
|
|
||||||
Thread.sleep(20000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
|
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
|
||||||
|
|
||||||
@ -240,14 +192,8 @@ public class HelpActivityTest {
|
|||||||
|
|
||||||
pressBack();
|
pressBack();
|
||||||
|
|
||||||
// Added a sleep statement to match the app's execution delay.
|
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
|
||||||
// The recommended way to handle such scenarios is to use Espresso idling resources:
|
|
||||||
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewInteraction recyclerView = onView(
|
ViewInteraction recyclerView = onView(
|
||||||
allOf(withId(R.id.recycler_view),
|
allOf(withId(R.id.recycler_view),
|
||||||
@ -256,25 +202,13 @@ public class HelpActivityTest {
|
|||||||
1)));
|
1)));
|
||||||
recyclerView.perform(actionOnItemAtPosition(1, click()));
|
recyclerView.perform(actionOnItemAtPosition(1, click()));
|
||||||
|
|
||||||
// Added a sleep statement to match the app's execution delay.
|
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
|
||||||
// The recommended way to handle such scenarios is to use Espresso idling resources:
|
|
||||||
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
|
|
||||||
try {
|
|
||||||
Thread.sleep(10000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
|
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
|
||||||
|
|
||||||
// Added a sleep statement to match the app's execution delay.
|
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
|
||||||
// The recommended way to handle such scenarios is to use Espresso idling resources:
|
|
||||||
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
|
|
||||||
try {
|
|
||||||
Thread.sleep(10000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewInteraction appCompatTextView3 = onView(
|
ViewInteraction appCompatTextView3 = onView(
|
||||||
allOf(withId(R.id.title), withText("Help"),
|
allOf(withId(R.id.title), withText("Help"),
|
||||||
@ -286,14 +220,8 @@ public class HelpActivityTest {
|
|||||||
isDisplayed()));
|
isDisplayed()));
|
||||||
appCompatTextView3.perform(click());
|
appCompatTextView3.perform(click());
|
||||||
|
|
||||||
// Added a sleep statement to match the app's execution delay.
|
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
|
||||||
// The recommended way to handle such scenarios is to use Espresso idling resources:
|
|
||||||
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
|
|
||||||
try {
|
|
||||||
Thread.sleep(20000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewInteraction textView3 = onView(
|
ViewInteraction textView3 = onView(
|
||||||
allOf(withText("Help"),
|
allOf(withText("Help"),
|
||||||
@ -346,14 +274,8 @@ public class HelpActivityTest {
|
|||||||
isDisplayed()));
|
isDisplayed()));
|
||||||
textView7.check(matches(withText("Where is the content?")));
|
textView7.check(matches(withText("Where is the content?")));
|
||||||
|
|
||||||
// Added a sleep statement to match the app's execution delay.
|
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
|
||||||
// The recommended way to handle such scenarios is to use Espresso idling resources:
|
|
||||||
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
|
|
||||||
try {
|
|
||||||
Thread.sleep(80000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewInteraction appCompatImageView = onView(
|
ViewInteraction appCompatImageView = onView(
|
||||||
allOf(withId(R.id.item_help_toggle_expand), withContentDescription("Expand"),
|
allOf(withId(R.id.item_help_toggle_expand), withContentDescription("Expand"),
|
||||||
@ -365,14 +287,8 @@ public class HelpActivityTest {
|
|||||||
isDisplayed()));
|
isDisplayed()));
|
||||||
appCompatImageView.perform(click());
|
appCompatImageView.perform(click());
|
||||||
|
|
||||||
// Added a sleep statement to match the app's execution delay.
|
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
|
||||||
// The recommended way to handle such scenarios is to use Espresso idling resources:
|
|
||||||
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
|
|
||||||
try {
|
|
||||||
Thread.sleep(160000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewInteraction textView8 = onView(
|
ViewInteraction textView8 = onView(
|
||||||
allOf(withId(R.id.item_help_description), withText(
|
allOf(withId(R.id.item_help_description), withText(
|
||||||
@ -439,14 +355,8 @@ public class HelpActivityTest {
|
|||||||
isDisplayed()));
|
isDisplayed()));
|
||||||
textView11.check(matches(isDisplayed()));
|
textView11.check(matches(isDisplayed()));
|
||||||
|
|
||||||
// Added a sleep statement to match the app's execution delay.
|
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
|
||||||
// The recommended way to handle such scenarios is to use Espresso idling resources:
|
|
||||||
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
|
|
||||||
try {
|
|
||||||
Thread.sleep(160000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewInteraction appCompatImageView4 = onView(
|
ViewInteraction appCompatImageView4 = onView(
|
||||||
allOf(withId(R.id.item_help_toggle_expand), withContentDescription("Expand"),
|
allOf(withId(R.id.item_help_toggle_expand), withContentDescription("Expand"),
|
||||||
@ -500,14 +410,8 @@ public class HelpActivityTest {
|
|||||||
isDisplayed()));
|
isDisplayed()));
|
||||||
appCompatImageView6.perform(click());
|
appCompatImageView6.perform(click());
|
||||||
|
|
||||||
// Added a sleep statement to match the app's execution delay.
|
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
|
||||||
// The recommended way to handle such scenarios is to use Espresso idling resources:
|
|
||||||
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
|
|
||||||
try {
|
|
||||||
Thread.sleep(160000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewInteraction appCompatImageButton2 = onView(
|
ViewInteraction appCompatImageButton2 = onView(
|
||||||
allOf(withContentDescription("Navigate up"),
|
allOf(withContentDescription("Navigate up"),
|
||||||
@ -520,14 +424,7 @@ public class HelpActivityTest {
|
|||||||
isDisplayed()));
|
isDisplayed()));
|
||||||
appCompatImageButton2.perform(click());
|
appCompatImageButton2.perform(click());
|
||||||
|
|
||||||
// Added a sleep statement to match the app's execution delay.
|
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
|
||||||
// The recommended way to handle such scenarios is to use Espresso idling resources:
|
|
||||||
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
|
|
||||||
try {
|
|
||||||
Thread.sleep(160000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
ViewInteraction textView14 = onView(
|
ViewInteraction textView14 = onView(
|
||||||
allOf(withText("Wikipedia"),
|
allOf(withText("Wikipedia"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user