app/src/androidTest/java/ch/epfl/sweng/favors/main/CompleteLoggedUITest.java
package ch.epfl.sweng.favors.main;
import android.support.test.espresso.ViewInteraction;
import android.support.test.filters.LargeTest;
import android.support.test.rule.ActivityTestRule;
import android.support.test.rule.GrantPermissionRule;
import android.support.test.runner.AndroidJUnit4;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.RecyclerView;
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.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import ch.epfl.sweng.favors.R;
import ch.epfl.sweng.favors.database.FakeDatabase;
import ch.epfl.sweng.favors.utils.ExecutionMode;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.Espresso.pressBack;
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.pressImeActionButton;
import static android.support.test.espresso.action.ViewActions.replaceText;
import static android.support.test.espresso.action.ViewActions.scrollTo;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition;
import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed;
import static android.support.test.espresso.matcher.ViewMatchers.withChild;
import static android.support.test.espresso.matcher.ViewMatchers.withClassName;
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;
import static org.hamcrest.Matchers.is;
@LargeTest
@RunWith(AndroidJUnit4.class)
public class CompleteLoggedUITest {
@Rule
public ActivityTestRule<SplashScreenActivity> mActivityTestRule = new ActivityTestRule<>(SplashScreenActivity.class, false, false);
@Rule
public GrantPermissionRule mGrantPermissionRule =
GrantPermissionRule.grant(
"android.permission.ACCESS_FINE_LOCATION",
"android.permission.ACCESS_COARSE_LOCATION");
@Before
public void setUp() {
ExecutionMode.getInstance().setTest(true);
FakeDatabase.getInstance().createBasicDatabase();
}
private void homeScreenTests(){
/**
* HOME Screen here
*/
// Check home title
ViewInteraction textView = onView(
allOf(withId(R.id.welcomeTitle), withText("Welcome back Fake!"),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(NestedScrollView.class),
0),
0),
isDisplayed()));
textView.check(matches(withText("Welcome back Fake!")));
// Check home main list type title
ViewInteraction textView2 = onView(
allOf(withId(R.id.lastFavorsTitle), withText("Discover favors in your area..."),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
1),
0),
isDisplayed()));
textView2.check(matches(withText("Discover favors in your area...")));
// Check if list switching button is here
ViewInteraction button = onView(
allOf(withId(R.id.switchList),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
1),
1),
isDisplayed()));
button.check(matches(isDisplayed()));
ViewInteraction textView8 = onView(
allOf(withId(R.id.title), withText("Closest favor"),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
0),
1)));
textView8.check(matches(withText("Closest favor")));
// Switch home screen list
ViewInteraction appCompatButton = onView(
allOf(withId(R.id.switchList), withText(">"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
1),
1),
isDisplayed()));
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
appCompatButton.perform(click());
// Click the "More favors button to get the lists"
ViewInteraction appCompatButton2 = onView(
allOf(withId(R.id.button), withText("More favors")));
appCompatButton2.perform(click());
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private void listSortingTests(){
// Test sort
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction appCompatSpinner3 = onView(
allOf(withId(R.id.sortBySpinner),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
1)));
appCompatSpinner3.perform(scrollTo(), click());
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction textView15 = onView(
allOf(withText("location")));
textView15.perform(scrollTo());
textView15.check(matches(withText("location")));
textView15.perform(click());
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction textView8 = onView(
allOf(withId(R.id.title), withText("Closest favor"),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
0),
1)));
textView8.check(matches(withText("Closest favor")));
appCompatSpinner3.perform(scrollTo(), click());
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
textView15 = onView(
allOf(withText("expiring soon")));
textView15.perform(scrollTo());
textView15.check(matches(withText("expiring soon")));
textView15.perform(click());
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
appCompatSpinner3.perform(scrollTo(), click());
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
textView15 = onView(
allOf(withText("recent")));
textView15.perform(scrollTo());
textView15.check(matches(withText("recent")));
textView15.perform(click());
try {
Thread.sleep(800);
} catch (InterruptedException e) {
e.printStackTrace();
}
/*ViewInteraction textView5 = onView(
allOf(withId(R.id.title), withText("Most recent favor")));
textView5.check(matches(withText("Most recent favor")));*/
appCompatSpinner3.perform(scrollTo(), click());
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
textView15 = onView(
allOf(withText("category")));
textView15.perform(scrollTo());
textView15.check(matches(withText("category")));
textView15.perform(click());
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
appCompatSpinner3.perform(scrollTo(), click());
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
textView15 = onView(
allOf(withText("recent")));
textView15.perform(scrollTo());
textView15.check(matches(withText("recent")));
textView15.perform(click());
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private void favorsListTests(){
/**
* Favors list view
*/
// Test list header
ViewInteraction button3 = onView(
allOf(withId(R.id.modeSwitch),
childAtPosition(
allOf(withId(R.id.linLayout1),
childAtPosition(
IsInstanceOf.<View>instanceOf(android.view.ViewGroup.class),
0)),
0),
isDisplayed()));
button3.check(matches(isDisplayed()));
ViewInteraction textView7 = onView(
allOf(withId(R.id.tokens), withText("7 Tokens"),
childAtPosition(
allOf(withId(R.id.linLayout1),
childAtPosition(
IsInstanceOf.<View>instanceOf(android.view.ViewGroup.class),
0)),
1),
isDisplayed()));
textView7.check(matches(withText("7 Tokens")));
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction textView8 = onView(
allOf(withId(R.id.title), withText("Closest favor"),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
0),
1)));
textView8.check(matches(withText("Closest favor")));
listSortingTests();
pressBack();
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction appCompatButton2 = onView(
allOf(withId(R.id.button), withText("More favors")));
appCompatButton2.perform(click());
try {
Thread.sleep(800);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction recyclerView2 = onView(allOf(withId(R.id.title), withText("Most recent favor")));
recyclerView2.perform(click());
try {
Thread.sleep(800);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction textView9 = onView(
allOf(withId(R.id.favReportAbusiveAdd)));
textView9.perform(scrollTo());
ViewInteraction appCompatButton34 = onView(
allOf(withId(R.id.selectButton), withText("Select people")));
appCompatButton34.perform(scrollTo(), click());
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction textView88 = onView(
allOf(withId(R.id.selected), withText("Select"),
childAtPosition(
childAtPosition(
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(RecyclerView.class),
0),
0),
2),
0)));
textView88.check(matches(withText("Select")));
textView88.perform(click());
ViewInteraction appCompatButton38 = onView(
allOf(withId(R.id.selectionDone), withText("Done")));
appCompatButton38.perform(scrollTo(), click());
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction appCompatButton3 = onView(
allOf(withId(R.id.payButton), withText("Pay")));
appCompatButton3.perform(scrollTo(), click());
}
private void favorEditionTests(){
/**
* Edit a favor
*/
ViewInteraction textView10 = onView(
allOf(withId(R.id.favTitle), withText("Most recent favor")));
textView10.perform(scrollTo());
textView10.check(matches(withText("Most recent favor")));
ViewInteraction imageView = onView(
allOf(withId(R.id.imageView), withContentDescription("image"),
childAtPosition(
allOf(withId(R.id.view2),
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
1)),
0),
isDisplayed()));
imageView.check(matches(isDisplayed()));
ViewInteraction textView11 = onView(
allOf(withId(R.id.favDescription), withText("It does messy things"),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.ScrollView.class),
0),
2),
isDisplayed()));
textView11.perform(scrollTo());
textView11.check(matches(withText("It does messy things")));
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction button4 = onView(
allOf(withId(R.id.interestedButton),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
5),
0)));
button4.perform(scrollTo());
button4.check(matches(isDisplayed()));
ViewInteraction button5 = onView(
allOf(withId(R.id.deleteButton),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
5),
1)));
button5.perform(scrollTo());
button5.check(matches(isDisplayed()));
ViewInteraction button7 = onView(
allOf(withId(R.id.payButton)));
button7.perform(scrollTo());
button7.check(matches(isDisplayed()));
ViewInteraction textView12 = onView(
allOf(withId(R.id.favTokAmmount), withText("2 * 2"),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
5),
2)));
textView12.perform(scrollTo());
textView12.check(matches(withText("2 * 2")));
ViewInteraction appCompatButton3 = onView(
allOf(withId(R.id.interestedButton), withText("Edit"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
5),
0)));
appCompatButton3.perform(scrollTo(), click());
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction appCompatEditText = onView(
allOf(withId(R.id.titleFavor), withText("Most recent favor")));
appCompatEditText.perform(scrollTo(), replaceText("Renamed favor"));
ViewInteraction appCompatEditText2 = onView(
allOf(withId(R.id.titleFavor), withText("Renamed favor"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
2),
isDisplayed()));
appCompatEditText2.perform(closeSoftKeyboard());
ViewInteraction appCompatTextView = onView(
allOf(withId(R.id.deadlineFavor),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
9)));
appCompatTextView.perform(scrollTo(), click());
ViewInteraction appCompatButton4 = onView(
allOf(withId(android.R.id.button1), withText("OK"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0),
2),
isDisplayed()));
appCompatButton4.perform(click());
ViewInteraction appCompatTextView2 = onView(
allOf(withId(R.id.search), withText("Search"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
7)));
appCompatTextView2.perform(scrollTo(), click());
ViewInteraction textView13 = onView(
allOf(withId(R.id.createFavorTitle), withText("Edit an existing favor"),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.ScrollView.class),
0),
0)));
textView13.perform(scrollTo());
textView13.check(matches(withText("Edit an existing favor")));
ViewInteraction appCompatButton5 = onView(
allOf(withId(R.id.testFavorDetailButton), withText("Preview favor"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
17)));
appCompatButton5.perform(scrollTo(), 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(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private void favorPreviewTests(){
/**
* Preview a favor while editing
*/
ViewInteraction textView14 = onView(
allOf(withId(R.id.favTitle), withText("Renamed favor"),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.ScrollView.class),
0),
0),
isDisplayed()));
textView14.check(matches(withText("Renamed favor")));
pressBack();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private void favorSubmitEditionTests(){
ViewInteraction appCompatEditText6 = onView(
allOf(withId(R.id.nbTokens),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
11),
isDisplayed()));
appCompatEditText6.perform(closeSoftKeyboard());
ViewInteraction appCompatButton7 = onView(
allOf(withId(R.id.addFavor), withText("Edit the favor"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
16)));
appCompatButton7.perform(scrollTo(), click());
ViewInteraction appCompatEditText8 = onView(
allOf(withId(R.id.nbTokens),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
11)));
appCompatEditText8.perform(scrollTo(), click());
ViewInteraction appCompatEditText9 = onView(
allOf(withId(R.id.nbTokens),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
11)));
appCompatEditText9.perform(scrollTo(), replaceText("1"), closeSoftKeyboard());
ViewInteraction appCompatEditText10 = onView(
allOf(withId(R.id.nbPersons),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
13)));
appCompatEditText10.perform(scrollTo(), replaceText("1"), closeSoftKeyboard());
ViewInteraction appCompatButton8 = onView(
allOf(withId(R.id.addFavor), withText("Edit the favor"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
16)));
appCompatButton8.perform(scrollTo(), click());
pressBack();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
pressBack();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private void favorDetailViewTests(){
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction recyclerView2 = onView(allOf(withChild(allOf(withId(R.id.title), withText("Closest favor")))));
recyclerView2.perform(click());
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction textView14 = onView(
allOf(withId(R.id.favTitle), withText("Closest favor"),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.ScrollView.class),
0),
0),
isDisplayed()));
textView14.check(matches(withText("Closest favor")));
ViewInteraction appCompatButton9 = onView(
allOf(withId(R.id.interestedButton), withText("Notify my interest"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
5),
0)));
appCompatButton9.perform(scrollTo(), click());
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
appCompatButton9 = onView(
allOf(withId(R.id.interestedButton),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
5),
0)));
appCompatButton9.perform(scrollTo(), click());
try {
Thread.sleep(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
appCompatButton9 = onView(
allOf(withId(R.id.interestedButton),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
5),
0)));
appCompatButton9.perform(scrollTo(), click());
ViewInteraction appCompatButton10 = onView(
allOf(withText("Jean")));
appCompatButton10.perform(scrollTo(), click());
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
posterDetailsTests();
pressBack();
}
private void posterDetailsTests() {
ViewInteraction textView26 = onView(
allOf(withId(R.id.posterTitle), withText("Who is the poster?"),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.ScrollView.class),
0),
0),
isDisplayed()));
textView26.check(matches(withText("Who is the poster?")));
ViewInteraction imageView4 = onView(
allOf(withId(R.id.profilePic),
childAtPosition(
allOf(withId(R.id.view2),
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
1)),
0),
isDisplayed()));
imageView4.check(matches(isDisplayed()));
ViewInteraction textView27 = onView(
allOf(withText("First name"),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.ScrollView.class),
0),
2),
isDisplayed()));
textView27.check(matches(withText("First name")));
pressBack();
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
pressBack();
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction appCompatButton3 = onView(
allOf(withId(R.id.modeSwitch), withText("Map view"),
childAtPosition(
allOf(withId(R.id.linLayout1),
childAtPosition(
withClassName(is("android.support.constraint.ConstraintLayout")),
0)),
0),
isDisplayed()));
appCompatButton3.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(600);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction button3 = onView(
allOf(withId(R.id.modeSwitch),
childAtPosition(
allOf(withId(R.id.linLayout1),
childAtPosition(
IsInstanceOf.<View>instanceOf(android.view.ViewGroup.class),
0)),
0),
isDisplayed()));
button3.check(matches(isDisplayed()));
ViewInteraction frameLayout = onView(
allOf(withId(R.id.mapView),
childAtPosition(
allOf(withId(R.id.favors_container),
childAtPosition(
IsInstanceOf.<View>instanceOf(android.view.ViewGroup.class),
1)),
0),
isDisplayed()));
frameLayout.check(matches(isDisplayed()));
}
private void navigationDrawerTests() {
ViewInteraction appCompatImageButton = onView(
allOf(withContentDescription("Open navigation drawer"),
childAtPosition(
allOf(withId(R.id.toolbar),
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0)),
0),
isDisplayed()));
appCompatImageButton.perform(click());
/*ViewInteraction textView8 = onView(
allOf(withId(R.id.textView2), withText("Fake Auth"),
childAtPosition(
childAtPosition(
withId(R.id.navigation_header_container),
0),
2),
isDisplayed()));
textView8.check(matches(withText("Fake Auth")));
ViewInteraction textView9 = onView(
allOf(withText("Fake Lausanne"),
childAtPosition(
childAtPosition(
withId(R.id.navigation_header_container),
0),
3),
isDisplayed()));
textView9.check(matches(withText(FakeGeocoder.FAKE_LOCATION_CITY)));*/
ViewInteraction checkedTextView = onView(
allOf(withId(R.id.design_menu_item_text),
childAtPosition(
childAtPosition(
withId(R.id.design_navigation_view),
1),
0),
isDisplayed()));
checkedTextView.check(matches(isDisplayed()));
ViewInteraction checkedTextView2 = onView(
allOf(withId(R.id.design_menu_item_text),
childAtPosition(
childAtPosition(
withId(R.id.design_navigation_view),
2),
0),
isDisplayed()));
checkedTextView2.check(matches(isDisplayed()));
ViewInteraction checkedTextView3 = onView(
allOf(withId(R.id.design_menu_item_text),
childAtPosition(
childAtPosition(
withId(R.id.design_navigation_view),
3),
0),
isDisplayed()));
checkedTextView3.check(matches(isDisplayed()));
ViewInteraction checkedTextView4 = onView(
allOf(withId(R.id.design_menu_item_text),
childAtPosition(
childAtPosition(
withId(R.id.design_navigation_view),
4),
0),
isDisplayed()));
checkedTextView4.check(matches(isDisplayed()));
ViewInteraction navigationMenuItemView = onView(
allOf(childAtPosition(
allOf(withId(R.id.design_navigation_view),
childAtPosition(
withId(R.id.nav_view),
0)),
2),
isDisplayed()));
navigationMenuItemView.perform(click());
appCompatImageButton.perform(click());
ViewInteraction navigationMenuItemView2 = onView(
allOf(childAtPosition(
allOf(withId(R.id.design_navigation_view),
childAtPosition(
withId(R.id.nav_view),
0)),
3),
isDisplayed()));
navigationMenuItemView2.perform(click());
appCompatImageButton.perform(click());
ViewInteraction navigationMenuItemView3 = onView(
allOf(childAtPosition(
allOf(withId(R.id.design_navigation_view),
childAtPosition(
withId(R.id.nav_view),
0)),
4),
isDisplayed()));
navigationMenuItemView3.perform(click());
appCompatImageButton.perform(click());
ViewInteraction floatingActionButton = onView(
allOf(withId(R.id.deleteProfilePicture),
childAtPosition(
childAtPosition(
withId(R.id.navigation_header_container),
0),
0),
isDisplayed()));
floatingActionButton.perform(click());
navigationMenuItemView3.perform(click());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private void profilTests(){
ViewInteraction appCompatImageButton2 = onView(
allOf(withContentDescription("Open navigation drawer"),
childAtPosition(
allOf(withId(R.id.toolbar),
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0)),
0),
isDisplayed()));
appCompatImageButton2.perform(click());
ViewInteraction navigationMenuItemView2 = onView(
allOf(childAtPosition(
allOf(withId(R.id.design_navigation_view),
childAtPosition(
withId(R.id.nav_view),
0)),
5),
isDisplayed()));
navigationMenuItemView2.perform(click());
ViewInteraction textView17 = onView(
allOf(withId(R.id.profEmail), withText("toto@mail.com"),
childAtPosition(
childAtPosition(
withId(R.id.fragment_container),
0),
1),
isDisplayed()));
textView17.check(matches(withText("toto@mail.com")));
ViewInteraction button6 = onView(
allOf(withId(R.id.editProfileButton),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
0),
1),
isDisplayed()));
button6.check(matches(isDisplayed()));
ViewInteraction button7 = onView(
allOf(withId(R.id.editProfileButton),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
0),
1),
isDisplayed()));
button7.check(matches(isDisplayed()));
ViewInteraction textView18 = onView(
allOf(withText("City:"),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
2),
0),
isDisplayed()));
textView18.check(matches(withText("City:")));
ViewInteraction textView19 = onView(
allOf(withText("City:"),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
2),
0),
isDisplayed()));
textView19.check(matches(withText("City:")));
ViewInteraction appCompatButton6 = onView(
allOf(withId(R.id.editProfileButton), withText("Edit profile"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0),
1),
isDisplayed()));
appCompatButton6.perform(click());
ViewInteraction textView20 = onView(
allOf(withId(R.id.editProfileTitle), withText("Edit profile"),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
0),
0),
isDisplayed()));
textView20.check(matches(withText("Edit profile")));
ViewInteraction appCompatEditText4 = onView(
allOf(withId(R.id.profFirstNameEdit), withText("Fake"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
1)));
appCompatEditText4.perform(scrollTo(), replaceText("Nom"));
ViewInteraction appCompatEditText8 = onView(
allOf(withId(R.id.profFirstNameEdit), withText("Nom"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
1),
isDisplayed()));
appCompatEditText8.perform(closeSoftKeyboard());
ViewInteraction appCompatEditText9 = onView(
allOf(withId(R.id.profFirstNameEdit), withText("Nom"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
1)));
appCompatEditText9.perform(pressImeActionButton());
ViewInteraction appCompatEditText11 = onView(
allOf(withId(R.id.profLastNameEdit), withText("Auth")));
appCompatEditText11.perform(scrollTo(), replaceText("Test"));
ViewInteraction appCompatEditText12 = onView(
allOf(withId(R.id.profLastNameEdit), withText("Test"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
3),
isDisplayed()));
appCompatEditText12.perform(closeSoftKeyboard());
ViewInteraction appCompatButton7 = onView(
allOf(withId(R.id.commitChanges), withText("Update"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
8)));
appCompatButton7.perform(scrollTo(), click());
ViewInteraction textView21 = onView(
allOf(withId(R.id.profileTitle), withText("Nom's Profile"),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
0),
0),
isDisplayed()));
textView21.check(matches(withText("Nom's Profile")));
ViewInteraction appCompatImageButton3 = onView(
allOf(withContentDescription("Open navigation drawer"),
childAtPosition(
allOf(withId(R.id.toolbar),
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0)),
0),
isDisplayed()));
appCompatImageButton3.perform(click());
}
private void myFavorsAndCreateFavorTest(){
ViewInteraction appCompatImageButton = onView(
allOf(withContentDescription("Open navigation drawer"),
childAtPosition(
allOf(withId(R.id.toolbar),
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0)),
0),
isDisplayed()));
appCompatImageButton.perform(click());
ViewInteraction navigationMenuItemView = onView(
allOf(childAtPosition(
allOf(withId(R.id.design_navigation_view),
childAtPosition(
withId(R.id.nav_view),
0)),
4),
isDisplayed()));
navigationMenuItemView.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(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction floatingActionButton = onView(
allOf(withId(R.id.addNewFavor),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0),
1),
isDisplayed()));
floatingActionButton.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(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction appCompatEditText11 = onView(
allOf(withId(R.id.titleFavor),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
2)));
appCompatEditText11.perform(scrollTo(), replaceText("New favor"), closeSoftKeyboard());
ViewInteraction floatingActionButton2 = onView(
allOf(withId(R.id.uploadFavorPictureCamera),
childAtPosition(
allOf(withId(R.id.imageOfFavor),
childAtPosition(
withClassName(is("android.support.constraint.ConstraintLayout")),
1)),
2)));
floatingActionButton2.perform(scrollTo(), click());
ViewInteraction floatingActionButton3 = onView(
allOf(withId(R.id.uploadFavorPicture),
childAtPosition(
allOf(withId(R.id.imageOfFavor),
childAtPosition(
withClassName(is("android.support.constraint.ConstraintLayout")),
1)),
1)));
floatingActionButton3.perform(scrollTo(), click());
ViewInteraction appCompatEditText12 = onView(
allOf(withId(R.id.descriptionFavor),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
4)));
appCompatEditText12.perform(scrollTo(), replaceText("Description"), closeSoftKeyboard());
ViewInteraction appCompatEditText13 = onView(
allOf(withId(R.id.locationFavor), withText("Fake Lausanne"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
6)));
appCompatEditText13.perform(scrollTo(), click());
ViewInteraction appCompatEditText14 = onView(
allOf(withId(R.id.locationFavor), withText("Fake Lausanne"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
6)));
appCompatEditText14.perform(scrollTo(), replaceText(""));
ViewInteraction appCompatEditText15 = onView(
allOf(withId(R.id.locationFavor),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
6),
isDisplayed()));
appCompatEditText15.perform(closeSoftKeyboard());
ViewInteraction appCompatTextView4 = onView(
allOf(withId(R.id.search), withText("Search"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
7)));
appCompatTextView4.perform(scrollTo(), click());
ViewInteraction appCompatEditText16 = onView(
allOf(withId(R.id.locationFavor),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
6)));
appCompatEditText16.perform(scrollTo(), replaceText("Fake"), closeSoftKeyboard());
ViewInteraction appCompatTextView5 = onView(
allOf(withId(R.id.search), withText("Search"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
7)));
appCompatTextView5.perform(scrollTo(), click());
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction imageView2 = onView(
allOf(withId(R.id.checkFavorLocation),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.ScrollView.class),
0),
8),
isDisplayed()));
imageView2.check(matches(isDisplayed()));
ViewInteraction appCompatTextView6 = onView(
allOf(withId(R.id.deadlineFavor),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
9)));
appCompatTextView6.perform(scrollTo(), click());
ViewInteraction appCompatButton11 = onView(
allOf(withId(android.R.id.button1), withText("OK"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0),
2),
isDisplayed()));
appCompatButton11.perform(click());
ViewInteraction appCompatSpinner = onView(
allOf(withId(R.id.categoryFavor)));
appCompatSpinner.perform(scrollTo(), click());
ViewInteraction textView14 = onView(
allOf(withText("Cooking")));
textView14.perform(scrollTo());
textView14.check(matches(withText("Cooking")));
ViewInteraction textView15 = onView(
allOf(withText("Tutoring")));
textView15.perform(scrollTo());
textView15.check(matches(withText("Tutoring")));
textView15.perform(click());
ViewInteraction appCompatEditText19 = onView(
allOf(withId(R.id.nbTokens), withText("1"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
11)));
appCompatEditText19.perform(scrollTo(), click());
ViewInteraction appCompatEditText20 = onView(
allOf(withId(R.id.nbTokens), withText("1"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
11)));
appCompatEditText20.perform(scrollTo(), replaceText("2"));
ViewInteraction appCompatEditText21 = onView(
allOf(withId(R.id.nbTokens), withText("2"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
11),
isDisplayed()));
appCompatEditText21.perform(closeSoftKeyboard());
ViewInteraction appCompatEditText22 = onView(
allOf(withId(R.id.nbPersons), withText("1"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
13)));
appCompatEditText22.perform(scrollTo(), replaceText("2"));
ViewInteraction appCompatEditText23 = onView(
allOf(withId(R.id.nbPersons), withText("2"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
13),
isDisplayed()));
appCompatEditText23.perform(closeSoftKeyboard());
ViewInteraction appCompatButton13 = onView(
allOf(withId(R.id.addFavor),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.ScrollView")),
0),
16)));
appCompatButton13.perform(scrollTo(), click());
pressBack();
// 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(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction textView17 = onView(
allOf(withId(R.id.title), withText("New favor"),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
0),
1),
isDisplayed()));
textView17.check(matches(withText("New favor")));
ViewInteraction textView18 = onView(
allOf(withId(R.id.textView), withText("Your favors"),
childAtPosition(
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
0),
0),
isDisplayed()));
textView18.check(matches(withText("Your favors")));
ViewInteraction recyclerView9 = onView(
allOf(withId(R.id.favorsList),
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
1)));
recyclerView9.perform(actionOnItemAtPosition(1, 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(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction appCompatButton14 = onView(
allOf(withId(R.id.deleteButton), withText("Delete"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
5),
1)));
appCompatButton14.perform(scrollTo(), click());
ViewInteraction appCompatImageButton34 = onView(
allOf(withContentDescription("Open navigation drawer"),
childAtPosition(
allOf(withId(R.id.toolbar),
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0)),
0),
isDisplayed()));
appCompatImageButton34.perform(click());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction navigationMenuItemView35 = onView(
allOf(childAtPosition(
allOf(withId(R.id.design_navigation_view),
childAtPosition(
withId(R.id.nav_view),
0)),
5),
isDisplayed()));
navigationMenuItemView35.perform(click());
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Test
public void completeLoggedUITest() {
mActivityTestRule.launchActivity(null);
// 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();
}
homeScreenTests();
favorsListTests();
favorEditionTests();
favorPreviewTests();
favorSubmitEditionTests();
favorDetailViewTests();
myFavorsAndCreateFavorTest();
}
@Test
public void secondCompleteLoggedUITest() {
mActivityTestRule.launchActivity(null);
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
navigationDrawerTests();
profilTests();
}
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));
}
};
}
}