logo
down
shadow

Assert progress of ProgressBar in Espresso test


Assert progress of ProgressBar in Espresso test

By : Cosmin
Date : January 11 2021, 03:32 PM
should help you out It would seem Espresso does not allow to check the progress attribute using a ViewInteraction. Although, it is possible to recover the progress bar view directly from the view and to assert its value using assertThat.
code :
@Test
public void ExampleAssertProgressBar(){
    ProgressBar progressBar = activity.getActivity().findViewById(R.id.progressBar);
    int progress = progressBar.getProgress();
    assertThat(progress, equalTo(50));
}


Share : facebook icon twitter icon
Espresso android -- Evoke assert? (NOT a view assert)

Espresso android -- Evoke assert? (NOT a view assert)


By : user3324038
Date : March 29 2020, 07:55 AM
will help you It's possible to enable keyword asserts, but it requires a manual step, and it would be unusual to use keyword asserts in test code.
It's best to use the JUnit methods (assertTrue, etc.) as you would in unit tests.
Espresso: How do i assert if a particular activity is launched when i click on a item using espresso

Espresso: How do i assert if a particular activity is launched when i click on a item using espresso


By : RayB
Date : March 29 2020, 07:55 AM
Hope that helps You should simulate the process of clicking a button and then test if the activity at the top of the stack is the one you're looking for
code :
@RunWith(AndroidJUnit4.class)
public class YourTestClass{


    @Test
    public void testButton() {
        Espresso.onView(ViewMatchers.withId(R.id.yourButtonId)).perform(ViewActions.click());

        Assert.assertEquals(getActivityInstance().getClass(), YourActivityThatShouldStart.class);
    }

    private Activity getActivityInstance() {
        final Activity[] currentActivity = {null};
        InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
            public void run() {
                Collection resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
                if (resumedActivities.iterator().hasNext()) {
                    currentActivity[0] = (Activity) resumedActivities.iterator().next();
                }
            }
        });

        return currentActivity[0];
    }

}
It is possible to test view below a progress dialog, using espresso?

It is possible to test view below a progress dialog, using espresso?


By : franceska
Date : March 29 2020, 07:55 AM
wish helps you Yes, you use a RootMatcher. For example:
code :
// Specifically target the main window view hierarchy
onView(withId(R.id.view_to_match))
    .inRoot(withDecorView(is(getActivity().getWindow().getDecorView())))
    .perform(click());
// Specifically disregard the dialog window view hierarchy
onView(withId(R.id.view_to_match))
    .inRoot(not(isDialog()))
    .perform(click());
any method to wait until invisible progressbar in espresso test?

any method to wait until invisible progressbar in espresso test?


By : jameslopez
Date : March 29 2020, 07:55 AM
wish of those help So, you want to wait until your ProgressBar is hidden. You can either create an idling resource or use a custom ViewAction as this one:
code :
/**
 * Perform action of waiting until the element is accessible & not shown.
 * @param viewId The id of the view to wait for.
 * @param millis The timeout of until when to wait for.
 */
public static ViewAction waitUntilNotShown(final int viewId, final long millis) {
    return new ViewAction() {
        @Override
        public Matcher<View> getConstraints() {
            return isRoot();
        }

        @Override
        public String getDescription() {
            return "wait for a specific view with id <" + viewId + "> is hidden during " + millis + " millis.";
        }

        @Override
        public void perform(final UiController uiController, final View view) {
            uiController.loopMainThreadUntilIdle();
            final long startTime = System.currentTimeMillis();
            final long endTime = startTime + millis;
            final Matcher<View> viewMatcher = withId(viewId);

            do {
                for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
                    // found view with required ID
                    if (viewMatcher.matches(child) && !child.isShown()) {
                        return;
                    }
                }

                uiController.loopMainThreadForAtLeast(50);
            }
            while (System.currentTimeMillis() < endTime);

            // timeout happens
            throw new PerformException.Builder()
                    .withActionDescription(this.getDescription())
                    .withViewDescription(HumanReadables.describe(view))
                    .withCause(new TimeoutException())
                    .build();
        }
    };
}
onView(isRoot()).perform(waitUntilNotShown(R.id.theIdToWaitFor, 5000));
Assert exceptions in Android Espresso test

Assert exceptions in Android Espresso test


By : cloudsoft
Date : March 29 2020, 07:55 AM
may help you . Eventually I found a way to do it. I've created a custom Hamcrest matcher that allows you to verify a nested exception.
code :
public class NestedExceptionMatcher extends TypeSafeMatcher<Throwable> {

    private final Class<?> mExpectedType;
    private final Matcher<String> mMessageMatcher;

    static NestedExceptionMatcher expectNestedThrowable(Class<?> expectedType, Matcher<String> messageMatcher) {
        return new NestedExceptionMatcher(expectedType, messageMatcher);
    }

    NestedExceptionMatcher(Class<?> expectedType, Matcher<String> messageMatcher) {
        mExpectedType = expectedType;
        mMessageMatcher = messageMatcher;
    }

