16922

android espresso : total count of elements with samerid not in adapter view

Question:

I am trying to get the count of elements with same rid

The solutions here <a href="https://stackoverflow.com/questions/27430500/how-to-get-count-of-items-with-same-ids-which-are-not-in-adapter-view" rel="nofollow">How to get count of items with same ids which are not in adapter view</a> is not helping me.

static int counter = 0; public static Matcher<View> withIdAndDisplayed(final int id) { Checks.checkNotNull(id); return new TypeSafeMatcher<View>() { @Override public void describeTo(Description description) { description.appendText("with item id: " + id); } @Override public boolean matchesSafely(View view) { if ((view.getId() == id) && (view.getGlobalVisibleRect(new Rect()) && withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE).matches(view))){ counter++; return true; } return false; } }; }

Answer1:

<strong>Update:</strong>

I see you trying to get child view count which is not an adapterView. See this one <a href="https://groups.google.com/forum/#!topic/android-test-kit-discuss/avLaBnBWr70" rel="nofollow">https://groups.google.com/forum/#!topic/android-test-kit-discuss/avLaBnBWr70</a>

<strong>Original answer:</strong>

Are you using RecyclerView?

I used below code in my tests to get the RecyclerView size.

public static Matcher<View> withRecyclerViewSize(final int size) { return new TypeSafeMatcher<View>() { @Override public boolean matchesSafely(final View view) { final int actualListSize = ((RecyclerView) view).getAdapter().getItemCount(); LOGD(TAG, "RecyclerView actual size " + actualListSize); return actualListSize == size; } @Override public void describeTo(final Description description) { description.appendText("RecyclerView should have " + size + " items"); } }; }

Usage: onView(withId(R.id.resource_id)).check(matches(withRecyclerViewSize(expectedSize)));

In this case resource_id is RecyclerView.

There are few examples here: <a href="https://gist.github.com/chemouna/00b10369eb1d5b00401b" rel="nofollow">https://gist.github.com/chemouna/00b10369eb1d5b00401b</a>.

Recommend

  • reformat multidimensional array based on value
  • java.lang.NullPointerException while trying to run google driver example
  • Assembly program crashes on call or exit
  • Espresso onData perform click on multiple items
  • How can I display changed line in Emacs?
  • Espresso - Check RecyclerView items are ordered correctly
  • Complex conditional element in accumulate in Jess rules
  • How send image from java applet to javascript?
  • visual basic: object reference not set to an instance of an object
  • How to get a specific type object from an Object Vector in Java
  • Using a BlockingCollection to queue Tasks
  • Writing text to file from multiple instances of program
  • replacement of asp:Treeview for ASP.NET MVC application
  • Slow performance using mysqldump from C#
  • How can I get the maximum number of OpenMP threads that may be created during the whole execution of
  • PHP Handling Namespace with SimpleXML
  • How to resolve “ Multiplicity is not valid in Role” error?
  • How to Update model and database with code first approach in Asp.net MVC
  • Java : Simple XML not parsing the xml. Gives Exception
  • Implementing an abstract function with access types in Ada
  • update record in database using jdatabase
  • Does Apple allow the usage of sysctl.h within iOS applications?
  • How to add git credentials to the build so it would be able to be used within a shell code?
  • How can the INSERT … ON CONFLICT (id) DO UPDATE… syntax be used with a sequence ID?
  • QLPreviewController hide print button in ios6
  • Uncaught Error: Could not find module `ember-load-initializers`
  • Java static initializers and reflection
  • Exception on Android 4.0 `android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode)`
  • Change div Background jquery
  • Bitwise OR returns boolean when one of operands is nil
  • unknown Exception android
  • EntityFramework adding new object to nested object collection
  • Is there any way to bind data to data.frame by some index?
  • Checking variable from a different class in C#
  • Django query for large number of relationships
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • failed to connect to specific WiFi in android programmatically
  • How to push additional view controllers onto NavigationController but keep the TabBar?
  • How can I use threading to 'tick' a timer to be accessed by other threads?