Skip to content

Instantly share code, notes, and snippets.

@joemasilotti
Created September 17, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joemasilotti/15ec2ed653d6dfe4c2b5 to your computer and use it in GitHub Desktop.
Save joemasilotti/15ec2ed653d6dfe4c2b5 to your computer and use it in GitHub Desktop.
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