How do we use NSOpenPanel in XCUITests?

In order to test my application UI I need to be able to open file but XCUITests recording doesn't work after a NSOpenPanel is displayed.


Is there something I'm missing or any workaround?


In my case I want to open a video in my AVPlayer.

I realise this is very old now, but if anybody else lands here with the same question as I did without finding anything else suitable on Google .... This example is based on your app having a button labelled "+", navigating to a folder other than the default folder in the Open dialog, selecting a file you expect to exist & clicking Ok.

Code Block Swift
func testAddCertificateButton() {
let app = XCUIApplication()
let windowsQuery = app.windows
let addButton = windowsQuery.buttons["+"]
XCTAssert(addButton.exists)
addButton.click()
let openDialog = app.dialogs.firstMatch
XCTAssert(openDialog.waitForExistence(timeout: 5))
// Make sure we're on the right type of dialog by checking the "Where:" popover button exists
// Also grab a reference to the Open button so we can click it later
let openButton = openDialog.buttons["Open"]
let whereButton = openDialog.popUpButtons["Where:"]
XCTAssert(whereButton.exists)
XCTAssert(openButton.exists)
app.typeKey("g", modifierFlags: [.command, .shift])
let sheet = openDialog.sheets.firstMatch
XCTAssert(sheet.waitForExistence(timeout: 5))
let goButton = openDialog.buttons["Go"]
let input = sheet.comboBoxes.firstMatch
XCTAssert(goButton.exists)
XCTAssert(input.exists)
input.typeText("/Full/Path/To/Location")
goButton.click()
let file = openDialog.images["FileYouExpect.txt"]
XCTAssert(cert.waitForExistence(timeout: 5))
file.click()
openButton.click()
}


That actually should say

Code Block Swift
XCTAssert(file.waitForExistence(timeout: 5))


That's what I get for modifying code in a web browser :)

Seems this broke in Monterey.

How do we use NSOpenPanel in XCUITests?
 
 
Q