Bartłomiej Semańczyk Bartłomiej Semańczyk - 4 years ago 97
Swift Question

How to reorder cells under UITests?

Along with

UITests
and
UITableView
I need to reorder cells. Is it possible? I tried
myTable.swipeDown()
but it is called in that place of cell which do not respond for reordering. How can I do this? Is it possible at all?

enter image description here

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download