AS2.2 Preview3がリリースされましたね。その中で、個人的に待っていたEspresso Test Recorderが実装されたので試してみました。
https://sites.google.com/a/android.com/tools/recent/androidstudio22preview3available
生成されたコードはこちら。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.kazucocoa.droidtodo; | |
| import android.support.test.espresso.ViewInteraction; | |
| import android.support.test.rule.ActivityTestRule; | |
| import android.support.test.runner.AndroidJUnit4; | |
| import android.test.suitebuilder.annotation.LargeTest; | |
| import org.junit.Rule; | |
| import org.junit.Test; | |
| import org.junit.runner.RunWith; | |
| import static android.support.test.espresso.Espresso.onView; | |
| import static android.support.test.espresso.action.ViewActions.*; | |
| import static android.support.test.espresso.assertion.ViewAssertions.*; | |
| import static android.support.test.espresso.matcher.ViewMatchers.*; | |
| @LargeTest | |
| @RunWith(AndroidJUnit4.class) | |
| public class ToDoActivityEspressoRecordingTest { | |
| @Rule | |
| public ActivityTestRule<ToDoActivity> mActivityTestRule = new ActivityTestRule<>(ToDoActivity.class); | |
| @Test | |
| public void toDoActivityEspressoRecordingTest() { | |
| ViewInteraction appCompatButton = onView( | |
| allOf(withId(android.R.id.button1), withText("OK"), | |
| withParent(allOf(withId(R.id.buttonPanel), | |
| withParent(withId(R.id.parentPanel)))), | |
| isDisplayed())); | |
| appCompatButton.perform(click()); | |
| ViewInteraction floatingActionButton = onView( | |
| allOf(withId(R.id.fab), isDisplayed())); | |
| floatingActionButton.perform(click()); | |
| ViewInteraction appCompatEditText = onView( | |
| allOf(withId(R.id.input), isDisplayed())); | |
| appCompatEditText.perform(replaceText("Espresso")); | |
| ViewInteraction appCompatButton2 = onView( | |
| allOf(withId(android.R.id.button1), withText("OK"), | |
| withParent(allOf(withId(R.id.buttonPanel), | |
| withParent(withId(R.id.parentPanel)))), | |
| isDisplayed())); | |
| appCompatButton2.perform(click()); | |
| ViewInteraction textView = onView( | |
| allOf(withId(R.id.todo_text_view), withText("Espresso"), isDisplayed())); | |
| textView.check(matches(withText("Espresso"))); | |
| } | |
| } |
1つ、依存性で解決していないところがあるのでこのままでは動かないです。
試したリポジトリのブランチはこちらです。
- repository
- branch
初めのテンプレを楽にするためとか、ちょっとした動作を一時的に自動化したい時とかには使えるかなという印象です。assertionも設定可能。
レコード時のエミュレータ側ではない、録画側はこんな感じです。
