手机UI自动化测试浏览一二级目录

在做手机UI自动化测试时,需求是一次浏览多个app的一级、二级目录,但是app不固定
针对UI层面的操作是否有方法可以做到

直接通过findElement() 或 findElements()来方法查找该元素。和正常的id、name、xpath定位元素类似,一直往下找就行。

  • 这有个类似的问题, 你可以参考下: https://ask.csdn.net/questions/7684204
  • 我还给你找了一篇非常好的博客,你可以看看是否有帮助,链接:移动设备共享平台、低成本赋能团队实现UI自动化测试及UI自动化用例管理
  • 除此之外, 这篇博客: 【移动设备交互应用】我的头条——仿安卓新闻APP制作中的 标题栏UI布局代码构建 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
    • 创建drawable–xxhdpi文件夹,用于存放图片资源,利用自动匹配机制去选择对应的布局和图片资源(本项目矢量图来自阿里巴巴矢量图标库https://www.iconfont.cn/)
    • 在layout文件夹中,创建title.xml,编写布局代码
    • 标题栏为线性布局,背景颜色设置为浅蓝色,完成整体设计
    <?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>
    
    • 下半部分
    • 使用RecyclerView,由于属于新增控件,Google将RecyclerView定义在AndroidX中,需要在项目的build.gradle中添加RecyclerView依赖,保证在所有Android系统版本上都可以使用RecyclerView控件。
    • 打开app/build.gradle文件,在dependencies闭包中添加以下内容
    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'
    }
    
    • 打开title.xml,编写布局代码
    <androidx.recyclerview.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/recyclerViewForTitle"/>
    
    • 最终效果图
      在这里插入图片描述
  • 您还可以看一下 刘国柱老师的游戏UI界面框架设计系列视频课程课程中的 无框架项目需要处理的问题小节, 巩固相关知识点