Initial effort toward fixing Suppress tests by integration of Espresso.
Bug: 27533946 Change-Id: I0286ff6d4c53b464180e3100b7219e766ca09de3 (cherry picked from commit 80c050b656030e070f27708bc4da5f5c7fc6cac6)
This commit is contained in:
@@ -11,7 +11,7 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src) \
|
||||
../tests/src/com/android/documentsui/StubProvider.java
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := android-support-v4 android.test.runner
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := mockito-target ub-uiautomator ub-janktesthelper
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := mockito-target ub-uiautomator ub-janktesthelper espresso-core
|
||||
|
||||
LOCAL_PACKAGE_NAME := DocumentsUIPerfTests
|
||||
LOCAL_INSTRUMENTATION_FOR := DocumentsUI
|
||||
|
||||
@@ -8,7 +8,7 @@ LOCAL_MODULE_TAGS := tests
|
||||
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
||||
|
||||
LOCAL_JAVA_LIBRARIES := android-support-v4 android.test.runner
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := mockito-target ub-uiautomator
|
||||
LOCAL_STATIC_JAVA_LIBRARIES := mockito-target ub-uiautomator espresso-core
|
||||
|
||||
LOCAL_PACKAGE_NAME := DocumentsUITests
|
||||
LOCAL_INSTRUMENTATION_FOR := DocumentsUI
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
</provider>
|
||||
</application>
|
||||
|
||||
<instrumentation android:name="android.test.InstrumentationTestRunner"
|
||||
<instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
|
||||
android:targetPackage="com.android.documentsui"
|
||||
android:label="Tests for DocumentsUI" />
|
||||
|
||||
|
||||
@@ -72,16 +72,13 @@ public class RenameDocumentUiTest extends ActivityTest<FilesActivity> {
|
||||
device.pressBack();
|
||||
}
|
||||
|
||||
@Suppress
|
||||
public void testRenameFile_OkButton() throws Exception {
|
||||
bots.directory.selectDocument(fileName1);
|
||||
bots.main.openOverflowMenu();
|
||||
bots.main.menuRename().click();
|
||||
bots.main.setDialogText(newName);
|
||||
|
||||
device.waitForIdle(TIMEOUT);
|
||||
bots.main.findDialogOkButton().click();
|
||||
device.waitForIdle(TIMEOUT);
|
||||
|
||||
bots.directory.assertDocumentsAbsent(fileName1);
|
||||
bots.directory.assertDocumentsPresent(newName);
|
||||
@@ -101,16 +98,13 @@ public class RenameDocumentUiTest extends ActivityTest<FilesActivity> {
|
||||
bots.directory.assertDocumentsCount(4);
|
||||
}
|
||||
|
||||
@Suppress
|
||||
public void testRenameFile_Cancel() throws Exception {
|
||||
bots.directory.selectDocument(fileName1);
|
||||
bots.main.openOverflowMenu();
|
||||
bots.main.menuRename().click();
|
||||
bots.main.setDialogText(newName);
|
||||
|
||||
device.waitForIdle(TIMEOUT);
|
||||
bots.main.findDialogCancelButton().click();
|
||||
device.waitForIdle(TIMEOUT);
|
||||
|
||||
bots.directory.assertDocumentsPresent(fileName1);
|
||||
bots.directory.assertDocumentsAbsent(newName);
|
||||
|
||||
@@ -39,7 +39,7 @@ public class RootsUiTest extends ActivityTest<FilesActivity> {
|
||||
|
||||
public void testRootTapped_GoToRootFromChildDir() throws Exception {
|
||||
bots.directory.openDocument(dirName1);
|
||||
bots.main.assertWindowTitle(dirName1);
|
||||
bots.main.assertBreadcrumbTitle(dirName1);
|
||||
bots.roots.openRoot(ROOT_0_ID);
|
||||
bots.main.assertWindowTitle(ROOT_0_ID);
|
||||
assertDefaultContentOfTestDir0();
|
||||
|
||||
@@ -29,7 +29,6 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
|
||||
super(FilesActivity.class);
|
||||
}
|
||||
|
||||
@Suppress
|
||||
public void testSearchView_ExpandsOnClick() throws Exception {
|
||||
bots.main.openSearchView();
|
||||
bots.main.assertSearchTextFiledAndIcon(true, false);
|
||||
@@ -43,7 +42,6 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
|
||||
bots.main.assertSearchTextFiledAndIcon(false, true);
|
||||
}
|
||||
|
||||
@Suppress
|
||||
public void testSearchView_ClearsTextOnBack() throws Exception {
|
||||
String query = "file2";
|
||||
bots.main.openSearchView();
|
||||
@@ -54,7 +52,6 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
|
||||
bots.main.assertSearchTextFiledAndIcon(false, true);
|
||||
}
|
||||
|
||||
@Suppress
|
||||
public void testSearch_ResultsFound() throws Exception {
|
||||
initTestFiles();
|
||||
assertDefaultContentOfTestDir0();
|
||||
@@ -64,7 +61,7 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
|
||||
bots.main.setSearchQuery(query);
|
||||
bots.main.assertSearchTextField(true, query);
|
||||
|
||||
device.pressEnter();
|
||||
bots.keyboard.pressEnter();
|
||||
|
||||
bots.directory.assertDocumentsCountOnList(true, 2);
|
||||
bots.directory.assertDocumentsPresent(fileName1, fileName2);
|
||||
@@ -90,7 +87,7 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
|
||||
bots.main.openSearchView();
|
||||
bots.main.setSearchQuery(query);
|
||||
|
||||
device.pressEnter();
|
||||
bots.keyboard.pressEnter();
|
||||
|
||||
bots.directory.assertDocumentsCountOnList(true, 1);
|
||||
bots.directory.assertDocumentsPresent(fileName2);
|
||||
@@ -98,7 +95,6 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
|
||||
device.pressBack();
|
||||
}
|
||||
|
||||
@Suppress
|
||||
public void testSearchResultsFound_ClearsOnBack() throws Exception {
|
||||
initTestFiles();
|
||||
assertDefaultContentOfTestDir0();
|
||||
@@ -107,13 +103,12 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
|
||||
bots.main.openSearchView();
|
||||
bots.main.setSearchQuery(query);
|
||||
|
||||
device.pressEnter();
|
||||
bots.keyboard.pressEnter();
|
||||
device.pressBack();
|
||||
|
||||
assertDefaultContentOfTestDir0();
|
||||
}
|
||||
|
||||
@Suppress
|
||||
public void testSearch_NoResults() throws Exception {
|
||||
initTestFiles();
|
||||
assertDefaultContentOfTestDir0();
|
||||
@@ -122,18 +117,16 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
|
||||
bots.main.openSearchView();
|
||||
bots.main.setSearchQuery(query);
|
||||
|
||||
device.pressEnter();
|
||||
bots.keyboard.pressEnter();
|
||||
|
||||
bots.directory.assertDocumentsCountOnList(false, 0);
|
||||
bots.directory.assertDocumentsCountOnList(true, 0);
|
||||
|
||||
device.waitForIdle();
|
||||
String msg = String.valueOf(context.getString(R.string.no_results));
|
||||
bots.directory.assertMessageTextView(String.format(msg, "TEST_ROOT_0"));
|
||||
|
||||
bots.main.assertSearchTextField(false, query);
|
||||
}
|
||||
|
||||
@Suppress
|
||||
public void testSearchNoResults_ClearsOnBack() throws Exception {
|
||||
initTestFiles();
|
||||
assertDefaultContentOfTestDir0();
|
||||
@@ -142,14 +135,13 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
|
||||
bots.main.openSearchView();
|
||||
bots.main.setSearchQuery(query);
|
||||
|
||||
device.pressEnter();
|
||||
bots.keyboard.pressEnter();
|
||||
device.pressBack();
|
||||
|
||||
device.waitForIdle();
|
||||
assertDefaultContentOfTestDir0();
|
||||
}
|
||||
|
||||
@Suppress
|
||||
public void testSearchResultsFound_ClearsOnDirectoryChange() throws Exception {
|
||||
initTestFiles();
|
||||
assertDefaultContentOfTestDir0();
|
||||
@@ -158,7 +150,7 @@ public class SearchViewUiTest extends ActivityTest<FilesActivity> {
|
||||
bots.main.openSearchView();
|
||||
bots.main.setSearchQuery(query);
|
||||
|
||||
device.pressEnter();
|
||||
bots.keyboard.pressEnter();
|
||||
|
||||
bots.roots.openRoot(ROOT_1_ID);
|
||||
assertDefaultContentOfTestDir1();
|
||||
|
||||
@@ -16,9 +16,14 @@
|
||||
|
||||
package com.android.documentsui.bots;
|
||||
|
||||
import static android.support.test.espresso.Espresso.onView;
|
||||
import static android.support.test.espresso.action.ViewActions.pressImeActionButton;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.test.uiautomator.UiDevice;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
|
||||
/**
|
||||
* A test helper class that provides support for keyboard manipulation.
|
||||
@@ -43,8 +48,9 @@ public class KeyboardBot extends BaseBot {
|
||||
}
|
||||
|
||||
public void pressEnter() {
|
||||
waitForIdle();
|
||||
mDevice.pressEnter();
|
||||
waitForIdle();
|
||||
//TODO: There seems to be a bug on N/Espresso that makes pressing Enter not work
|
||||
// This is a temporary workaround that somehow works
|
||||
// See b/28399576
|
||||
onView(isAssignableFrom(EditText.class)).perform(pressImeActionButton());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,17 @@
|
||||
|
||||
package com.android.documentsui.bots;
|
||||
|
||||
import static android.support.test.espresso.Espresso.onView;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.isAssignableFrom;
|
||||
import static android.support.test.espresso.assertion.ViewAssertions.matches;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.test.espresso.matcher.BoundedMatcher;
|
||||
import android.support.test.uiautomator.By;
|
||||
import android.support.test.uiautomator.UiDevice;
|
||||
import android.support.test.uiautomator.UiObject;
|
||||
@@ -29,8 +34,15 @@ import android.support.test.uiautomator.UiObject2;
|
||||
import android.support.test.uiautomator.UiObjectNotFoundException;
|
||||
import android.support.test.uiautomator.UiSelector;
|
||||
import android.support.test.uiautomator.Until;
|
||||
import android.util.Log;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.Toolbar;
|
||||
|
||||
import com.android.documentsui.R;
|
||||
import com.android.documentsui.model.DocumentInfo;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@@ -51,19 +63,13 @@ public class UiBot extends BaseBot {
|
||||
}
|
||||
|
||||
public void assertWindowTitle(String expected) {
|
||||
// Turns out the title field on a window does not have
|
||||
// an id associated with it at runtime (which confuses the hell out of me)
|
||||
// In code we address this via "android.R.id.title".
|
||||
UiObject2 o = find(By.text(expected));
|
||||
// It's a bit of a conceit that we then *assert* that the title
|
||||
// is the value that we used to identify the UiObject2.
|
||||
// If the preceeding lookup fails, this'll choke with an NPE.
|
||||
// But given the issue described in the comment above, we're
|
||||
// going to do it anyway. Because we shouldn't be looking up
|
||||
// the uiobject by it's expected content :|
|
||||
assertEquals(expected, o.getText());
|
||||
onView(isAssignableFrom(Toolbar.class)).check(matches(withToolbarTitle(is(expected))));
|
||||
}
|
||||
|
||||
public void assertBreadcrumbTitle(String expected) {
|
||||
onView(isAssignableFrom(Spinner.class)).check(matches(withBreadcrumbTitle(is(expected))));
|
||||
}
|
||||
|
||||
public void assertMenuEnabled(int id, boolean enabled) {
|
||||
UiObject2 menu= findMenuWithName(mContext.getString(id));
|
||||
assertNotNull(menu);
|
||||
@@ -228,4 +234,31 @@ public class UiBot extends BaseBot {
|
||||
public void pressKey(int keyCode, int metaState) {
|
||||
mDevice.pressKeyCode(keyCode, metaState);
|
||||
}
|
||||
|
||||
private static Matcher<Object> withToolbarTitle(
|
||||
final Matcher<CharSequence> textMatcher) {
|
||||
return new BoundedMatcher<Object, Toolbar>(Toolbar.class) {
|
||||
@Override public boolean matchesSafely(Toolbar toolbar) {
|
||||
return textMatcher.matches(toolbar.getTitle());
|
||||
}
|
||||
@Override public void describeTo(Description description) {
|
||||
description.appendText("with toolbar title: ");
|
||||
textMatcher.describeTo(description);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static Matcher<Object> withBreadcrumbTitle(
|
||||
final Matcher<CharSequence> textMatcher) {
|
||||
return new BoundedMatcher<Object, Spinner>(Spinner.class) {
|
||||
@Override public boolean matchesSafely(Spinner breadcrumb) {
|
||||
DocumentInfo selectedDoc = (DocumentInfo) breadcrumb.getSelectedItem();
|
||||
return textMatcher.matches(selectedDoc.displayName);
|
||||
}
|
||||
@Override public void describeTo(Description description) {
|
||||
description.appendText("with breadcrumb title: ");
|
||||
textMatcher.describeTo(description);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user