How to reorder cells under UITests?

2 Solutions Collect From Internet About “How to reorder cells under UITests?”

If you have set the accessibility properties of the custom cell set correctly then the reorder control should be accessible. Let’s assume the cell’s set their accessibility labels/identifiers to “LondonStreet” and “BakerStreet”, respectively.

You can reorder the cells by tapping and dragging from one reorder control to the next. The accessibility identifier for these controls is set automatically from the cell’s information.

let app = XCUIApplication()
app.launch()

let topButton = app.buttons["Reorder LondonStreet"]
let bottomButton = app.buttons["Reorder BakerStreet"]
bottomButton.pressForDuration(0.5, thenDragToElement: topButton)

The "Reorder " prefix was set by the OS. Try using the Accessibility Inspector to see what your reorder control’s values are.

Using the Accessibility Inspector to access the reorder control

I’ve added an example to my UI Testing Cheat Sheet with some working sample code if you would like to try it on your machine.

To enable Accessibility Inspector first you have to go to:

System Preferences > Security & Privacy:

enter image description here

And then Xcode > Open Developer Tool > Accessibility Inspector

enter image description here