在做手机UI自动化测试时,需求是一次浏览多个app的一级、二级目录,但是app不固定
针对UI层面的操作是否有方法可以做到
直接通过findElement() 或 findElements()来方法查找该元素。和正常的id、name、xpath定位元素类似,一直往下找就行。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#17d9ff"
android:orientation="vertical">
<--上下部分代码-->
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="10dp">
<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:id="@+id/sideMenuButton"
android:layout_marginStart="15dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="30dp"
android:background="@drawable/sidemenu"/>
<TextView
android:id="@+id/appTitle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"
android:text="@string/my_top_news"
android:textSize="30sp"
android:textColor="#ffffff"
tools:ignore="RtlHardcoded"
android:typeface="serif"/>
</LinearLayout>
<TextView
android:id="@+id/appTitle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"
android:text="@string/my_top_news"
android:textSize="30sp"
android:textColor="#ffffff"
tools:ignore="RtlHardcoded"
android:typeface="serif"/>
</LinearLayout>
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
...
implementation 'androidx.recyclerview:recyclerview:1.1.0'
...
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recyclerViewForTitle"/>