【问题标题】:Automation testing framework for Jetpack composeJetpack compose 自动化测试框架
【发布时间】:2023-02-11 15:17:28
【问题描述】:

我们成功地重写了 Jetpack Compose 中的几个功能。我们遇到了一个障碍,我们的 QA 说他们编写的现有自动化脚本不再适用于 Compose UI 屏幕。

自动化脚本的背景: QA 使用 Appium 脚本,该脚本使用 UIAutomator2 来自动化元素。为了识别定位器(ID)——使用了 appium 检查器。 我们在 Compose UI 中没有 ID。 我们尝试添加 testTag 但在 appium 检查器中没有看到它。

请分享您必须为自动化脚本做什么样的框架更改以支持 Compose UI。

谢谢

【问题讨论】:

    标签: android-jetpack-compose ui-automation appium-android


    【解决方案1】:

    不幸的是,Appium UIAutomator2 还不支持属性testTag

    在 Apppium 的 repository 上已经创建了一个请求此属性的问题。

    【讨论】:

      【解决方案2】:

      伙计们,我只是设法通过在 Android Studio 中添加属性contentDescription = "UseThisInstead" 来访问 Compose 元素 稍后我可以通过 xpath 使用 Appium/ UIAutomator2 访问元素

      driver.findElement(By.xpath("//*[@content-desc='UseThisInstead']")).isDisplayed();
      

      试试那个

      【讨论】:

        【解决方案3】:

        更新

        根据compose official docs 和与 UiAutomator 的互操作性(自 Compose 版本 1.3.3 起):

        可以为可组合项层次结构中的特定可组合项子树启用 testTagAsResourceId,以确保可以从 UiAutomator 访问所有带有 Modifier.testTag 的嵌套可组合项。

        在撰写中:

        Scaffold(
            // Enables for all composables in the hierarchy.
            modifier = Modifier.semantics {
                testTagsAsResourceId = true
            }
        ){
            // Modifier.testTag is accessible from UiAutomator for composables nested here.
            LazyColumn(
                modifier = Modifier.testTag("myLazyColumn")
            ){
                // content
            }
        }
        

        在测试中:

        val device = UiDevice.getInstance(getInstrumentation())
        
        val lazyColumn: UiObject2 = device.findObject(By.res("myLazyColumn"))
        // some interaction with the lazyColumn
        

        【讨论】:

          猜你喜欢
          • 2012-02-25
          • 1970-01-01
          • 2022-10-02
          • 2016-07-09
          • 1970-01-01
          • 1970-01-01
          • 2010-09-12
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多