0

I am trying to write a UI Test in Xcode for dragging a dot around the screen. The test had been working for weeks, but as soon as I put text behind the starting position of the dot, the UI Test is no longer able to drag the dot around (even though it's totally draggable in the actual app!). I’m using SwiftUI to develop the app. Why is this happening?

Code:

func testShouldDragDot() throws {
    let endLocation = app.otherElements["endLocation"]
    let thankYouText = app.staticTexts["thankYouText"]
    let dot = app.otherElements["dot"]
    
    dot.press(forDuration: 1, thenDragTo: endLocation)

    XCTAssertEqual(thankYouText.label, "Thank You")
}

Without text behind dot, it works fine:

enter image description here

But with text behind dot, the test fails:

enter image description here

wristbands
  • 1,021
  • 11
  • 22

1 Answers1

0

Can you try and manually change the .zIndex of each element to make sure they are correct in the hierarchy.

Also add waitForExistence to the dot to make sure the layout has fully loaded, then try and drag.

Dharman
  • 30,962
  • 25
  • 85
  • 135
vibrazy
  • 91
  • 2
  • Unfortunately those tips didn't work for me. – wristbands Sep 10 '21 at 16:17
  • What do you see if you do ‘po XCUIApplication()’? – vibrazy Sep 11 '21 at 17:33
  • What do you mean `po XCUIApplication()`? I have declared at the top of my XCTestCase class `let app = XCUIApplication()`. Are you referring to changing that in some way? – wristbands Sep 13 '21 at 23:38
  • In the console, print the hierarchy of the app. You need to check that the elements you interact with are there. If you have an app variable already you can do ‘po app’. That should help you check if all the identifiers are there etc – vibrazy Sep 15 '21 at 05:30
  • Oh I see--you meant setting a breakpoint sometime after creating the XCUIApplication, running the test, and then entering `po app` in the debugger when it hit the breakpoint. I did that, and it looks like all the relevant elements are there. – wristbands Sep 21 '21 at 01:09