我从SurfaceView扩展了一个GameView
课程。我在activity_main布局中添加了这个视图,如下所示:
gameView = new GameView(MainActivity.this);
activity_main = findViewById(R.id.activity_main);
activity_main.addView(gameView);
现在我想使用Espresso UI测试在此SurfaceView上执行任何视图操作(即单击)。到目前为止,我想出了这个:
DataInteraction surfaceView = onData(instanceOf(GameView.class))
.inAdapterView(withClassName(is("android.view.SurfaceView")));
surfaceView.perform(click());
但这不是正确的方法,因为它会出现以下错误:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with class name: is "android.view.SurfaceView"
如何找到视图?
答案 0 :(得分:0)
使用getName()解决了问题。
ViewInteraction surfaceView = onView(withClassName(equalTo(GameView.class.getName())));
surfaceView.perform(click());