编程语言
首页 > 编程语言> > android-由于Firebase测试实验室中的Chrome自动更新,经过工具测试的应用程序崩溃

android-由于Firebase测试实验室中的Chrome自动更新,经过工具测试的应用程序崩溃

作者:互联网

在Google的Firebase测试实验室上运行仪器测试时,由于Google Chrome在后台更新,因此被测试的应用程序崩溃了.经过测试的应用程序确实具有一些WebView,但是在测试运行期间不会显示它们.

录像独特地显示了Play商店正在下载和安装的应用(动画下载通知).

相关日志:

03-19 22:52:52.450: I/ActivityManager(1154): Force stopping com.android.chrome appid=10086 user=-1: installPackageLI
03-19 22:52:52.450: I/ActivityManager(1154): Killing 31128:com.google.android.googlequicksearchbox:search/u0a54 (adj 500): stop com.android.chrome
03-19 22:52:52.454: I/ActivityManager(1154): Killing 15064:com.MYAPP/u0a159 (adj 0): stop com.android.chrome

在其上方,我可以清楚地看到正在下载,验证等的更新.

我们还尝试了使用–no-auto-google-login标志运行gcloud,但未成功:仍在下载和安装应用程序.

还有其他人遇到过这个问题或有什么建议吗?

解决方法:

为了更好地控制我们的仪器测试,我们最终编写了ChromeDisabler,它将运行每个仪器测试会话,进入手机的Chrome设置,然后卸载并禁用Chrome,从而阻止了它的自动更新.

理想情况下,Google应该禁用Firebase测试实验室图像的自动更新.

用法:

class CustomTestRunner : AndroidJUnitRunner() {

    override fun onStart() {
        ChromeDisabler.disable()
        super.onStart()
    }
}

ChromeDisabler:

object ChromeDisabler {
    private const val CHROME_APP_PACKAGE_NAME = "com.android.chrome"
    private const val APPLICATION_DETAILS_SETTINGS_APP_PACKAGE_NAME = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
    private const val WAIT_TIMEOUT_MILLIS = 5000L

    private val device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
    private val disableButton = device.findObject(UiSelector().textStartsWith("disable"))
    private val uninstallButton = device.findObject(UiSelector().textStartsWith("uninstall"))

    fun disable() {
        device.pressHome()

        launchSettingsActivityForChrome()

        device.wait(Until.hasObject(By.pkg(APPLICATION_DETAILS_SETTINGS_APP_PACKAGE_NAME).depth(0)), WAIT_TIMEOUT_MILLIS)

        when {
            disableButton.exists() -> {
                Timber.e("Stock $CHROME_APP_PACKAGE_NAME found")
                disableApp(device)
            }

            uninstallButton.exists() -> {
                Timber.e("Non-stock $CHROME_APP_PACKAGE_NAME found")
                uninstallApp(device)
                disableApp(device)
            }

            device.findObject(UiSelector().textStartsWith("enable")).exists() -> {
                Timber.e("$CHROME_APP_PACKAGE_NAME is already disabled")
            }
        }
    }

    private fun launchSettingsActivityForChrome() {
        val intent = Intent().apply {
            action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS
            data = Uri.fromParts("package", CHROME_APP_PACKAGE_NAME, null)
            addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        }

        InstrumentationRegistry.getInstrumentation().targetContext.startActivity(intent)
    }

    private fun disableApp(device: UiDevice) {
        Timber.e("Attempting to disable $CHROME_APP_PACKAGE_NAME")

        try {
            disableButton.click()
            device.findObject(UiSelector().textStartsWith("disable app")).click()
            Timber.e("Successfully disabled $CHROME_APP_PACKAGE_NAME")
        } catch (exception: Exception) {
            Timber.e("Failed to disable $CHROME_APP_PACKAGE_NAME, cause: $exception")
        }
    }

    private fun uninstallApp(device: UiDevice) {
        Timber.e("Attempting to uninstall $CHROME_APP_PACKAGE_NAME")

        try {
            uninstallButton.click()
            device.findObject(UiSelector().textStartsWith("ok")).click()
            Timber.e("Successfully uninstalled $CHROME_APP_PACKAGE_NAME")
        } catch (exception: Exception) {
            Timber.e("Failed to uninstall $CHROME_APP_PACKAGE_NAME, cause: $exception")
        }
    }
}

标签:firebase,automated-tests,firebase-test-lab,android
来源: https://codeday.me/bug/20191108/2006030.html