J'ai des problèmes pour tester le mot d'affichage dans le style ITALIQUE. Quelqu'un peut-il me fournir un exemple de code pour afficher le style de mot? J'utilise Espresso et JUnit 4 dans le studio android. J'ai vraiment apprécié votre coopération. MerciComment tester le style de mot "ITALIC" dans Espresso Testing
Répondre
Cela devrait rendre votre TextView
gras, souligné et italic en même temps.
strings.xml
<resources>
<string name="register"><u><b><i>Copyright</i></b></u></string>
</resources>
Pour définir cette chaîne à votre TextView, faites ceci dans votre main.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/register" />
Oui. j'ai déjà ça. Maintenant, je veux tester ITALIC WORD dans l'automatisation de test en utilisant Android Studio – intan
S'il vous plaît essayer les éléments suivants Solution. Cela pourrait marcher pour vous. L'idée principale consiste à utiliser ViewMatcher personnalisé pour votre cas.
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);
}
};
}
Et vous TESTCASE, vous pouvez
onView(CustomMatchers.withItalicStyle(R.id.yourResourceId)).check(isDisplayed());
Pour tutoriel, s'il vous plaît vérifier les échantillons goole dans https://github.com/googlesamples/android-testing/blob/master/ui/espresso/IdlingResourceSample/app/src/main/java/com/example/android/testing/espresso/IdlingResourceSample/MainActivity.java
Vous pouvez éviter de coulée avec le [BoundedMatcher] (https://developer.android.com/reference/android/support/test/espresso/matcher/BoundedMatcher.html) –
Utiliser 'android: TEXTSTYLE = "italic"'. – KeLiuyue
@KeLiuyue .. Merci. mais comment tester à l'intérieur de Test Automation. – intan