本文整理汇总了Java中android.support.test.espresso.ViewInteraction类的典型用法代码示例。如果您正苦于以下问题:Java ViewInteraction类的具体用法?Java ViewInteraction怎么用?Java ViewInteraction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ViewInteraction类属于android.support.test.espresso包,在下文中一共展示了ViewInteraction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyViewEnabledStates
import android.support.test.espresso.ViewInteraction; //导入依赖的package包/类
private static void verifyViewEnabledStates(TestCase test) {
ViewInteraction[] buttonsInteractions = getButtonInteractions();
ViewInteraction[] altButtonsInteractions = getAltButtonInteractions();
for (int digit : test.sequence) {
buttonsInteractions[digit]
.check(ViewAssertions.matches(ViewMatchers.isEnabled()))
.perform(ViewActions.click());
}
for (int i = 0; i < 10; i++) {
buttonsInteractions[i].check(matchesIsEnabled(
i >= test.numberKeysEnabledStart && i < test.numberKeysEnabledEnd));
altButtonsInteractions[0].check(matchesIsEnabled(test.leftAltKeyEnabled));
altButtonsInteractions[1].check(matchesIsEnabled(test.rightAltKeyEnabled));
}
Espresso.onView(ViewMatchers.withText(android.R.string.ok))
.check(matchesIsEnabled(test.okButtonEnabled));
ViewInteraction backspaceInteraction = Espresso.onView(
ViewMatchers.withId(R.id.nptp_backspace));
// Reset after each iteration by backspacing on the button just clicked.
backspaceInteraction.check(matchesIsEnabled(true))
.perform(ViewActions.longClick())
.check(matchesIsEnabled(false));
}
示例2: swipeOnView
import android.support.test.espresso.ViewInteraction; //导入依赖的package包/类
public static void swipeOnView(AppEventOuterClass.UIID uiid, ViewInteraction vi, AppEventOuterClass.Orientation ori){
switch(ori.getOrientType()){
case UP: vi.perform(swipeUp()); break;
case DOWN: vi.perform(swipeDown()); break;
case LEFT: vi.perform(swipeLeft()); break;
case RIGHT: vi.perform(swipeRight()); break;
case XY_TYPE:
ActivityManager activityManager = new ActivityManager();
View v = new View(activityManager.getActivityInstance().getApplicationContext());
switch(uiid.getIdType()){
case R_ID:
v = activityManager.getDecorView().findViewById(uiid.getRid());
break;
case NAME_ID:
View decorView = activityManager.getDecorView();
int resId = decorView.getResources().getIdentifier(uiid.getNameid(), "id", activityManager.getActivityInstance().getPackageName() );
v = decorView.findViewById(resId);
break;
}
if(v == null) {
return;
}
float x = v.getX();
float y = v.getY();
float centerX = x + v.getWidth() / 2;
float centerY = y + v.getHeight() / 2;
AppEventOuterClass.XYCoordin desXY = ori.getXy();
vi.perform(swipeOnCoord(centerX, centerY, desXY.getX(), desXY.getY()));
break;
}
}
示例3: swipeOnCoord
import android.support.test.espresso.ViewInteraction; //导入依赖的package包/类
public static void swipeOnCoord(ViewInteraction vi, AppEventOuterClass.XYCoordin fromXY, AppEventOuterClass.Orientation ori){
float fromX = fromXY.getX();
float fromY = fromXY.getY();
float offset = 100;
switch(ori.getOrientType()){
case UP: vi.perform(swipeOnCoord(fromX, fromY, fromX, fromY - offset));
case DOWN: vi.perform(swipeOnCoord(fromX, fromY, fromX, fromY + offset));
case LEFT: vi.perform(swipeOnCoord(fromX, fromY, fromX - offset, fromY));
case RIGHT: vi.perform(swipeOnCoord(fromX, fromY, fromX + offset, fromY));
case XY_TYPE:
AppEventOuterClass.XYCoordin ToXY = ori.getXy();
float toX = ToXY.getX();
float toY = ToXY.getY();
vi.perform(swipeOnCoord(fromX, fromY, toX, toY));
default:
break;
}
}
示例4: mainActivityTest2
import android.support.test.espresso.ViewInteraction; //导入依赖的package包/类
@Test
public void mainActivityTest2() {
ViewInteraction appCompatButton = onView(
allOf(withId(R.id.next_activity_button), withText("Next Activity"),
childAtPosition(
childAtPosition(
withId(android.R.id.content),
0),
0),
isDisplayed()));
appCompatButton.perform(click());
ViewInteraction appCompatButton2 = onView(
allOf(withId(R.id.random_button), withText("RANDOM NUMBER"),
childAtPosition(
childAtPosition(
withId(android.R.id.content),
0),
0),
isDisplayed()));
appCompatButton2.perform(click());
}
示例5: getButtonInteractions
import android.support.test.espresso.ViewInteraction; //导入依赖的package包/类
private static ViewInteraction[] getButtonInteractions() {
ViewInteraction[] buttonsInteractions = new ViewInteraction[10];
// We cannot rely on the withDigit() matcher to retrieve these because,
// after performing a click on a button, the time display will update to
// take on that button's digit text, and so withDigit() will return a matcher
// that matches multiple views with that digit text: the button
// itself and the time display. This will prevent us from performing
// validation on the same ViewInteractions later.
buttonsInteractions[0] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text10));
buttonsInteractions[1] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text0));
buttonsInteractions[2] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text1));
buttonsInteractions[3] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text2));
buttonsInteractions[4] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text3));
buttonsInteractions[5] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text4));
buttonsInteractions[6] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text5));
buttonsInteractions[7] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text6));
buttonsInteractions[8] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text7));
buttonsInteractions[9] = Espresso.onView(ViewMatchers.withId(R.id.nptp_text8));
return buttonsInteractions;
}
示例6: mainActivityTest
import android.support.test.espresso.ViewInteraction; //导入依赖的package包/类
@Test
public void mainActivityTest() throws Throwable {
ViewInteraction webView = onView(
allOf(childAtPosition(
allOf(withId(R.id.activity_main),
childAtPosition(
withId(android.R.id.content),
0)),
0),
isDisplayed()));
webView.check(matches(isDisplayed()));
ViewInteraction editText = onView(
allOf(withId(R.id.input_view),
childAtPosition(
allOf(withId(R.id.activity_main),
childAtPosition(
withId(android.R.id.content),
0)),
1),
isDisplayed()));
editText.check(matches(isDisplayed()));
}
示例7: deleteItemInTheFirstLine_ItemHasMaximumHeight_SameStartPadding
import android.support.test.espresso.ViewInteraction; //导入依赖的package包/类
@Test
public void deleteItemInTheFirstLine_ItemHasMaximumHeight_SameStartPadding() throws Exception {
//arrange
//just adapt input items list to required start values
items.remove(1);
activity.runOnUiThread(() -> activity.initialize());
ViewInteraction recyclerView = onView(withId(R.id.rvTest)).check(matches(isDisplayed()));
InstrumentalUtil.waitForIdle();
View second = layoutManager.getChildAt(1);
int startHeight = second.getHeight();
double expectedY = second.getY();
//act
recyclerView.perform(
actionDelegate(((uiController, view) -> items.remove(1))),
notifyItemRemovedAction(1));
InstrumentalUtil.waitForIdle();
second = layoutManager.getChildAt(1);
int endHeight = second.getHeight();
double resultY = second.getY();
//assert
//check test behaviour
assumeTrue(startHeight > endHeight);
assertNotEquals(0, expectedY, 0.01);
assertNotEquals(0, resultY, 0.01);
assertEquals(resultY, expectedY, 0.01);
}
示例8: performStartAdventure
import android.support.test.espresso.ViewInteraction; //导入依赖的package包/类
protected void performStartAdventure() {
ViewInteraction button = onView(allOf(withText(getString(R.string.create_new_adventure)), isDisplayed()));
button.perform(click());
//Clicks over the proper book using the property order of the GamebookEnum
DataInteraction textView = onData(anything())
.inAdapterView(allOf(withId(R.id.gamebookListView),
childAtPosition(
withClassName(is("android.widget.RelativeLayout")),
0)))
.atPosition(getGamebook().getOrder() - 1);
textView.perform(click());
button = onView(allOf(withText(getString(R.string.create_new_adventure)), isDisplayed()));
button.perform(click());
Espresso.closeSoftKeyboard();
}
示例9: definingInitialFragmentWithState
import android.support.test.espresso.ViewInteraction; //导入依赖的package包/类
@Test
public void definingInitialFragmentWithState() {
ViewInteraction appCompatButton = onView(
allOf(withId(R.id.defining_initial_fragment_with_state), withText("Defining initial fragment with state"),
childAtPosition(
childAtPosition(
withId(android.R.id.content),
0),
4),
isDisplayed()));
appCompatButton.perform(click());
ViewInteraction textView = onView(
allOf(withId(R.id.value), withText("100"),
childAtPosition(
childAtPosition(
withId(R.id.fragment_container),
0),
0),
isDisplayed()));
textView.check(matches(withText("100")));
}
示例10: openFile
import android.support.test.espresso.ViewInteraction; //导入依赖的package包/类
private void openFile(String fileName) {
openActionBarOverflowOrOptionsMenu(getInstrumentation().getTargetContext());
ViewInteraction openMenuItem = onView(
allOf(withId(R.id.title), withText("Open"),
childAtPosition(
childAtPosition(
withClassName(is("android.support.v7.view.menu.ListMenuItemView")),
0),
0),
isDisplayed()));
openMenuItem.perform(click());
onView(withText(fileName))
.perform(click());
}
示例11: performChooseWeapons
import android.support.test.espresso.ViewInteraction; //导入依赖的package包/类
public void performChooseWeapons() {
ViewInteraction button4 = onView(
allOf(withId(R.id.buttonAddweapon), withText("Add Weapon"),
childAtPosition(
withParent(withId(R.id.pager)),
1),
isDisplayed()));
button4.perform(click());
ViewInteraction button5 = onView(
allOf(withId(android.R.id.button1), withText("Ok"),
childAtPosition(
childAtPosition(
withClassName(is("android.widget.LinearLayout")),
0),
2),
isDisplayed()));
button5.perform(click());
}
示例12: definingInitialFragmentTest
import android.support.test.espresso.ViewInteraction; //导入依赖的package包/类
@Test
public void definingInitialFragmentTest() {
ViewInteraction appCompatButton = onView(
allOf(withId(R.id.defining_initial_fragment), withText("Defining initial fragment"),
childAtPosition(
childAtPosition(
withId(android.R.id.content),
0),
3),
isDisplayed()));
appCompatButton.perform(click());
ViewInteraction textView = onView(
allOf(withText("2"),
childAtPosition(
childAtPosition(
withId(R.id.fragment_container),
0),
0),
isDisplayed()));
textView.check(matches(withText("2")));
}
示例13: shouldHaveTitleAndSubtitle
import android.support.test.espresso.ViewInteraction; //导入依赖的package包/类
@Test
public void shouldHaveTitleAndSubtitle() {
ViewInteraction textView = onView(
allOf(withText("Turbo Chat"),
childAtPosition(
allOf(withId(R.id.toolbar),
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
0)),
0),
isDisplayed()));
textView.check(matches(withText("Turbo Chat")));
ViewInteraction textView2 = onView(
allOf(withText("Teams"),
childAtPosition(
allOf(withId(R.id.toolbar),
childAtPosition(
IsInstanceOf.<View>instanceOf(android.widget.LinearLayout.class),
0)),
1),
isDisplayed()));
textView2.check(matches(withText("Teams")));
}
示例14: checkDisabledButtonSend
import android.support.test.espresso.ViewInteraction; //导入依赖的package包/类
@Test
public void checkDisabledButtonSend() {
onView(withId(R.id.forgot_password)).perform(click());
onView(withId(android.R.id.button1)).check(matches(not(isEnabled())));
ViewInteraction email = onView(
allOf(withClassName(is("android.support.design.widget.TextInputEditText")),
withParent(allOf(withId(R.id.custom),
withParent(withId(R.id.customPanel)))),
isDisplayed()));
email.perform(replaceText("йцкк"), closeSoftKeyboard());
onView(withId(android.R.id.button1)).check(matches((isEnabled())));
email.perform(replaceText(""), closeSoftKeyboard());
onView(withId(android.R.id.button1)).check(matches(not(isEnabled())));
onView(withId(android.R.id.button2)).perform(click());
}
示例15: verifyMessageSentToMessageActivity
import android.support.test.espresso.ViewInteraction; //导入依赖的package包/类
@Test
public void verifyMessageSentToMessageActivity() {
ViewInteraction appCompatTextView2 = onView(
allOf(withId(R.id.subtitle), withText("NEARBY"), isDisplayed()));
appCompatTextView2.perform(click());
// Types a message into a EditText element.
onView(withId(R.id.searchText))
.perform(typeText(MESSAGE), closeSoftKeyboard());
//onView(withId(R.id.submit)).perform(click());
// Verifies that the DisplayMessageActivity received an intent
// with the correct package name and message.
// Check that the text was changed.
onView(withId(R.id.subtitle))
.check(matches(withText(MESSAGE)));
}