0

我正在为 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,但从管理类的实践角度来看,我不想这样做。

截图:版本 1: 标题部分 版本 2: 在此处输入图像描述

4

1 回答 1

0

找到了使用多个条件的替代方法。我对使用多个条件的定位器策略进行了更多研究,发现您可以使用带有 className 和 id/resource-id 的 xpath 定位器。但是,这取决于 className 标记是否与 resource-id 的更改相同。目前,我的情况符合这些条件。

@AndroidFindBy(xpath="//android.widget.TextView[@resource-id='com.reddit.frontpage:id/search_view' or @resource-id='com.reddit.frontpage:id/toolbar_title']")
public MobileElement navTitle;
于 2019-10-15T06:49:23.300 回答