java - 安卓测试 : What do to when nothing has an id?

标签 java android robotium android-testing

我正在尝试为我拥有的应用程序编写一些自动化脚本。我已经完成了 Robotium 网站上的教程,并对如何实现自动化有了基本的了解。但是,据我所知,我正在测试的应用程序是通过使用 android 层次结构查看器,我看到所有 View 都没有明确定义的 ID。 Sample Hierarchy

正如您从屏幕截图中看到的那样,在嵌套 View 上存在 View 。它们的 ID 读起来像 0x17e0 或 0x17de。我如何在 robotium 脚本中引用这些内容?最终结果是我试图让它甚至在其中一个文本切换器 View 上触发点击。到目前为止,如果我给它一个像素点去,或者如果我给它按钮中出现的文本,我只能让它工作(但文本是动态的并且会导致糟糕的测试)。

我是否必须使用 getCurrentViews() 来过滤文本切换器?或者我是否必须想出一种方法来遍历从 FrameLayout>RelativeLayout>FrameLayout>LinearLayout>TextSwitcher 开始的整个树?

如果我必须遍历整棵树,我该如何逐个查看?

最佳答案

虽然我无法让 ViewGroup() 和 getChildAt() 方法为我工作,但我最终做了一些不同的事情:

// Grabbing all the LinearLayout views found under view with with id of 'content' 
ArrayList<LinearLayout> linearLayouts = solo.getCurrentViews(LinearLayout.class, solo.getView(R.id.content));

// The 4th item in the linearLayouts list is the one I need
View pickerList = linearLayouts.get(3);

// Grabbing the buttons in the pickerList
ArrayList<TextSwitcher> buttons = solo.getCurrentViews(TextSwitcher.class,pickerList);

// Now I can click on the buttons
solo.clickOnView(buttons.get(0));

我会说这很慢。第一次按钮点击触发大约需要 10 秒。但是一旦它飞起来。

关于java - 安卓测试 : What do to when nothing has an id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15618031/

相关文章:

java - Lotus 的 Notes.jar 的 javadoc 在哪里?

java - 检查是否违反特定约束

java - 我们可以更改 java 安装文件夹的路径吗?怎么办?

android - 使用 robotium 测试 Activity 流程

android - 如何编写使用内置相机拍照的 Solo/Robotium 测试用例?

android - 如何显示 Android Robotium 测试的进度对话框 :

java - 异步检索 SQL 查询执行结果。

Android-NDK构建系统(构建hello-gl2)

javascript - Google Signin 无法点击并且仅在移动设备上卡住登录

java - 4.4.4 上的 android.view.InflateException 而 5.0 则没问题