1

假设我setup()在运行这样的测试用例之前在方法中使用了代码片段:

if EarlGrey().selectElementWithMatcher(grey_accessibilityID("TabBar-Navigation-Search")).assertWithMatcher(grey_sufficientlyVisible()) != nil {
    TabBarNavigation().navigateToSearch()
} else {
    assentViewModelsSwifts.signInCheck()
    assentViewModelsSwifts.enterLoginCredentials("username", password: "password")
    let visibleSignInButtonMatcher = grey_allOfMatchers(grey_accessibilityID("Login-Button-SignIn"), grey_sufficientlyVisible())
    EarlGrey().selectElementWithMatcher(visibleSignInButtonMatcher).performAction(grey_tap())
    TabBarNavigation().navigateToSearch()
    Log.info("Landed on Search Page")
}

我遇到了一个错误。发现断言'assertWithMatcher: matcherForSufficientlyVisible(>=0.750000)' was not performed because no UI element matching (respondsToSelector(accessibilityIdentifier) && accessibilityID("TabBar-Navigation-Activity"))

其实我想检查一个元素的存在。如果元素存在,请执行某个步骤或执行其他操作。但是,尽管该元素不存在于该特定屏幕上,但循环内的代码并未执行。任何建议将不胜感激。

4

1 回答 1

2

尝试以下方法进行零检查:

- (instancetype)assertWithMatcher:(id<GREYMatcher>)matcher error:(__strong NSError **)errorOrNil

尝试下面的代码来检查零:

let errorOrNil
EarlGrey().selectElementWithMatcher(grey_accessibilityID("TabBar-Navigation-Search")).assertWithMatcher(grey_sufficientlyVisible(), error:&errorOrNil)
 if errorOrNil != nil {
                TabBarNavigation().navigateToSearch()
            } else {
            assentViewModelsSwifts.signInCheck()
            assentViewModelsSwifts.enterLoginCredentials("username", password: "password")
            let visibleSignInButtonMatcher = grey_allOfMatchers(grey_accessibilityID("Login-Button-SignIn"), grey_sufficientlyVisible())
            EarlGrey().selectElementWithMatcher(visibleSignInButtonMatcher).performAction(grey_tap())
            TabBarNavigation().navigateToSearch()
            Log.info("Landed on Search Page")
            }
于 2016-11-03T07:22:54.550 回答