I am having problems to test display word in ITALIC style. Can someone provide me any example code to display word style? I am using Espresso and JUnit 4 in android studio. I really appreciated your cooperation. Thank you
Please try out the following solution. It might work for you. The core idea is considering using custom ViewMatcher for your case.
public static Matcher<View> withItalicStyle(final int resourceId) {
return new TypeSafeMatcher<View>() {
@Override
public void describeTo(Description description) {
description.appendText("has Italic Text with resource" );
}
@Override
public boolean matchesSafely(View view) {
TextView textView = (TextView) view.findViewById(resourceId);
return (textView.getTypeface().getStyle() == Typeface.ITALIC);
}
};
}
And in you testcase, you can
onView(CustomMatchers.withItalicStyle(R.id.yourResourceId)).check(isDisplayed());
For tutorial, please check goole samples in https://github.com/googlesamples/android-testing/blob/master/ui/espresso/IdlingResourceSample/app/src/main/java/com/example/android/testing/espresso/IdlingResourceSample/MainActivity.java
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With