如何验证单元格在我的 UI 测试中是否可见
How can I verify a cell is visible in my UI Test
我试图在 UITest 中断言双击主页图标会将我的 table 视图滚动回顶部。
我假设这个模式是加载视图,滚动,断言它不能出现,点击主页并断言现在可以。
我有这样的东西
let username = "...."
let password = "...."
app.launch()
let loginPage = app.otherElements["login page"]
loginPage.waitForExistence()
let usernameInputField = app/*@START_MENU_TOKEN@*/.webViews.textFields["Email address"]/*[[".otherElements[\"bfx_login\"].webViews",".otherElements[\"Log in to OneHub | Recognition\"].textFields[\"Email address\"]",".textFields[\"Email address\"]",".webViews"],[[[-1,3,1],[-1,0,1]],[[-1,2],[-1,1]]],[0,0]]@END_MENU_TOKEN@*/
usernameInputField.tap()
usernameInputField.typeText(username)
let passwordInputField = app/*@START_MENU_TOKEN@*/.webViews.secureTextFields["Password"]/*[[".otherElements[\"bfx_login\"].webViews",".otherElements[\"Log in to OneHub | Recognition\"].secureTextFields[\"Password\"]",".secureTextFields[\"Password\"]",".webViews"],[[[-1,3,1],[-1,0,1]],[[-1,2],[-1,1]]],[0,0]]@END_MENU_TOKEN@*/
passwordInputField.tap()
passwordInputField.typeText(password)
loginPage.buttons["Log In"].tap()
let tabBarController = app.tabBars["home_tabBarController"]
tabBarController.waitForExistence()
let activityFeed = app.tables["Activity Feed"]
activityFeed.waitForExistence()
app.swipeUp()
XCTAssertFalse(activityFeed.cells.element(boundBy: 0).isHittable)
let homeButton = tabBarController.children(matching: .button).element(boundBy: 0)
homeButton.waitForExistence()
homeButton.doubleTap()
XCTAssertTrue(activityFeed.cells.element(boundBy: 0).isHittable)
除了能够对单元格进行断言之外,一切正常。我不相信
XCTAssertFalse(activityFeed.cells.element(boundBy: 0).isHittable)
和
XCTAssertTrue(activityFeed.cells.element(boundBy: 0).isHittable)
正在按照我的预期工作。
如何断言 table 视图中的单元格可见?
就检查某物是否可见而言,you want to use isHittable in conjunction with exists. See also 。
像这样:
element.exists && element.isHittable
你说过 isHittable 对你不起作用,你能解释一下它不起作用的原因吗?
我试图在 UITest 中断言双击主页图标会将我的 table 视图滚动回顶部。
我假设这个模式是加载视图,滚动,断言它不能出现,点击主页并断言现在可以。
我有这样的东西
let username = "...."
let password = "...."
app.launch()
let loginPage = app.otherElements["login page"]
loginPage.waitForExistence()
let usernameInputField = app/*@START_MENU_TOKEN@*/.webViews.textFields["Email address"]/*[[".otherElements[\"bfx_login\"].webViews",".otherElements[\"Log in to OneHub | Recognition\"].textFields[\"Email address\"]",".textFields[\"Email address\"]",".webViews"],[[[-1,3,1],[-1,0,1]],[[-1,2],[-1,1]]],[0,0]]@END_MENU_TOKEN@*/
usernameInputField.tap()
usernameInputField.typeText(username)
let passwordInputField = app/*@START_MENU_TOKEN@*/.webViews.secureTextFields["Password"]/*[[".otherElements[\"bfx_login\"].webViews",".otherElements[\"Log in to OneHub | Recognition\"].secureTextFields[\"Password\"]",".secureTextFields[\"Password\"]",".webViews"],[[[-1,3,1],[-1,0,1]],[[-1,2],[-1,1]]],[0,0]]@END_MENU_TOKEN@*/
passwordInputField.tap()
passwordInputField.typeText(password)
loginPage.buttons["Log In"].tap()
let tabBarController = app.tabBars["home_tabBarController"]
tabBarController.waitForExistence()
let activityFeed = app.tables["Activity Feed"]
activityFeed.waitForExistence()
app.swipeUp()
XCTAssertFalse(activityFeed.cells.element(boundBy: 0).isHittable)
let homeButton = tabBarController.children(matching: .button).element(boundBy: 0)
homeButton.waitForExistence()
homeButton.doubleTap()
XCTAssertTrue(activityFeed.cells.element(boundBy: 0).isHittable)
除了能够对单元格进行断言之外,一切正常。我不相信
XCTAssertFalse(activityFeed.cells.element(boundBy: 0).isHittable)
和
XCTAssertTrue(activityFeed.cells.element(boundBy: 0).isHittable)
正在按照我的预期工作。
如何断言 table 视图中的单元格可见?
就检查某物是否可见而言,you want to use isHittable in conjunction with exists. See also
element.exists && element.isHittable
你说过 isHittable 对你不起作用,你能解释一下它不起作用的原因吗?