1. 根据ID查找,不区分layout
示例:
GetButtonById(“login”).click()
缺点:
a. 每次写脚本,都要借助Hierarchy Viewer,来获取“login”。
b. ”login”这个字符串不能写错,所以每次都要去确认一下。
优点:
a. 简洁
2. 按layout中xml文件树型结构
示例:
Layout(Main2.class).relativeLayout_id1().relativeLayout_id2().relativeLayout_id3().login().click
Layout(Main2.class).relativeLayout_id1().relativeLayout_id2().search_box().setText(“123”)
Layout(Main2.class).relativeLayout_id4().hot_store.click
缺点:
a. 借助Hierarchy Viewer,来熟悉UI。
b. 层级可能很多6个,代码长;
c. 一旦路径走错了,下面就不知道是啥了;
d. 受开发调整结构的限制。
优点:
a. 每个relativeLayout下的控件不会很多;
b. 代码智能感应,不会写错。
3. 按类型平铺
示例:
Layout(Main2.class).Button().login().click()
Layout(Main2.class).TextView().hot_store().click()
Layout(Main2.class).EditText().search_box().setText(“123”)
缺点:
a. 借助Hierarchy Viewer,来熟悉UI。
b. 看着像Button实际上是个TextView,这时候测试需要了解一些特殊TextView (像Button);
c. 分类下面的view平铺,可能很多20个,不好找。
优点:
a. 代码智能感应,不会写错;
b. 路径短;
c. 可以增加过滤黑名单。
d. 灵活应对开发调整结构。
4. 使用Automan的PageModel思想
示例:
Layout(Main2.class).LoginArea().login().click()
Layout(Main2.class).StoreSubmodel().hot_store().click()
Layout(Main2.class).SearchSubmodel().SearchArea().search_box().setText(“123”)
缺点:
a. 编辑PageModel需要人肉参与,起中文名字方便做为eclipse提示。
优点:
a. 代码智能感应,不会写错;
b. 可以通过导入layout xml的方式,通过人工参与删减,生成PageModel;
c. 在建PageModel时,需要借助Hierarchy Viewer对UI有一定的了解。
d. 灵活应对开发调整结构。