Ios 使用触摸手势进行测试
我想测试一个应用程序,用XCTest在屏幕上记录用户绘制手势。我想知道使用Xcode7中引入的新UI测试是否有可能实现这一点。我浏览了整个视频解释,大部分讨论仅限于在按钮上生成点击事件 我想到了两种可能解决你问题的方法,这取决于你的问题有多复杂以及你的偏好Ios 使用触摸手势进行测试,ios,xcode,xctest,touches,Ios,Xcode,Xctest,Touches,我想测试一个应用程序,用XCTest在屏幕上记录用户绘制手势。我想知道使用Xcode7中引入的新UI测试是否有可能实现这一点。我浏览了整个视频解释,大部分讨论仅限于在按钮上生成点击事件 我想到了两种可能解决你问题的方法,这取决于你的问题有多复杂以及你的偏好 在UITests中,您可以使用一些手势,如.swipleft()或pinchWithScale(2.0,速度:1),或.tap(),或按ForDuration(2.0)。虽然通常情况下,如果您尝试记录测试,它可能无法捕获滑动或挤压,因此您很可
func testThatAfterLongPressMyNewViewIsPresented() {
let app = XCUIApplication()
let window = app.childrenMatchingType(.Window).elementBoundByIndex(0)
let myOldView = window.childrenMatchingType(.Other).elementBoundByIndex(1).childrenMatchingType(.Other).element
let myNewView = window.childrenMatchingType(.Other).elementBoundByIndex(2).childrenMatchingType(.Other).elementBoundByIndex(1)
XCTAssertFalse(myNewView.exists)
myOldView.pressForDuration(2.0)
XCTAssertTrue(myNewView.exists)
}
(B) 如果在滑动标签后发生更改,则可以查找标签值并与旧值进行比较(顺便说一句,这里我假设app
和myOldView
是类变量,并在设置方法中实例化)
希望这有帮助
达纳
func testThatAfterSwipeLabelChanges() {
let myTextLabel = app.textFields.matchingIdentifier("textLabelId")
let currentlyDisplayedText = myTextLabel.label
myOldView.swipeLeft()
XCTAssertNotEqual(currentlyDisplayedText, myTextLabel.label)
}