私は私の最初のアイデア以下しまった:私はスクリーンショットを取る方法を実装しましたthis回答に基づいて
- を。
、私はユーザーとの対話を必要とせずに電子メールを送信できるAPIのJavaMailを実装しましたベース
this答えに
- 。
1と2の組み合わせは、私のutilのライブラリスクリーンショットを取り、希望する状態に入るkotlin-components
最後に私が実装されてきたUIテストで見つけることができます - 外部SDカード上に保存します - そして、最後のステップで、それは私が好きに送信する電子メールの添付ファイルとしてSSを追加します。
@RunWith(AndroidJUnit4::class)
@LargeTest
class UITestSearchSamples {
companion object {
private val SCREENSHOTS_DIRECTORY = "search-interface"
private val TIME_OUT = 3000L
private val WAITING_TIME = 1000L
@get:ClassRule
var disableAnimationsRule = DisableAnimationsRule()
}
private var finished = false
@get:Rule
var mActivityRule = ActivityTestRule(ActivityHomepage::class.java)
private var mMonitor: Instrumentation.ActivityMonitor? = null
@Before
fun setup() {
setWaitingPolice()
mMonitor = getInstrumentation().addMonitor(ActivitySearch::class.java.name, null, false)
}
private fun performWaitingTime() {
val idlingResource = ElapsedTimeIdlingResource(WAITING_TIME)
Espresso.registerIdlingResources(idlingResource)
}
private fun setWaitingPolice() {
IdlingPolicies.setMasterPolicyTimeout(TIME_OUT, TimeUnit.MILLISECONDS);
IdlingPolicies.setIdlingResourceTimeout(TIME_OUT, TimeUnit.MILLISECONDS);
}
@After
fun tearDown() {
closeSoftKeyboard()
performWaitingTime()
val activitySearch = getInstrumentation().waitForMonitorWithTimeout(mMonitor, TIME_OUT) as AppCompatActivity
activitySearch.takeScreenShot(location = DirectoryPath.EXTERNAL, path = SCREENSHOTS_DIRECTORY, openScreenShot = false, showToast = false)
activitySearch.finish()
if (finished) {
sendNotificationEmail(activitySearch)
}
}
private fun sendNotificationEmail(activitySearch: AppCompatActivity) {
try {
val sender = Sender("sender_email", "sender_password")
val email = Email(
"Hello world: SMTP Server from Android with Attachments",
"This is a sample e-mail sent via SMTP server from Android without the need of user interaction.",
mutableListOf("recipient_01", "recipient_02"),
File("${DirectoryPath.EXTERNAL.getValue(activitySearch)}/search-interface").listFiles()
)
activitySearch.sendEmail(sender, email)
} catch (e: Exception) {
Log.e("SENDER E-MAIL SLAVE", e.message, e)
}
}
@Test
fun launchSample01() {
onView(withId(R.id.btn_sample_01)).perform(click())
onView(withId(R.id.input)).perform(typeText("Diana"))
}
@Test
fun launchSample02() {
onView(withId(R.id.btn_sample_02)).perform(click())
onView(withId(R.id.input)).perform(typeText("Clark"))
}
@Test
fun launchSample03() {
onView(withId(R.id.btn_sample_03)).perform(click())
onView(withId(R.id.input)).perform(typeText("Diana"))
onView(withId(R.id.wrapper)).perform(click())
performWaitingTime()
onView(withId(R.id.input)).perform(typeText("a"))
finished = true
}
}