    @Override
    protected boolean matchesSafely(Throwable item) {
        boolean matches = isMatch(item);

        Throwable currentThrowable = item.getCause();
        while (!matches && currentThrowable != null) {
            matches = isMatch(currentThrowable);
            currentThrowable = currentThrowable.getCause();
        }

        return matches;
    }

    @Override
    public void describeTo(Description description) {
        description
                .appendText("expects type ")
                .appendValue(mExpectedType)
                .appendText(" with a message ")
                .appendDescriptionOf(mMessageMatcher);
    }

    private boolean isMatch(Throwable t) {
        return t.getClass().isAssignableFrom(mExpectedType) && mMessageMatcher.matches(t.getMessage());
    }
}
public class SomeActivityTest {

    @Rule
    public ActivityTestRule<SomeActivity> mRule = new ActivityTestRule<>(
            SomeActivity.class, false, false);

    @Rule
    public ExpectedException mExceptionRule = ExpectedException.none();

    @Test
    public void testClick_whenInvalidParamsAreSet_shouldThrowException() {
        mRule.launchActivity(getIntentWithInvalidParams());
        mExceptionRule.expect(expectNestedThrowable(
                IllegalArgumentException.class,
                containsString("parameter isn't defined")
        ));

        onView(withId(R.id.my_btn)).perform(click());
    }

    private Intent getIntentWithInvalidParams() {
        ...
    }
}
Related Posts Related Posts :
  • Android Broadcastreceiver for other apps install/delete not working
  • Android Studio onClick not working in BindViewHolder
  • How to use Spring Converter for some controllers only?
  • How verify that 3 numbers in sequence are equals?
  • When using .compareTo to compare dates, why doesn't it take Months into account?
  • Does the perfomance of "filter then map" and "map then filter" differ in a Stream?
  • How can I set the initial Delay after pressing the start Button to a specific time (HH:mm:ss) format
  • How to switch between Android devices during the tests
  • How to configure java.util.logging via properties to use standard output?
  • How to iterate through array in order
  • Is there better way of iteration to find the evenly divisible number?
  • How to split a string to non empty words if it might include a separator like tab on first place
  • Supplier<Sequence<String>> cannot be iterated more than once
  • Why there is only one thread can actually started in @PostConstruct method?
  • Manage CompletionStage inside of Netty handler
  • Url Problem while Developing on Localhost and deploy on Remote Virtual Server
  • How to identify the missing type id in Jackson error?
  • android data binding error: cannot find symbol
  • Spring Boot application with a jar dependency does not run after maven build
  • Spring Data JPA query , filter ? search engine ? JPQL?
  • Why LiveData returns null in ViewModel?
  • what this line of code mean....new URLClassLoader(new URL[0],getClass().getClassLoader());
  • Why do need to use new Random() instead of just Random Randomnum?
  • I want to access zk components from the java file
  • How do I cast FieldValue.serverTimestamp() to Kotlin/Java Date Class
  • Insertion Sort Double Array with User Input - JAVA
  • Creating 2 dimesional array with user input and find sum of specific columns
  • can not get Advertising ID Provider in android
  • Convert list of Objects to map of properties
  • How to represent an undirected weighted graph in java
  • Return values as array from collection
  • ByteBuddy generic method return cast to concrete type
  • ImageView hides the round corners of the parent
  • Is there a way to find setter method by its getter method or vice versa in a class?
  • Get aggregated list of properties from list of Objects(Java 8)
  • Unable to find a document in Mongodb where exact date match in java
  • UsernamePasswordAuthenticationFilter skips success handler
  • Use Java filter on stream with in a stream filter
  • Default Login not successful in spring boot 2.1.7
  • Adding key value pairs from a file to a Hashmap
  • Rub regex: matching a char except when after by another char
  • Convert Base64 String to String Array
  • Escape Unicode Character 'POPCORN' to HTML Entity
  • An empty JSON field which is a boolean/nullable field in Java model, is getting converted as null
  • Mongo java driver cannot find public constructor for interface
  • How to unit test writing a file to AWS Lambda output stream?
  • How to make a GitHub GraphQL API Call from Java
  • What's the difference between @ComponentScan and @Bean in a context configuration?
  • Expected class or package adding a view using a class
  • can be delete of a element in a static array be O(1)?
  • Instance variable heap or stack ? ( with specific example)
  • How to detect if gson.fromjson() has excess elements
  • I cant generate the proper code to select the a specific filter on a BI dashboard I am working on
  • How to Inject Dependencies into a Servlet Filter with Spring Boot Filter Registration Bean?
  • Thrift types as a Generic
  • Effective algorithm to random 4 unique integers less than a big max such as 100_000
  • Combining or and negation in Java regex?
  • Unable to instantiate default tuplizer Exception
  • Multi-tenant migration to work with quarkus
  • Ignite persisting a Set: Cannot find metadata for object with compact footer
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org