Issue
I have a class GameView extended from SurfaceView. I added this view in activity_main layout like this:
gameView = new GameView(MainActivity.this);
activity_main = findViewById(R.id.activity_main);
activity_main.addView(gameView);
Now I want to perform any view action (i.e. click) on this SurfaceView using Espresso UI test. So far I came up with this:
DataInteraction surfaceView = onData(instanceOf(GameView.class))
.inAdapterView(withClassName(is("android.view.SurfaceView")));
surfaceView.perform(click());
But this is not the right way cause it gives the following error:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with class name: is "android.view.SurfaceView"
How can I find the view?
Solution
Using getName() solved the problem.
ViewInteraction surfaceView = onView(withClassName(equalTo(GameView.class.getName())));
surfaceView.perform(click());
Answered By - Nafis
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.