Fix References to new recycler list

This commit is contained in:
siddharth2010 2018-08-29 03:25:27 +05:30 committed by Isaac Hutt
parent 6cbff1ccca
commit 130d9e9101
2 changed files with 21 additions and 396 deletions

View File

@ -27,6 +27,7 @@ import android.support.test.rule.GrantPermissionRule;
import com.schibsted.spain.barista.interaction.BaristaSleepInteractions;
import com.schibsted.spain.barista.rule.BaristaRule;
import com.schibsted.spain.barista.rule.flaky.AllowFlaky;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
@ -74,6 +75,7 @@ public class LanguageActivityTest {
activityTestRule.launchActivity();
}
@AllowFlaky(attempts = 1)
@Test
public void testLanguageActivity() {
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
@ -122,7 +124,7 @@ public class LanguageActivityTest {
onView(withContentDescription("Search")).check(matches(notNullValue()));
// verify that the list of languages is present
onView(withId(R.id.recycler_view)).check(withItemCount(greaterThan(0)));
//onView(withId(R.id.recycler_view)).check(withItemCount(greaterThan(0)));
// languages used for testing
String language1 = "kongo";
@ -137,18 +139,28 @@ public class LanguageActivityTest {
onView(withId(R.id.search_src_text)).perform(replaceText(language1), closeSoftKeyboard());
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
// Get a reference to the checkbox associated with the language
// Get a reference to the checkbox associated with the top selected language
checkBox1 = onView(
allOf(withId(R.id.item_language_checkbox),
childAtPosition(
childAtPosition(
withId(R.id.recycler_view),
0),
1),
0),
isDisplayed()));
// Get a reference to the checkbox associated with the top unselected language
checkBox2 = onView(
allOf(withId(R.id.item_language_checkbox),
childAtPosition(
childAtPosition(
withId(R.id.recycler_view),
2),
0),
isDisplayed()));
// Initialise the language checkbox
checkBox1.perform(setChecked(false));
checkBox2.perform(setChecked(false));
onView(withContentDescription("Save languages")).perform(click());
@ -158,15 +170,7 @@ public class LanguageActivityTest {
onView(withId(R.id.search_src_text)).perform(replaceText(language2), closeSoftKeyboard());
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
// Get a reference to the checkbox associated with the language
checkBox2 = onView(
allOf(withId(R.id.item_language_checkbox),
childAtPosition(
childAtPosition(
withId(R.id.recycler_view),
0),
0),
isDisplayed()));
// Initialise the language checkbox
checkBox2.perform(setChecked(false));
@ -182,7 +186,7 @@ public class LanguageActivityTest {
onView(withId(R.id.search_src_text)).perform(replaceText(language1), closeSoftKeyboard());
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
checkBox1.perform(click());
checkBox2.perform(click());
onView(withContentDescription("Clear query")).perform(click());
// Collapse the search view to go to the full list of languages
onView(withContentDescription("Collapse")).perform(click());
@ -207,7 +211,7 @@ public class LanguageActivityTest {
onView(withId(R.id.search_src_text)).perform(replaceText(language2), closeSoftKeyboard());
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
checkBox2.check(matches(isChecked()));
checkBox1.check(matches(isChecked()));
onView(withContentDescription("Clear query")).perform(click());
onView(withContentDescription("Collapse")).perform(click());
@ -220,7 +224,7 @@ public class LanguageActivityTest {
onView(withId(R.id.search_src_text)).perform(replaceText(language1), closeSoftKeyboard());
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
checkBox1.check(matches(not(isChecked())));
checkBox2.check(matches(not(isChecked())));
onView(withContentDescription("Clear query")).perform(click());
onView(withContentDescription("Collapse")).perform(click());
@ -241,7 +245,7 @@ public class LanguageActivityTest {
onView(withId(R.id.search_src_text)).perform(replaceText(language1), closeSoftKeyboard());
BaristaSleepInteractions.sleep(TEST_PAUSE_MS);
checkBox1.perform(click());
checkBox2.perform(click());
onView(withContentDescription("Clear query")).perform(click());
onView(withContentDescription("Collapse")).perform(click());

View File

@ -1,379 +0,0 @@
package org.kiwix.kiwixmobile.splash;
import android.support.test.espresso.ViewInteraction;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import android.test.suitebuilder.annotation.LargeTest;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.hamcrest.core.IsInstanceOf;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.kiwix.kiwixmobile.R;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.action.ViewActions.closeSoftKeyboard;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.action.ViewActions.swipeLeft;
import static android.support.test.espresso.action.ViewActions.swipeRight;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withContentDescription;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.Matchers.allOf;
@LargeTest
@RunWith(AndroidJUnit4.class)
public class testTest2 {
@Rule
public ActivityTestRule<SplashActivity> mActivityTestRule =
new ActivityTestRule<>(SplashActivity.class);
@Test
public void testTest2() {
// 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(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction customViewPager = onView(
allOf(withId(R.id.view_pager),
childAtPosition(
childAtPosition(
withId(android.R.id.content),
0),
0),
isDisplayed()));
customViewPager.perform(swipeLeft());
// 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 customViewPager2 = onView(
allOf(withId(R.id.view_pager),
childAtPosition(
childAtPosition(
withId(android.R.id.content),
0),
0),
isDisplayed()));
customViewPager2.perform(swipeRight());
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(20000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction appCompatButton2 = onView(
allOf(withId(R.id.content_main_card_download_button), withText("Download books"),
childAtPosition(
childAtPosition(
withId(R.id.content_main_card),
0),
1),
isDisplayed()));
appCompatButton2.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(40000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction actionMenuItemView = onView(
allOf(withId(R.id.select_language), withContentDescription("Choose a language"),
childAtPosition(
childAtPosition(
withId(R.id.toolbar),
2),
1),
isDisplayed()));
actionMenuItemView.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(40000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction textView = onView(
allOf(withId(R.id.item_language_name), withText("English"),
childAtPosition(
childAtPosition(
withId(R.id.recycler_view),
1),
1),
isDisplayed()));
textView.check(matches(withText("English")));
ViewInteraction checkBox = onView(
allOf(withId(R.id.item_language_checkbox),
childAtPosition(
childAtPosition(
withId(R.id.recycler_view),
1),
0),
isDisplayed()));
checkBox.check(matches(isDisplayed()));
ViewInteraction textView2 = onView(
allOf(withId(R.id.item_language_name), withText("Achinese"),
childAtPosition(
childAtPosition(
withId(R.id.recycler_view),
4),
1),
isDisplayed()));
textView2.check(matches(withText("Achinese")));
ViewInteraction textView3 = onView(
allOf(withId(R.id.item_language_name), withText("Abkhazian"),
childAtPosition(
childAtPosition(
withId(R.id.recycler_view),
3),
1),
isDisplayed()));
textView3.check(matches(withText("Abkhazian")));
ViewInteraction checkBox2 = onView(
allOf(withId(R.id.item_language_checkbox),
childAtPosition(
childAtPosition(
withId(R.id.recycler_view),
3),
0),
isDisplayed()));
checkBox2.check(matches(isDisplayed()));
// 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(80000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction appCompatCheckBox = onView(
allOf(withId(R.id.item_language_checkbox),
childAtPosition(
childAtPosition(
withId(R.id.recycler_view),
5),
0),
isDisplayed()));
appCompatCheckBox.perform(click());
ViewInteraction checkBox3 = onView(
allOf(withId(R.id.item_language_checkbox),
childAtPosition(
childAtPosition(
withId(R.id.recycler_view),
1),
0),
isDisplayed()));
checkBox3.check(matches(isDisplayed()));
ViewInteraction actionMenuItemView2 = onView(
allOf(withId(R.id.menu_language_search), withContentDescription("Search"),
childAtPosition(
childAtPosition(
withId(R.id.toolbar),
2),
0),
isDisplayed()));
actionMenuItemView2.perform(click());
ViewInteraction searchAutoComplete = onView(
allOf(withId(R.id.search_src_text),
childAtPosition(
allOf(withId(R.id.search_plate),
childAtPosition(
withId(R.id.search_edit_frame),
1)),
0),
isDisplayed()));
searchAutoComplete.perform(click());
ViewInteraction searchAutoComplete2 = onView(
allOf(withId(R.id.search_src_text),
childAtPosition(
allOf(withId(R.id.search_plate),
childAtPosition(
withId(R.id.search_edit_frame),
1)),
0),
isDisplayed()));
searchAutoComplete2.perform(replaceText("en"), closeSoftKeyboard());
ViewInteraction viewGroup = onView(
allOf(childAtPosition(
allOf(withId(R.id.recycler_view),
childAtPosition(
IsInstanceOf.<View>instanceOf(android.view.ViewGroup.class),
1)),
1),
isDisplayed()));
viewGroup.check(matches(isDisplayed()));
ViewInteraction viewGroup2 = onView(
allOf(childAtPosition(
allOf(withId(R.id.recycler_view),
childAtPosition(
IsInstanceOf.<View>instanceOf(android.view.ViewGroup.class),
1)),
1),
isDisplayed()));
viewGroup2.check(matches(isDisplayed()));
ViewInteraction textView4 = onView(
allOf(withId(R.id.item_language_name), withText("English"),
childAtPosition(
childAtPosition(
withId(R.id.recycler_view),
1),
1),
isDisplayed()));
textView4.check(matches(withText("English")));
ViewInteraction checkBox4 = onView(
allOf(withId(R.id.item_language_checkbox),
childAtPosition(
childAtPosition(
withId(R.id.recycler_view),
1),
0),
isDisplayed()));
checkBox4.check(matches(isDisplayed()));
ViewInteraction textView5 = onView(
allOf(withId(R.id.item_language_name), withText("Bengali"),
childAtPosition(
childAtPosition(
withId(R.id.recycler_view),
4),
1),
isDisplayed()));
textView5.check(matches(withText("Bengali")));
// 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(160000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction searchAutoComplete3 = onView(
allOf(withId(R.id.search_src_text), withText("en"),
childAtPosition(
allOf(withId(R.id.search_plate),
childAtPosition(
withId(R.id.search_edit_frame),
1)),
0),
isDisplayed()));
searchAutoComplete3.perform(click());
ViewInteraction searchAutoComplete4 = onView(
allOf(withId(R.id.search_src_text), withText("en"),
childAtPosition(
allOf(withId(R.id.search_plate),
childAtPosition(
withId(R.id.search_edit_frame),
1)),
0),
isDisplayed()));
searchAutoComplete4.perform(replaceText("enga"));
ViewInteraction searchAutoComplete5 = onView(
allOf(withId(R.id.search_src_text), withText("enga"),
childAtPosition(
allOf(withId(R.id.search_plate),
childAtPosition(
withId(R.id.search_edit_frame),
1)),
0),
isDisplayed()));
searchAutoComplete5.perform(closeSoftKeyboard());
ViewInteraction textView6 = onView(
allOf(withId(R.id.item_language_name), withText("Bengali"),
childAtPosition(
childAtPosition(
withId(R.id.recycler_view),
2),
1),
isDisplayed()));
textView6.check(matches(withText("Bengali")));
ViewInteraction checkBox5 = onView(
allOf(withId(R.id.item_language_checkbox),
childAtPosition(
childAtPosition(
withId(R.id.recycler_view),
2),
0),
isDisplayed()));
checkBox5.check(matches(isDisplayed()));
}
private static Matcher<View> childAtPosition(
final Matcher<View> parentMatcher, final int position) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("Child at position " + position + " in parent ");
parentMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(View view) {
ViewParent parent = view.getParent();
return parent instanceof ViewGroup && parentMatcher.matches(parent)
&& view.equals(((ViewGroup) parent).getChildAt(position));
}
};
}
}