I have a file browser Swift Package that I am writing tests for. One of the features is that you can save a boolean value about the file. If you press on the square it check or unchecks. If you press on the file name then it does a quick view of the file or take user defined action. I tried using the record feature but it only stores the Cell identifier so when I rerun the test script the QuickView action takes effect instead of the boolean toggle as I want. I have tried using the accessibility modifier but without success.
Now here is the code that generates the view.
public var body: some View {
HStack {
List {
ForEach(fileList, id: \.self) { file in
NavigationLink(destination: FileLinkView(item:file)) {
HStack {
HStack {
Image(uiImage: file.type.image())
VStack {
Text(file.displayName).font(.body).accessibility(identifier: "displayName")
translateDateString(from: file.fileAttributes?.fileCreationDate() ?? Date()).font(.footnote)
}
}
Spacer()
if !file.isDirectory {
extraInfoView1(file:file)
}
}
}.navigationBarTitle(validInitialPath.lastPathComponent)
}.onDelete( perform: deleteFile)
}
}.onAppear {
let tmp = FileParser.sharedInstance.filesForDirectory(validInitialPath, xInfo0: extraInfo0, xInfo1: extraInfo1)
fileList.removeAll()
fileList.append(contentsOf: tmp)
self.didAppear?(self)
}
}// end of body
struct extraInfoView1: View {
@ObservedObject var file: FBFile
var body: some View {
HStack {
if let exInfo = file.fileExInfo0 {
HStack {
Text(exInfo.title)
Image(systemName: file.fileExInfo0Value ? "checkmark.square" : "square"
).onTapGesture {
file.fileExInfo0Value.toggle()
}.accessibility(identifier: "ExInfo0Select")
}
}
if let exInfo = file.fileExInfo1 {
HStack {
Text(exInfo.title)
Image(systemName: file.fileExInfo1Value ? "checkmark.square" : "square"
)
.onTapGesture {
file.fileExInfo1Value.toggle()
}
.accessibility(identifier: "ExInfo1Select")
}
}
} // end of stack
} // end of body
} // end of struct
Now when I stop at the Cell access I print out the descendants and I see Other but I am unable to figure out 1) if these are the elements I want to use, 2) how to get access to Other and 3) how to use them to try to toggle either piece of extra info.
UI Test:
func testOffenseSelection() throws {
// UI tests must launch the application that they test.
let sv:UInt32 = 300
let app = XCUIApplication()
app.launch()
app.buttons["Files"].tap()
let baymaxJpgOffenseDefense20201225123904Button = app.tables/*@START_MENU_TOKEN@*/.cells["Baymax.jpg, Offense, Defense, 2020-12-25 12:39:04"].buttons["Baymax.jpg, Offense, Defense, 2020-12-25 12:39:04"]/*[[".cells[\"Baymax.jpg, Offense, Defense, 2020-12-25 12:39:04\"].buttons[\"Baymax.jpg, Offense, Defense, 2020-12-25 12:39:04\"]",".buttons[\"Baymax.jpg, Offense, Defense, 2020-12-25 12:39:04\"]"],[[[-1,1],[-1,0]]],[1]]@END_MENU_TOKEN@*/
baymaxJpgOffenseDefense20201225123904Button.tap()
app.navigationBars["_TtGC7SwiftUIP13$7fff5767130428DestinationHosting"].buttons["Documents"].tap()
/**********
HELP NEEDED HERE to figure out how to press the image without triggering the navigation link, it works in the app. And Using the recorder does not recreate the image tap;.
***********/
// need to press the offense Image.
let cell = app.tables.cells["Baymax.jpg, Offense, Defense, 2020-12-25 12:39:04"].descendants(matching: .any)
usleep(sv)
}
And Finally here is the debugger output
o cell
t = 13.80s Requesting snapshot of accessibility hierarchy for app with pid 98724
t = 14.17s Find: Descendants matching type Table
t = 14.17s Find: Descendants matching type Cell
t = 14.17s Find: Elements matching predicate '"Baymax.jpg, Offense, Defense, 2020-12-25 12:39:04" IN identifiers'
t = 14.17s Find: Descendants matching type Any
t = 14.17s Requesting snapshot of accessibility hierarchy for app with pid 98724
t = 14.21s Find: Descendants matching type Table
t = 14.21s Find: Descendants matching type Cell
t = 14.21s Find: Elements matching predicate '"Baymax.jpg, Offense, Defense, 2020-12-25 12:39:04" IN identifiers'
t = 14.21s Find: Descendants matching type Any
t = 14.21s Requesting snapshot of accessibility hierarchy for app with pid 98724
t = 14.24s Find: Descendants matching type Table
t = 14.24s Find: Descendants matching type Cell
t = 14.24s Find: Elements matching predicate '"Baymax.jpg, Offense, Defense, 2020-12-25 12:39:04" IN identifiers'
t = 14.25s Requesting snapshot of accessibility hierarchy for app with pid 98724
t = 14.27s Find: Descendants matching type Table
t = 14.27s Find: Descendants matching type Cell
t = 14.28s Requesting snapshot of accessibility hierarchy for app with pid 98724
t = 14.30s Find: Descendants matching type Table
t = 14.31s Requesting snapshot of accessibility hierarchy for app with pid 98724
Find: Target Application 'com.wolfshead.FileBrowserSUI-Dev1'
Output: {
Application, pid: 98724, label: 'FileBrowserSUI_Dev'
}
↪︎Find: Descendants matching type Table
Output: {
Table, {{53.0, 42.0}, {704.0, 995.5}}
}
↪︎Find: Descendants matching type Cell
Output: {
Cell, {{53.0, 150.0}, {704.0, 48.5}}, label: 'BB8.jpg, Offense, Defense, 2020-12-25 12:39:04'
Cell, {{53.0, 198.5}, {704.0, 48.5}}, label: 'Baymax.jpg, Offense, Defense, 2020-12-25 12:39:04'
Cell, {{53.0, 247.0}, {704.0, 48.5}}, label: 'Images.zip, Offense, Defense, 2020-12-25 12:39:04'
Cell, {{53.0, 295.5}, {704.0, 48.5}}, label: 'Stitch.jpg, Offense, Defense, 2020-12-25 12:39:04'
Cell, {{53.0, 344.0}, {704.0, 48.5}}, label: 'cameraStreams, 2020-12-25 01:31:53'
}
↪︎Find: Elements matching predicate '"Baymax.jpg, Offense, Defense, 2020-12-25 12:39:04" IN identifiers'
Output: {
Cell, {{53.0, 198.5}, {704.0, 48.5}}, label: 'Baymax.jpg, Offense, Defense, 2020-12-25 12:39:04'
}
↪︎Find: Descendants matching type Any
Output: {
Other, {{53.0, 198.5}, {704.0, 48.5}}
Other, {{53.0, 198.5}, {704.0, 48.5}}
Button, {{69.0, 204.5}, {668.0, 36.5}}, identifier: 'displayName-ExInfo0Select-ExInfo1Select', label: 'Baymax.jpg, Offense, Defense, 2020-12-25 12:39:04'
Other, {{53.0, 198.5}, {704.0, 48.5}}
}
