0

I am working on UI Test for several System Alerts in a row (ie. a video app to get permission for Camera, Microphone and Photos). With a sample project, it seems the new method addUIInterruptionMonitorWithDescription is not working for Landscape mode.

I come across this post Swift UI Test - User Notifications System Alert, but the case is different for me.

My code looks like this:

    let desc = "\u{201c}Alert\u{201d} Would Like to Access the Camera"

    let app = XCUIApplication()

    addUIInterruptionMonitorWithDescription(desc) { (alert) -> Bool in
        let okButton = alert.buttons["OK"]
        print(okButton.frame)
        okButton.tap()
        return true
    }
    app.buttons["Alert"].tap()

It works for Portrait, not Landscape. The case can be reproduced by Simulator and Device.

Moreover the okButton.frame I got in Portrait is

 CGRect
  ▿ origin : CGPoint
    - x : 207.0
    - y : 387.666666666667
  ▿ size : CGSize
    - width : 135.0
    - height : 44.0

but the frame in Landscape shows like this

Landscape System Alert

 CGRect
  ▿ origin : CGPoint
    - x : 143.333333333333
    - y : 368.0
  ▿ size : CGSize
    - width : 44.0
    - height : 135.0

The test failure error I got is this one

test failure: -[AlertUITests testExample()] failed: UI Testing Failure - Failed to scroll to visible (by AX action) Button 0x14df73840: traits: 8589934593, {{277.0, 345.0}, {46.0, 30.0}}, label: 'Button', error: Error -25204 performing AXAction 2003

Any idea?

EDIT 1

Submitted to Radar rdar://23931990

Community
  • 1
  • 1
Harry Ng
  • 1,070
  • 8
  • 20
  • This is the exact problem of the question you references. Check out the asker's edits, they mention the app being in landscape mode as well. – Joe Masilotti Dec 17 '15 at 01:47
  • @JoeMasilotti I noticed the edit. However, it is a different problem. As mentioned by the asker, his app taps on the `Dont Allow` button, while in my case, it shows error with AX action. – Harry Ng Dec 17 '15 at 01:51
  • Sounds like there's a bug with landscape system alerts, right? I think a radr is all we can do here. – Joe Masilotti Dec 17 '15 at 01:52

1 Answers1

0

It's a framework bug.

Try use something like this:

Helpers:

var device: XCUIDevice {return XCUIDevice.shared()}

extension XCUIDevice {

    func type() -> String {

        if XCUIApplication().windows.element(boundBy: 0).horizontalSizeClass == .compact || XCUIApplication().windows.element(boundBy: 0).verticalSizeClass == .compact {

            return "iPhone"

        } else {

            return "iPad"
        }
    }
}

Method:

func handleOrientation(_ orientationAltered: Bool) -> Bool {

        guard device.type() == "iPad" else {return false}

        if !orientationAltered && device.orientation == .landscapeLeft {

            device.orientation = .portrait
            return true

        } else if orientationAltered && (device.orientation == .landscapeLeft || device.orientation == .landscapeRight) {

            device.orientation = .landscapeLeft
            return false

        } else {return false}
    }
Oxi Ros
  • 11
  • 3