Billy Boyo Billy Boyo - 1 month ago 26
Swift Question

Is there an oposite to 'exists' in XCUITest

I am writing my tests on XCUITest and checking to see if a deleted item no longer exists... I can't find anything that I can use to XCTAssert that the element does not exist.

Does anyone know if there is an BOOL value what you can use to detect if an element is not visible?

Or if there is any work arounds?

Thanks in advance,

Answer

Other than XCTAssert there are also other helpful assert statements.

To test the boolean values of a property you can use XCTAssertFalse / XCTAssertTrue

So lets say a view is hidden/displayed on doing something. Then you could write a test case like:

func testViewIsNotHidden() {
    let view = UIView()
    view.hidden = true

    // Do something which unhides the view

    XCTAssertFalse(view.hidden)
}

func testViewIsHidden() {
    let view = UIView()
    view.hidden = false

    // Do something which hides the view

    XCTAssertTrue(view.hidden)
}

You can check out other XCTAsserts over here.