google/EarlGrey

NSInvalidArgumentException unrecognized selector exception EarlGrey2

alimyuz opened this issue · 0 comments

I followed the guide on white-box setup with CocoaPods but I get an exception when I try communicating with my app under test.

testLaunch(): XCTAssertEqual failed: throwing "NSInvalidArgumentException: *** -[NSProxy doesNotRecognizeSelector:interfaceOrientation] called!"

What could be the reason for this?

func testLaunch() throws {
    let app = XCUIApplication()
    app.launch()
     
    let _ = EarlGrey.selectElement(with: grey_keyWindow())
    try EarlGrey.rotateDevice(to: .landscapeLeft)
    XCTAssertEqual(host.interfaceOrientation(), .landscapeRight) // exception here
}

var host: SwiftTestsHost {
    return unsafeBitCast(
        GREYHostApplicationDistantObject.sharedInstance,
        to: SwiftTestsHost.self)
}

Definition in Helper bundle:

@objc
protocol SwiftTestsHost {
    func interfaceOrientation() -> UIInterfaceOrientation
}

// Extension is not exposed to UI Test Target
extension GREYHostApplicationDistantObject: SwiftTestsHost {
    func interfaceOrientation() -> UIInterfaceOrientation {
        return UIApplication.shared.statusBarOrientation
    }
}