Skip to content

Instantly share code, notes, and snippets.

@joemasilotti
Created September 17, 2015 14:12
Embed
What would you like to do?
How to assert if a view is off screen
import XCTest
class UITests: XCTestCase {
let app = XCUIApplication()
override func setUp() {
super.setUp()
continueAfterFailure = false
app.launch()
}
func testElementIsOnScreen() {
let windowFrame = app.windows.elementBoundByIndex(0).frame
let onScreenElementFrame = app.buttons["On"].frame
let offScreenElementFrame = app.buttons["Off"].frame
XCTAssert(CGRectContainsRect(windowFrame, onScreenElementFrame))
XCTAssertFalse(CGRectContainsRect(windowFrame, offScreenElementFrame))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment