About https://github.com/appium/appium/issues/15138
I toyed compose layout with JetChat in https://github.com/android/compose-samples with Appium. Below XMLs are the result. When we add contentDescription in each element, Appium can access them. But I understand the contentDescription is for accessibility feature. We should not use it only for automation as possible.
I wondered resource-id and tag. But so far, probably it works only in semantic context in compose. So, we must find a way to inject compose elements via instrumentation. I assume UIA2 will not work fully. Espresso or a new driver may work. Hm…
Note:
With Espresso driver. The below espressoBuildConfig was needed to build.
{
toolsVersions: {
minSdk: 21,
targetSdk: 30,
kotlin: '1.4.31'
},
additionalAndroidTestDependencies: [
'androidx.core:core-ktx:1.5.0-beta03',
'androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha03'
]
}
<?xmlversion='1.0'encoding='UTF-8'standalone='yes'?>
<com.android.internal.policy.DecorViewindex="0"package="com.example.compose.jetchat"class="com.android.internal.policy.DecorView"checkable="false"checked="false"clickable="false"enabled="true"focusable="false"focused="false"scrollable="false"long-clickable="false"password="false"selected="false"visible="true"bounds="[0,0][1080,1920]"viewIndex="0">
<android.widget.LinearLayoutindex="0"package="com.example.compose.jetchat"class="android.widget.LinearLayout"checkable="false"checked="false"clickable="false"enabled="true"focusable="false"focused="false"scrollable="false"long-clickable="false"password="false"selected="false"visible="true"bounds="[0,0][1080,1920]"viewIndex="1">
<android.view.ViewStubindex="0"package="com.example.compose.jetchat"class="android.view.ViewStub"checkable="false"checked="false"clickable="false"enabled="true"focusable="false"focused="false"scrollable="false"long-clickable="false"password="false"selected="false"visible="false"bounds="[0,0][0,0]"resource-id="android:id/action_mode_bar_stub"viewIndex="2"/>
<android.widget.FrameLayoutindex="1"package="com.example.compose.jetchat"class="android.widget.FrameLayout"checkable="false"checked="false"clickable="false"enabled="true"focusable="false"focused="false"scrollable="false"long-clickable="false"password="false"selected="false"visible="true"bounds="[0,0][1080,1920]"viewIndex="3">
<androidx.appcompat.widget.FitWindowsLinearLayoutindex="0"package="com.example.compose.jetchat"class="androidx.appcompat.widget.FitWindowsLinearLayout"checkable="false"checked="false"clickable="false"enabled="true"focusable="false"focused="false"scrollable="false"long-clickable="false"password="false"selected="false"visible="true"bounds="[0,0][1080,1920]"resource-id="app:id/action_bar_root"viewIndex="4">
<androidx.appcompat.widget.ViewStubCompatindex="0"package="com.example.compose.jetchat"class="androidx.appcompat.widget.ViewStubCompat"checkable="false"checked="false"clickable="false"enabled="true"focusable="false"focused="false"scrollable="false"long-clickable="false"password="false"selected="false"visible="false"bounds="[0,0][0,0]"resource-id="app:id/action_mode_bar_stub"viewIndex="5"/>
<androidx.appcompat.widget.ContentFrameLayoutindex="1"package="com.example.compose.jetchat"class="androidx.appcompat.widget.ContentFrameLayout"checkable="false"checked="false"clickable="false"enabled="true"focusable="false"focused="false"scrollable="false"long-clickable="false"password="false"selected="false"visible="true"bounds="[0,0][1080,1920]"resource-id="android:id/content"viewIndex="6">
<androidx.compose.ui.platform.ComposeViewindex="0"package="com.example.compose.jetchat"class="androidx.compose.ui.platform.ComposeView"checkable="false"checked="false"clickable="false"enabled="true"focusable="false"focused="false"scrollable="false"long-clickable="false"password="false"selected="false"visible="true"bounds="[0,0][1080,1920]"viewIndex="7">
<androidx.compose.ui.platform.AndroidComposeViewindex="0"package="com.example.compose.jetchat"class="androidx.compose.ui.platform.AndroidComposeView"checkable="false"checked="false"clickable="false"enabled="true"focusable="true"focused="false"scrollable="false"long-clickable="false"password="false"selected="false"visible="true"bounds="[0,0][1080,1920]"viewIndex="8">
<androidx.compose.ui.platform.AndroidViewsHandlerindex="0"package="com.example.compose.jetchat"class="androidx.compose.ui.platform.AndroidViewsHandler"checkable="false"checked="false"clickable="false"enabled="true"focusable="false"focused="false"scrollable="false"long-clickable="false"password="false"selected="false"visible="true"bounds="[0,0][1080,1920]"viewIndex="9">
<androidx.compose.ui.viewinterop.ViewFactoryHolderindex="0"package="com.example.compose.jetchat"class="androidx.compose.ui.viewinterop.ViewFactoryHolder"checkable="false"checked="false"clickable="false"enabled="true"focusable="false"focused="false"scrollable="false"long-clickable="false"password="false"selected="false"visible="true"bounds="[0,0][1080,1920]"viewIndex="10">
<android.widget.FrameLayoutindex="0"package="com.example.compose.jetchat"class="android.widget.FrameLayout"checkable="false"checked="false"clickable="false"enabled="true"focusable="false"focused="false"scrollable="false"long-clickable="false"password="false"selected="false"visible="true"bounds="[0,0][1080,1920]"viewIndex="11">
<androidx.fragment.app.FragmentContainerViewindex="0"package="com.example.compose.jetchat"class="androidx.fragment.app.FragmentContainerView"checkable="false"checked="false"clickable="false"enabled="true"focusable="false"focused="false"scrollable="false"long-clickable="false"password="false"selected="false"visible="true"bounds="[0,0][1080,1920]"resource-id="app:id/nav_host_fragment"viewIndex="12">
<androidx.fragment.app.FragmentContainerViewindex="0"package="com.example.compose.jetchat"class="androidx.fragment.app.FragmentContainerView"checkable="false"checked="false"clickable="false"enabled="true"focusable="false"focused="false"scrollable="false"long-clickable="false"password="false"selected="false"visible="true"bounds="[0,0][1080,1920]"resource-id="app:id/nav_host_fragment"viewIndex="13">
<androidx.compose.ui.platform.ComposeViewindex="0"package="com.example.compose.jetchat"class="androidx.compose.ui.platform.ComposeView"checkable="false"checked="false"clickable="false"enabled="true"focusable="false"focused="false"scrollable="false"long-clickable="false"password="false"selected="false"visible="true"bounds="[0,0][1080,1920]"viewIndex="14">
<androidx.compose.ui.platform.AndroidComposeViewindex="0"package="com.example.compose.jetchat"class="androidx.compose.ui.platform.AndroidComposeView"checkable="false"checked="false"clickable="false"enabled="true"focusable="true"focused="false"scrollable="false"long-clickable="false"password="false"selected="false"visible="true"bounds="[0,0][1080,1920]"viewIndex="15"/>
</androidx.compose.ui.platform.ComposeView>
</androidx.fragment.app.FragmentContainerView>
</androidx.fragment.app.FragmentContainerView>
</android.widget.FrameLayout>
</androidx.compose.ui.viewinterop.ViewFactoryHolder>
</androidx.compose.ui.platform.AndroidViewsHandler>
</androidx.compose.ui.platform.AndroidComposeView>
</androidx.compose.ui.platform.ComposeView>
</androidx.appcompat.widget.ContentFrameLayout>
</androidx.appcompat.widget.FitWindowsLinearLayout>
</android.widget.FrameLayout>
</android.widget.LinearLayout>
</com.android.internal.policy.DecorView>
The below is UIA2 driver.
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>\r\n
<hierarchy index=\"0\" class=\"hierarchy\" rotation=\"0\" width=\"1080\" height=\"1794\">\r\n
<android.widget.FrameLayout index=\"0\" package=\"com.example.compose.jetchat\" class=\"android.widget.FrameLayout\" text=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" long-clickable=\"false\" password=\"false\" scrollable=\"false\" selected=\"false\" bounds=\"[0,0][1080,1794]\" displayed=\"true\">\r\n
<android.widget.LinearLayout index=\"0\" package=\"com.example.compose.jetchat\" class=\"android.widget.LinearLayout\" text=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" long-clickable=\"false\" password=\"false\" scrollable=\"false\" selected=\"false\" bounds=\"[0,0][1080,1794]\" displayed=\"true\">\r\n
<android.widget.FrameLayout index=\"0\" package=\"com.example.compose.jetchat\" class=\"android.widget.FrameLayout\" text=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" long-clickable=\"false\" password=\"false\" scrollable=\"false\" selected=\"false\" bounds=\"[0,0][1080,1794]\" displayed=\"true\">\r\n
<android.widget.LinearLayout index=\"0\" package=\"com.example.compose.jetchat\" class=\"android.widget.LinearLayout\" text=\"\" resource-id=\"com.example.compose.jetchat:id/action_bar_root\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" long-clickable=\"false\" password=\"false\" scrollable=\"false\" selected=\"false\" bounds=\"[0,0][1080,1794]\" displayed=\"true\">\r\n
<android.widget.FrameLayout index=\"0\" package=\"com.example.compose.jetchat\" class=\"android.widget.FrameLayout\" text=\"\" resource-id=\"android:id/content\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" long-clickable=\"false\" password=\"false\" scrollable=\"false\" selected=\"false\" bounds=\"[0,0][1080,1794]\" displayed=\"true\">\r\n
<android.view.ViewGroup index=\"0\" package=\"com.example.compose.jetchat\" class=\"android.view.ViewGroup\" text=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" long-clickable=\"false\" password=\"false\" scrollable=\"false\" selected=\"false\" bounds=\"[0,0][1080,1794]\" displayed=\"true\">\r\n
<android.view.View index=\"0\" package=\"com.example.compose.jetchat\" class=\"android.view.View\" text=\"\" checkable=\"false\" checked=\"false\" clickable=\"false\" enabled=\"true\" focusable=\"false\" focused=\"false\" long-clickable=\"false\" password=\"false\" scrollable=\"false\" selected=\"false\" bounds=\"[0,0][1080,1794]\" displayed=\"true\" />\r\n
</android.view.ViewGroup>\r\n
</android.widget.FrameLayout>\r\n
</android.widget.LinearLayout>\r\n
</android.widget.FrameLayout>\r\n
</android.widget.LinearLayout>\r\n
</android.widget.FrameLayout>\r\n
</hierarchy>