UI Test and Screentime

Im having an issue on how to refer to this view / "Allow with passcode" button while UI testing Im trying to UI test our setup procedure and ScreenTime is a part of that process so I need this approval before I go to my next VC

let stHandler = addUIInterruptionMonitor(withDescription: "“Allow Access to Screen Time")
            { (alert) 

or 

let stHandler = addUIInterruptionMonitor(withDescription: "“Allow Access to Screen Time")
            { (group) 

dont work

Anyone any ideas? Thanks in advance

Answered by Developer Tools Engineer in 789826022

If this is an unexpected interruption that is blocking your test from running, you can handle it using addUIInterruptionMonitor and print the debugDescription of group to see what elements are available in that interruption.

If you want to handle as a part of your UI test workflow, you can interact with the popup and see what elements are interact-able using XCUIApplication().debugDescription

You could use the XCUIElementSnapshotProviding class snapshot function to see what the ui test is seeing.

https://developer.apple.com/documentation/xctest/xcuielementsnapshot

Thanks @jlilest Thanks, got bit further with the snapshot 2 children one is the main app that's being tested and the other is what I can only assume is the system popover but not very helpful ▿ 13 elements ▿ 0 : 2 elements ▿ key : XCUIElementAttributeName - _rawValue : elementType - value : 4 ▿ 1 : 2 elements ▿ key : XCUIElementAttributeName - _rawValue : frame ▿ value : 4 elements ▿ 0 : 2 elements - key : Width - value : 393 ▿ 1 : 2 elements - key : Height - value : 852 ▿ 2 : 2 elements - key : Y - value : 0 ▿ 3 : 2 elements - key : X - value : 0 ▿ 2 : 2 elements ▿ key : XCUIElementAttributeName - _rawValue : windowContextID - value : 2843123068 ▿ 3 : 2 elements ▿ key : XCUIElementAttributeName - _rawValue : children ▿ value : 1 element ▿ 0 : 13 elements ▿ 0 : 2 elements - key : label - value : ▿ 1 : 2 elements - key : windowContextID - value : 2843123068 ▿ 2 : 2 elements - key : frame ▿ value : 4 elements ▿ 0 : 2 elements - key : Width - value : 393 ▿ 1 : 2 elements - key : Height - value : 852 ▿ 2 : 2 elements - key : Y - value : 0 ▿ 3 : 2 elements - key : X - value : 0 ▿ 3 : 2 elements - key : horizontalSizeClass - value : 1 ▿ 4 : 2 elements - key : title - value : ▿ 5 : 2 elements - key : identifier - value : ▿ 6 : 2 elements - key : displayID - value : 1 ▿ 7 : 2 elements - key : elementType - value : 1 ▿ 8 : 2 elements - key : enabled - value : 1 ▿ 9 : 2 elements - key : verticalSizeClass - value : 2 ▿ 10 : 2 elements - key : hasFocus - value : 0 ▿ 11 : 2 elements - key : children ▿ value : 2 elements ▿ 0 : 12 elements ▿ 0 : 2 elements - key : label - value : ▿ 1 : 2 elements - key : windowContextID - value : 2843123068 ▿ 2 : 2 elements - key : frame ▿ value : 4 elements ▿ 0 : 2 elements - key : Width - value : 393 ▿ 1 : 2 elements - key : Height - value : 852 ▿ 2 : 2 elements - key : Y - value : 0 ▿ 3 : 2 elements - key : X - value : 0 ▿ 3 : 2 elements - key : horizontalSizeClass - value : 1 ▿ 4 : 2 elements - key : title - value : ▿ 5 : 2 elements - key : identifier - value : ▿ 6 : 2 elements - key : displayID - value : 1 ▿ 7 : 2 elements - key : elementType - value : 1 ▿ 8 : 2 elements - key : enabled - value : 1 ▿ 9 : 2 elements - key : verticalSizeClass - value : 2 ▿ 10 : 2 elements - key : hasFocus - value : 0 ▿ 11 : 2 elements - key : selected - value : 0 ▿ 1 : 12 elements ▿ 0 : 2 elements - key : label - value : ▿ 1 : 2 elements - key : windowContextID - value : 2843123068 ▿ 2 : 2 elements - key : frame ▿ value : 4 elements ▿ 0 : 2 elements - key : Width - value : 393 ▿ 1 : 2 elements - key : Height - value : 233 ▿ 2 : 2 elements - key : Y - value : 852 ▿ 3 : 2 elements - key : X - value : 0 ▿ 3 : 2 elements - key : horizontalSizeClass - value : 1 ▿ 4 : 2 elements - key : title - value : ▿ 5 : 2 elements - key : identifier - value : ▿ 6 : 2 elements - key : displayID - value : 1 ▿ 7 : 2 elements - key : elementType - value : 1 ▿ 8 : 2 elements - key : enabled - value : 1 ▿ 9 : 2 elements - key : verticalSizeClass - value : 2 ▿ 10 : 2 elements - key : hasFocus - value : 0 ▿ 11 : 2 elements - key : selected - value : 0 ▿ 12 : 2 elements - key : selected - value : 0 ▿ 4 : 2 elements ▿ key : XCUIElementAttributeName - _rawValue : verticalSizeClass - value : 2 ▿ 5 : 2 elements ▿ key : XCUIElementAttributeName - _rawValue : title - value : ▿ 6 : 2 elements ▿ key : XCUIElementAttributeName - _rawValue : selected - value : 0 ▿ 7 : 2 elements ▿ key : XCUIElementAttributeName - _rawValue : enabled - value : 1 ▿ 8 : 2 elements ▿ key : XCUIElementAttributeName - _rawValue : horizontalSizeClass - value : 1 ▿ 9 : 2 elements ▿ key : XCUIElementAttributeName - _rawValue : label - value : ▿ 10 : 2 elements ▿ key : XCUIElementAttributeName - _rawValue : displayID - value : 1 ▿ 11 : 2 elements ▿ key : XCUIElementAttributeName - _rawValue : identifier - value : ▿ 12 : 2 elements ▿ key : XCUIElementAttributeName - _rawValue : hasFocus - value : 0

Accepted Answer

If this is an unexpected interruption that is blocking your test from running, you can handle it using addUIInterruptionMonitor and print the debugDescription of group to see what elements are available in that interruption.

If you want to handle as a part of your UI test workflow, you can interact with the popup and see what elements are interact-able using XCUIApplication().debugDescription

UI Test and Screentime
 
 
Q