Jos*_*osh 5 xcode ios swift xcode-ui-testing
我已经构建了一个带有3个选项卡的简单标签栏.
我想运行UI测试以确保如果用户单击选项卡栏项,则显示正确的视图控制器.我该怎么做呢?下面是我要开始的代码,只是不知道如何编写我的断言.
func testTabBarMyProfileButton() {
let tabBarsQuery = XCUIApplication().tabBars
tabBarsQuery.buttons["My Profile"].tap()
}
func testTabBarGraphsButton() {
let tabBarsQuery = XCUIApplication().tabBars
tabBarsQuery.buttons["Graphs"].tap()
}
func testTabBarAboutButton() {
let tabBarsQuery = XCUIApplication().tabBars
tabBarsQuery.buttons["About"].tap()
}
Run Code Online (Sandbox Code Playgroud)
您可以通过其位置访问标签栏按钮:
app.tabBars.buttons.element(boundBy: 2).tap()
Run Code Online (Sandbox Code Playgroud)
如果在每个选项卡栏上显示的每个视图控制器中都有不同的控件,则可以断言它们是否存在(预期)。例如,如果第一个标签栏有名为“名字”的 UILabel,您可以通过编写来断言它是否存在
Let theLabel = app.staticTexts["myValue"]
XCTAssert(theLabel.exists).to(beTrue)
Run Code Online (Sandbox Code Playgroud)
在其他屏幕上为不同的控件做同样的事情。
归档时间: |
|
查看次数: |
4196 次 |
最近记录: |