0

I'm trying to write some UI tests for my app and i'm using a third party popup view library. Under the hood i see it's using the fullscreenCover view modifier.

My tested class looks something like this

struct FirstTimeView: View {    var body: some View {       TabView(selection: $selection) { <some views for tab view> // one of the above views contains a tap taht toggles showLegendView       }       .tabViewStyle(PageTabViewStyle())     .popup(isPresented: self.$showLegendView,         view: {           LegendView()             .cornerRadius(15) .accessibilityIdentifier("legend")         }, customize: popupDefaultCustomisationWithOpaqueAndCloseOnTap)   } 

and my test class looks something like this

app.staticTexts[<id of element to toggle showLegendView>].firstMatch.tap() 

If I tap on the popup view wherever, it's dismissed, but i want to tap on an element inside it so i can also test that it exists there

app.staticTexts["legend"].firstMatch.tap() 

if I put a breakpoint on the above line and print the static texts of the app I get

Find: Target Application 'com.test' Output: { Application, 0x1023212c0, pid: 40158, label: 'test' } ↪︎Find: Descendants matching type StaticText Output: { StaticText, 0x102716de0, {{349.0, 638.7}, {18.0, 14.0}}, identifier: 'legend', label: 'test1' StaticText, 0x102717500, {{277.2, 638.7}, {46.7, 14.0}}, identifier: 'legend', label: 'test2' StaticText, 0x102717bd0, {{233.2, 638.7}, {19.7, 14.0}}, identifier: 'legend', label: 'test3' 

But if i let the code run I get

 t = 397.10s Tap "legend" StaticText t = 397.11s Wait for com.test to idle t = 397.12s Find the "legend" StaticText t = 397.14s Check for interrupting elements affecting "legend" StaticText t = 397.21s Synthesize event t = 397.24s Scroll element to visible t = 397.24s Find the "legend" StaticText t = 397.28s Computed hit point {-1, -1} after scrolling to visible t = 397.28s Failed: Failed to scroll to visible (by AX action) StaticText, {{349.0, 638.7}, {18.0, 14.0}}, identifier: 'legend', label: 'test1', error: Error kAXErrorCannotComplete performing AXAction kAXScrollToVisibleAction on element AX element pid: 40158, elementOrHash.elementID: 105553169980768.46 

Not sure why this is happening.

Any ideas? 🙏

enter image description here

1 Answer 1

0

Try these methods:

  • Consider using app.staticTexts["legend"].element(boundBy:0)
  • See if the isHittable property of the "legend" button is true (If it is not hittable, try to tap using its coordinates)
  • Try to make the button's container view's "isAccessibilityElement" value set to true

My recommendation is to try accessing an element using its both identifier and label in the following manner if you have numerous elements with the same identifier:

extension XCUIElementQuery { func element(id identifier: String, label: String) -> XCUIElement { let predicate = NSPredicate(format: "identifier == %@ AND label == %@", identifier, label) return element(matching: predicate) } } 

Ex: app.staticTexts.element(id: "legend", label: "test1")

Good luck!

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.