我正在开发一个Android库模块,它在UI方面可高度自定义。如果有一个脚本或某种自动化过程可以拍摄正在运行的应用程序的屏幕截图,将它们连接起来并通过电子邮件发送,那将是非常好的。所以我可以快速检查是否有一些更改与某些UI组件混淆和/或者拥有更新库READ-ME的最新资产。
有关如何执行此操作的任何想法?
我目前的想法
到目前为止,我一直在考虑添加代码以编程方式获取SS,将它们存储在临时文件夹中,并且在收集完所有图像后,通过一些REST API将它们发送到服务器。我想知道是否有更好的方法来做到这一点。
答案 0 :(得分:0)
我最终遵循了我最初的想法:
可以在我的util库kotlin-components上找到1和2的组合
最后,我实现了进入所需状态的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
}
}