public final class

LayoutMatchers

extends java.lang.Object

 java.lang.Object

↳androidx.test.espresso.matcher.LayoutMatchers

Gradle dependencies

compile group: 'androidx.test.espresso', name: 'espresso-core', version: '3.5.0-alpha06'

  • groupId: androidx.test.espresso
  • artifactId: espresso-core
  • version: 3.5.0-alpha06

Artifact androidx.test.espresso:espresso-core:3.5.0-alpha06 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.test.espresso:espresso-core com.android.support.test.espresso:espresso-core

Androidx class mapping:

androidx.test.espresso.matcher.LayoutMatchers android.support.test.espresso.matcher.LayoutMatchers

Overview

A collection of hamcrest matches to detect typical layout issues.

Summary

Methods
public static <any>hasEllipsizedText()

Matches TextView elements having ellipsized text.

public static <any>hasMultilineText()

Matches TextView elements having multiline text.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods

public static <any> hasEllipsizedText()

Matches TextView elements having ellipsized text. If text is too long to fit into a TextView, it can be either ellipsized ('Too long' shown as 'Too l…' or '… long') or cut off ('Too long' shown as 'Too l'). Though acceptable in some cases, usually indicates bad user experience.

public static <any> hasMultilineText()

Matches TextView elements having multiline text.

Source

/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.test.espresso.matcher;

import android.text.Layout;
import android.view.View;
import android.widget.TextView;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

/** A collection of hamcrest matches to detect typical layout issues. */
public final class LayoutMatchers {

  private LayoutMatchers() {}

  /**
   * Matches TextView elements having ellipsized text. If text is too long to fit into a TextView,
   * it can be either ellipsized ('Too long' shown as 'Too l…' or '… long') or cut off ('Too long'
   * shown as 'Too l'). Though acceptable in some cases, usually indicates bad user experience.
   */
  public static Matcher<View> hasEllipsizedText() {
    return new TypeSafeMatcher<View>(TextView.class) {
      @Override
      public void describeTo(Description description) {
        description.appendText("has ellipsized text");
      }

      @Override
      public boolean matchesSafely(View tv) {
        Layout layout = ((TextView) tv).getLayout();
        if (layout != null) {
          int lines = layout.getLineCount();
          return lines > 0 && layout.getEllipsisCount(lines - 1) > 0;
        }
        return false;
      }
    };
  }

  /** Matches TextView elements having multiline text. */
  public static Matcher<View> hasMultilineText() {
    return new TypeSafeMatcher<View>(TextView.class) {
      @Override
      public void describeTo(Description description) {
        description.appendText("has more than one line of text");
      }

      @Override
      public boolean matchesSafely(View tv) {
        return ((TextView) tv).getLineCount() > 1;
      }
    };
  }
}