some RxJava information:
http://www.jianshu.com/p/52cd2d514528Github:
https://github.com/roy989898/tryOKHTTP-withRXjava
@Test
public void ahouldBeAbleToAddTaskAndTheTaskShow(){
// click the new button
onView(withId(R.id.menu_main_new_task)).perform(click());
// click task name
// input Task1
onView(withId(R.id.new_task_task_name)).perform(click()).perform(typeText("Task1"));
// Click task Description
// Task1 Desc
onView(withId(R.id.new_task_task_desc)).perform(click()).perform(typeText("Task1 Desc"));
// CLick Add
onView(withId(R.id.new_task_add)).perform(click());
// Task1 appear
onView(withText("Task1")).check(matches(isDisplayed()));
}
|
androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.1') {
exclude module: 'support-annotations'
exclude module: 'support-v4'
exclude module: 'support-v13'
exclude module: 'recyclerview-v7'
}
|
onView(withId(R.id.main_task_list)).perform(RealmRecyclerViewActions.scrollToPosition(12));
onView(withText("Task10")).check(matches(isDisplayed()));
|
@Test
public void ahouldBeAbleToAddTaskAndTheTaskShow(){
for(int i=0;i<15;i++){
// click the new button
onView(withId(R.id.menu_main_new_task)).perform(click());
// click task name
// input Task1
onView(withId(R.id.new_task_task_name)).perform(click()).perform(typeText("Task"+i));
// Click task Description
// Task1 Desc
onView(withId(R.id.new_task_task_desc)).perform(click()).perform(typeText("Task1"+i+" Desc"));
// CLick Add
onView(withId(R.id.new_task_add)).perform(click());
}
// Task1 appear
onView(withText("Task1")).check(matches(isDisplayed()));
// scroll to Tasl 10
// Task 10 appear
onView(withId(R.id.main_task_list)).perform(RealmRecyclerViewActions.scrollToPosition(12));
onView(withText("Task10")).check(matches(isDisplayed()));
}
|
onView(withId(R.id.main_task_list)).perform(RealmRecyclerViewActions.scrollToPosition(12));
|
onView(withId(R.id.main_task_list)).perform(RealmRecyclerViewActions.scrollTo(withText("Task10")));
|
public static Matcher<View> withTaskName(final String expected){
return new TypeSafeMatcher<View>() {
@Override
protected boolean matchesSafely(View item) {
if(item==null)
return false;
else {
TextView taskName = (TextView) item.findViewById(R.id.task_item_task_name);
if(taskName!=null&& !TextUtils.isEmpty(taskName.getText())&&taskName.getText().toString().equals(expected)){
return true;
}else
return false;
}
}
@Override
public void describeTo(Description description) {
description.appendText("look for "+expected+" in the recycle view");
}
};
}
|
public static Matcher<View> withImageDrawable(final int resourceId) {
return new BoundedMatcher<View, ImageView>(ImageView.class) {
@Override
public void describeTo(Description description) {
description.appendText("has image drawable resource " + resourceId);
}
@Override
public boolean matchesSafely(ImageView imageView) {
return sameBitmap(imageView.getContext(), imageView.getDrawable(), resourceId);
}
};
}
private static boolean sameBitmap(Context context, Drawable drawable, int resourceId) {
Drawable otherDrawable = context.getResources().getDrawable(resourceId);
if (drawable == null || otherDrawable == null) {
return false;
}
if (drawable instanceof StateListDrawable && otherDrawable instanceof StateListDrawable) {
drawable = drawable.getCurrent();
otherDrawable = otherDrawable.getCurrent();
}
if (drawable instanceof BitmapDrawable) {
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
Bitmap otherBitmap = ((BitmapDrawable) otherDrawable).getBitmap();
return bitmap.sameAs(otherBitmap);
}
return false;
}
|
The current drawable that will be used by this drawable. For simple drawables, this is just the drawable itself. For drawables that change state like StateListDrawable and LevelListDrawable this will be the child drawable currently in use.
|