@@ -56,23 +56,94 @@ enum Query {
5656 navigator. descendants ( matching: . outlineRow)
5757 }
5858
59+ static func getAddButton( _ window: XCUIElement ) -> XCUIElement {
60+ if window. buttons [ " addButton " ] . exists {
61+ return window. buttons [ " addButton " ]
62+ }
63+
64+ if window. popUpButtons [ " addButton " ] . exists {
65+ return window. popUpButtons [ " addButton " ]
66+ }
67+
68+ return window. descendants ( matching: . any) . matching ( identifier: " addButton " ) . firstMatch
69+ }
70+
5971 static func getSelectedRows( _ navigator: XCUIElement ) -> XCUIElementQuery {
6072 getRows ( navigator) . matching ( NSPredicate ( format: " selected = true " ) )
6173 }
6274
63- static func getProjectNavigatorRow ( fileTitle: String , index : Int = 0 , _ navigator: XCUIElement ) -> XCUIElement {
64- return getRows ( navigator)
75+ static func getProjectNavigatorRows ( fileTitle: String , _ navigator: XCUIElement ) -> XCUIElementQuery {
76+ getRows ( navigator)
6577 . containing ( . textField, identifier: " ProjectNavigatorTableViewCell- \( fileTitle) " )
78+ }
79+
80+ static func getProjectNavigatorRow( fileTitle: String , index: Int = 0 , _ navigator: XCUIElement ) -> XCUIElement {
81+ return getProjectNavigatorRows ( fileTitle: fileTitle, navigator)
6682 . element ( boundBy: index)
6783 }
6884
85+ static func waitForProjectNavigatorRow(
86+ fileTitle: String ,
87+ index: Int = 0 ,
88+ _ navigator: XCUIElement ,
89+ timeout: TimeInterval
90+ ) -> XCUIElement ? {
91+ let deadline = Date ( ) . addingTimeInterval ( timeout)
92+ while Date ( ) < deadline {
93+ let row = getProjectNavigatorRow ( fileTitle: fileTitle, index: index, navigator)
94+ if row. exists {
95+ return row
96+ }
97+ RunLoop . current. run ( until: Date ( ) . addingTimeInterval ( 0.05 ) )
98+ }
99+
100+ let row = getProjectNavigatorRow ( fileTitle: fileTitle, index: index, navigator)
101+ return row. exists ? row : nil
102+ }
103+
104+ static func getLastProjectNavigatorRow( fileTitle: String , _ navigator: XCUIElement ) -> XCUIElement {
105+ let matchingRows = getProjectNavigatorRows ( fileTitle: fileTitle, navigator)
106+ return matchingRows. element ( boundBy: max ( matchingRows. count - 1 , 0 ) )
107+ }
108+
69109 static func disclosureIndicatorForRow( _ row: XCUIElement ) -> XCUIElement {
70- row. descendants ( matching: . disclosureTriangle) . element
110+ row. descendants ( matching: . disclosureTriangle) . firstMatch
71111 }
72112
73113 static func rowContainsDisclosureIndicator( _ row: XCUIElement ) -> Bool {
74114 disclosureIndicatorForRow ( row) . exists
75115 }
116+
117+ static func waitForRowCount(
118+ _ navigator: XCUIElement ,
119+ greaterThan rowCount: Int ,
120+ timeout: TimeInterval
121+ ) -> Bool {
122+ waitForRowCount ( navigator, timeout: timeout) { $0 > rowCount }
123+ }
124+
125+ static func waitForRowCount(
126+ _ navigator: XCUIElement ,
127+ equalTo rowCount: Int ,
128+ timeout: TimeInterval
129+ ) -> Bool {
130+ waitForRowCount ( navigator, timeout: timeout) { $0 == rowCount }
131+ }
132+
133+ private static func waitForRowCount(
134+ _ navigator: XCUIElement ,
135+ timeout: TimeInterval ,
136+ predicate: ( Int ) -> Bool
137+ ) -> Bool {
138+ let deadline = Date ( ) . addingTimeInterval ( timeout)
139+ while Date ( ) < deadline {
140+ if predicate ( getRows ( navigator) . count) {
141+ return true
142+ }
143+ RunLoop . current. run ( until: Date ( ) . addingTimeInterval ( 0.05 ) )
144+ }
145+ return predicate ( getRows ( navigator) . count)
146+ }
76147 }
77148
78149 enum TabBar {
0 commit comments