XCUIElements call XCTAssert instead of throwing exceptions

Originator:iFreeCarve
Number:rdar://23296820 Date Originated:10/28/2015
Status:Open Resolved:
Product:Developer Tools Product Version:Version 7.0 (7A220)
Classification: Reproducible:Always
 
Summary:
Rather than throw exceptions for things like ambiguous queries to XCUIElements, code in XCUIElement can cause tests to immediately fail.  Such high-level logic should not be left up to such a low-level component.

The correct behavior would be to throw an exception or Swift error, which would accomplish the existing functionality of failing the test case (assuming the exception was not caught).  As-is, the test environment is severely crippled.

Steps to Reproduce:
The following XCTest code should produce an error in just about any iOS app:


import XCTest

class TestEnvironmentSanity: XCTestCase {

    override func setUp() {
        super.setUp()
        XCUIApplication().launch()
    }
    
 
   func test_XCTestSanity() {
        let app = XCUIApplication()
        do {
            try app.windows[""].elementType
        } catch {
            NSLog("We will have to access the window a different way.")
        }
    }
}

Expected Results:
The message should be printed in the log

Actual Results:
Test fails with "UI Testing Failure - Multiple matches found:"

Version:
Xcode Version 7.0 (7A220)


Notes:


Configuration:

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!