Androidエスプレッソテストを作成して、動画が再生されているかどうかを確認しようとしています。再生ボタンをクリックした後に私のSimpleExoPlayerView
の関連プレイヤーがプレイしているかどうかを確認しています。問題は、SimpleExoPlayerView
と同じIDを持つ階層にPlaybackControlView
があることです(設定しないので、同じIDを持つ方法がわかりません)。 SimpleExoPlayerView
をテストするように指定するにはどうすればよいですか?ここでAmbiguousViewMatcherException SimpleExoPlayerView Android
私のテストで:
@RunWith(AndroidJUnit4.class)
public class VideoPlaybackTest {
@Rule
public ActivityTestRule<MainActivity> mMainActivityTestRule =
new ActivityTestRule<MainActivity>(MainActivity.class);
@Before
public void registerIdlingResources() {
Espresso.registerIdlingResources(mMainActivityTestRule.getActivity().getIdlingResource());
}
@Test
public void videoIsPlayed() {
Intents.init();
onView(withId(R.id.recipes_recycler_view))
.perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
onView(withId(R.id.steps_recycler_view))
.perform(RecyclerViewActions.actionOnItemAtPosition(0, click()));
onView(withId(R.id.exo_play))
.perform(click());
onView(withId(R.id.simple_video_view))
.check(new VideoPlaybackAssertion(true));
Intents.release();
}
@After
public void unregisterIdlingResources() {
Espresso.unregisterIdlingResources(mMainActivityTestRule.getActivity().getIdlingResource());
}
}
class VideoPlaybackAssertion implements ViewAssertion {
private final Matcher<Boolean> matcher;
//Constructor
public VideoPlaybackAssertion(Matcher<Boolean> matcher) {
this.matcher = matcher;
}
//Sets the Assertion's matcher to the expected playbck state.
public VideoPlaybackAssertion(Boolean expectedState) {
this.matcher = is(expectedState);
}
//Method to check if the video is playing.
@Override
public void check(View view, NoMatchingViewException noViewFoundException) {
if (noViewFoundException != null) {
throw noViewFoundException;
}
SimpleExoPlayerView exoPlayerView = (SimpleExoPlayerView) view;
SimpleExoPlayer exoPlayer = exoPlayerView.getPlayer();
int state = exoPlayer.getPlaybackState();
Boolean isPlaying;
if ((state == STATE_BUFFERING) || (state == STATE_READY)) {
isPlaying = true;
} else {
isPlaying = false;
}
assertThat(isPlaying, matcher);
}
}
android.support.test.espresso.AmbiguousViewMatcherException: 'idを持つ: com.example.android.bakingapp:ID/simple_video_view' で複数の 意見が一致します階層。
同じIDを持つ2つのビューが私のSimpleExoPlayerView
と私は本当に理解していないPlaybackControlView
です。