我正在为 Main Activity 部分中的 Header 类/小部件创建 POM 类(Reddit 应用程序就是示例。请参见下面的屏幕截图。)通过 Inspector,我看到 header 将有可用的搜索框,但如果我要移动到主活动的另一个部分/选项卡搜索框变得不可用。id/resource-id 也以 :id/search_view 或 :id/toolbar_title 结尾。我对这个问题的最初反应是否定的,但想在退出之前联系任何遇到过这个特定主题的人。
我想看看我是否能够在调用 ResourceIdMatches 方法时使用 UiSelector 中的正则表达式条件将任一 Id 存储到我的 Header 类的单个 MobileElement 中。
这是我目前在 My Header 课程中的内容。(重点是 navTitle MobileElement):
@AndroidFindBy(id="com.reddit.frontpage:id/toolbar")
public MobileElement headerSection;
@AndroidFindBy(id = "com.reddit.frontpage:id/nav_icon")
public MobileElement userIcon;
//Needs work
@AndroidFindBy(uiAutomator = "new UiSelector()"
+ ".resourceIdMatches(\".*id/^([search_view|toolbar_title])+$\")")
public MobileElement navTitle;
public RedditMainActivityHeader(AppiumDriver<MobileElement> driver) {
super(driver);
}
在研究 Regex 主题时,我在使用 word bounderies(\b) 之前编辑了 Regex 条件,不使用 [],使用 * 而不是 +。解决此问题的替代方法是创建第二个 Header 类,并让 navTitle 通过 :id/search_view 或 :id/toolbar_title 找到 id,但从管理类的实践角度来看,我不想这样做。