【发布时间】:2016-08-24 18:53:05
【问题描述】:
我正在使用 XCTest 框架运行 UI 测试。
除了在我的一些测试中 XCTest 必须尝试很多次 次才能成功找到它正在寻找的 UIElement 之外,一切都运行良好。它似乎特别发生在从表格视图单元格中的按钮生成的菜单中包含的菜单项中。
这是我的一个具有这种行为的测试的代码。
func testMoreMenuCopyDirectLinkAction()
{
//Arrange
CloudPasteboardController.clearClipboard()
XCTAssertTrue(CloudPasteboardController.getPasteboardItems().count == 0)
let app = XCUIApplication()
let firstCell = app.tables.cells.elementBoundByIndex(0)
let moreMenu = firstCell.menus.elementBoundByIndex(0)
let copyDirectLink = moreMenu.menuItems.elementMatchingType(.MenuItem, identifier: "Copy Direct Link")
//Act
openApp()
findAndClickCellButtonWithName("More Button")
waitForUIElementToAppear(copyDirectLink)
copyDirectLink.click()
//Assert
XCTAssertTrue(CloudPasteboardController.getPasteboardItems().count == 1)
}
这是部分输出的屏幕截图。可以看出,它多次尝试在某种循环中查找元素。总而言之,在这个测试中,它在第 11 个循环中成功了。
我尝试在不调用“waitForUIElementToAppear(...)”的情况下重新编写代码,并且尝试通过说“copyDirectLink = app.menuItems[“Copy Direct Link”]”来简化调用但它不会改变任何东西。
【问题讨论】:
-
它在我看来像是循环播放。也许它正在等待它出现或其他什么。
标签: xcode macos xcode-ui-testing