use of android.support.test.espresso.ViewInteraction in project appium-espresso-driver by appium.
the class Finder method handle.
@Override
public Element handle(Locator locator) throws AppiumException {
try {
if (locator.getUsing() == null) {
throw new InvalidStrategyException("Locator strategy cannot be empty");
} else if (locator.getValue() == null) {
throw new MissingCommandsException("No locator provided");
}
// Test the selector
ViewInteraction matcher = findBy(locator.getUsing(), locator.getValue());
matcher.check(matches(isDisplayed()));
// If we have a match, return success
return new Element(matcher);
} catch (NoMatchingViewException e) {
throw new NoSuchElementException("Could not find element with strategy " + locator.getUsing() + " and selector " + locator.getValue());
}
}
use of android.support.test.espresso.ViewInteraction in project chefly_android by chef-ly.
the class SearchTest method searchTest.
@Test
public void searchTest() {
ViewInteraction appCompatButton = onView(allOf(withId(R.id.skipBtn), withText("Skip"), isDisplayed()));
appCompatButton.perform(click());
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction appCompatTextView = onView(allOf(withId(R.id.continueAsGuest), withText("Skip"), withParent(allOf(withId(R.id.activity_main), withParent(withId(android.R.id.content)))), isDisplayed()));
appCompatTextView.perform(click());
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction actionMenuItemView = onView(allOf(withId(R.id.action_search), withContentDescription("Search"), isDisplayed()));
actionMenuItemView.perform(click());
ViewInteraction searchAutoComplete = onView(allOf(withId(R.id.search_src_text), withParent(allOf(withId(R.id.search_plate), withParent(withId(R.id.search_edit_frame)))), isDisplayed()));
searchAutoComplete.perform(replaceText("pasta"), closeSoftKeyboard());
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction searchAutoComplete2 = onView(allOf(withId(R.id.search_src_text), withText("pasta"), withParent(allOf(withId(R.id.search_plate), withParent(withId(R.id.search_edit_frame)))), isDisplayed()));
searchAutoComplete2.perform(replaceText("pasta"), closeSoftKeyboard());
ViewInteraction searchAutoComplete3 = onView(allOf(withId(R.id.search_src_text), withText("pasta"), withParent(allOf(withId(R.id.search_plate), withParent(withId(R.id.search_edit_frame)))), isDisplayed()));
searchAutoComplete3.perform(pressImeActionButton());
ViewInteraction appCompatImageView = onView(allOf(withId(R.id.search_close_btn), withContentDescription("Clear query"), withParent(allOf(withId(R.id.search_plate), withParent(withId(R.id.search_edit_frame)))), isDisplayed()));
appCompatImageView.perform(click());
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction appCompatImageButton = onView(allOf(withContentDescription("Open navigation drawer"), withParent(withId(R.id.toolbar)), isDisplayed()));
appCompatImageButton.perform(click());
ViewInteraction appCompatCheckedTextView = onView(allOf(withId(R.id.design_menu_item_text), withText("Ingredients Search"), isDisplayed()));
appCompatCheckedTextView.perform(click());
ViewInteraction appCompatEditText = onView(allOf(withId(R.id.ingredient1EditText), withParent(allOf(withId(R.id.activitySearchIngredients), withParent(withId(android.R.id.content)))), isDisplayed()));
appCompatEditText.perform(replaceText("fish,rice"), closeSoftKeyboard());
ViewInteraction appCompatButton2 = onView(allOf(withId(R.id.findRecipes), withText("Find Recipes"), withParent(allOf(withId(R.id.activitySearchIngredients), withParent(withId(android.R.id.content)))), isDisplayed()));
appCompatButton2.perform(click());
}
use of android.support.test.espresso.ViewInteraction in project chefly_android by chef-ly.
the class ShoppinListTest method shoppinListTest.
@Test
public void shoppinListTest() {
ViewInteraction appCompatButton = onView(allOf(withId(R.id.skipBtn), withText("Skip"), isDisplayed()));
appCompatButton.perform(click());
// 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(allOf(withId(R.id.continueAsGuest), withText("Skip"), withParent(allOf(withId(R.id.activity_main), withParent(withId(android.R.id.content)))), isDisplayed()));
appCompatTextView.perform(click());
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction relativeLayout = onView(allOf(childAtPosition(withId(R.id.list), 0), isDisplayed()));
relativeLayout.perform(click());
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction textView = onView(allOf(childAtPosition(withId(R.id.ingredientGroup), 0), isDisplayed()));
textView.perform(scrollTo(), click());
pressBack();
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction appCompatImageButton = onView(allOf(withContentDescription("Open navigation drawer"), withParent(withId(R.id.toolbar)), isDisplayed()));
appCompatImageButton.perform(click());
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction appCompatCheckedTextView = onView(allOf(withId(R.id.design_menu_item_text), withText("Shopping List"), isDisplayed()));
appCompatCheckedTextView.perform(click());
ViewInteraction button = onView(allOf(withId(R.id.addBtn), withText("+"), withParent(allOf(withId(R.id.activity_shopping_list), withParent(withId(android.R.id.content)))), isDisplayed()));
button.perform(click());
ViewInteraction editText = onView(allOf(withClassName(is("android.widget.EditText")), withParent(allOf(withId(R.id.activity_shopping_list), withParent(withId(android.R.id.content)))), isDisplayed()));
editText.perform(replaceText("1 cup sugar"), closeSoftKeyboard());
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction editText2 = onView(allOf(withText("1 cup sugar"), withParent(allOf(withId(R.id.activity_shopping_list), withParent(withId(android.R.id.content)))), isDisplayed()));
editText2.perform(replaceText("1 cup sugar"), closeSoftKeyboard());
ViewInteraction editText3 = onView(allOf(withText("1 cup sugar"), withParent(allOf(withId(R.id.activity_shopping_list), withParent(withId(android.R.id.content)))), isDisplayed()));
editText3.perform(pressImeActionButton());
ViewInteraction linearLayout = onView(allOf(childAtPosition(allOf(withId(android.R.id.list), withParent(withId(R.id.activity_shopping_list))), 0), isDisplayed()));
linearLayout.perform(click());
ViewInteraction button2 = onView(allOf(withId(R.id.clearPurchasedBtn), withText("Clear Purchased"), withParent(allOf(withId(R.id.activity_shopping_list), withParent(withId(android.R.id.content)))), isDisplayed()));
button2.perform(click());
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
pressBack();
// https://google.github.io/android-testing-support-library/docs/espresso/idling-resource/index.html
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
ViewInteraction appCompatImageButton2 = onView(allOf(withContentDescription("Open navigation drawer"), withParent(withId(R.id.toolbar)), isDisplayed()));
appCompatImageButton2.perform(click());
ViewInteraction appCompatCheckedTextView2 = onView(allOf(withId(R.id.design_menu_item_text), withText("Log Out"), isDisplayed()));
appCompatCheckedTextView2.perform(click());
}
use of android.support.test.espresso.ViewInteraction in project quickstart-android by firebase.
the class MainActivityTest method caughtExceptionTest.
@Test
public void caughtExceptionTest() {
// Make sure the checkbox is on screen
ViewInteraction al = onView(allOf(withId(R.id.catchCrashCheckBox), withText(R.string.catch_crash_checkbox_label), isDisplayed()));
// Click the checkbox if it's not already checked
CheckBox checkBox = (CheckBox) mActivityTestRule.getActivity().findViewById(R.id.catchCrashCheckBox);
if (!checkBox.isChecked()) {
al.perform(click());
}
// Cause a crash
ViewInteraction ak = onView(allOf(withId(R.id.crashButton), withText(R.string.crash_button_label), isDisplayed()));
ak.perform(click());
}
use of android.support.test.espresso.ViewInteraction in project quickstart-android by firebase.
the class NewPostTest method newPostTest.
@Test
public void newPostTest() {
// Generate user and post content
String username = "user" + randomDigits();
String email = username + "@example.com";
String password = "testuser";
String postTitle = "Title " + randomDigits();
String postContent = "Content " + randomDigits();
// Go back to the sign in screen if we're logged in from a previous test
logOutIfPossible();
// Select email field
ViewInteraction appCompatEditText = onView(allOf(withId(R.id.field_email), withParent(withId(R.id.layout_email_password)), isDisplayed()));
appCompatEditText.perform(click());
// Enter email address
ViewInteraction appCompatEditText2 = onView(allOf(withId(R.id.field_email), withParent(withId(R.id.layout_email_password)), isDisplayed()));
appCompatEditText2.perform(replaceText(email));
// Enter password
ViewInteraction appCompatEditText3 = onView(allOf(withId(R.id.field_password), withParent(withId(R.id.layout_email_password)), isDisplayed()));
appCompatEditText3.perform(replaceText(password));
// Click sign up
ViewInteraction appCompatButton = onView(allOf(withId(R.id.button_sign_up), withText(R.string.sign_up), withParent(withId(R.id.layout_buttons)), isDisplayed()));
appCompatButton.perform(click());
// Click new post button
ViewInteraction floatingActionButton = onView(allOf(withId(R.id.fab_new_post), isDisplayed()));
floatingActionButton.perform(click());
// Enter post title
ViewInteraction appCompatEditText4 = onView(allOf(withId(R.id.field_title), isDisplayed()));
appCompatEditText4.perform(replaceText(postTitle));
// Enter post content
ViewInteraction appCompatEditText5 = onView(allOf(withId(R.id.field_body), isDisplayed()));
appCompatEditText5.perform(replaceText(postContent));
// Click submit button
ViewInteraction floatingActionButton2 = onView(allOf(withId(R.id.fab_submit_post), isDisplayed()));
floatingActionButton2.perform(click());
// Navigate to "My Posts"
ViewInteraction appCompatTextView = onView(allOf(withText(R.string.heading_my_posts), isDisplayed()));
appCompatTextView.perform(click());
// Check that the title is correct
ViewInteraction textView = onView(allOf(withId(R.id.post_title), withText(postTitle), isDisplayed()));
textView.check(matches(withText(postTitle)));
// Check that the content is correct
ViewInteraction textView2 = onView(allOf(withId(R.id.post_body), withText(postContent), isDisplayed()));
textView2.check(matches(withText(postContent)));
// Check that it has zero stars
ViewInteraction textView3 = onView(allOf(withId(R.id.post_num_stars), withText("0"), withParent(withId(R.id.star_layout)), isDisplayed()));
textView3.check(matches(withText("0")));
}
Aggregations