---
title: "#124: More on UI Testing 🚸"
url: https://littlebitesofcocoa.com/124-more-on-ui-testing
author: Jake Marsh
date: 2015-11-12
published: 2015-11-12
topics: ["Testing","Tools"]
description: "We covered the basics of UI Testing in Xcode when it was first announced all the way back in Bite #30. It's a fantastic way to test our app's interface."
---

# #124: More on UI Testing 🚸

By Jake Marsh, November 12, 2015. HTML: https://littlebitesofcocoa.com/124-more-on-ui-testing

We covered the basics of _UI Testing in Xcode_ when it was first announced all the way back in [Bite #30](https://littlebitesofcocoa.com/30). It's a fantastic way to test our **app's** interface. Today we'll look at a few more _UI Testing_ odds and ends. Let's dive in:

First, let's write a **test** to verify that one of our **table views** properly loads and displays its data. The data is loaded asynchronously (which should be mocked in our test, but that's a future <i>Bite</i>). We'll need to give our **app** a little time to load and render the data we're testing for. We can use an **expectation** to easily pull this off:

``` swift
expectationForPredicate(
  NSPredicate(format: "count > 0"),
  evaluatedWithObject: app.tables.cells,
  handler: nil)

waitForExpectationsWithTimeout(5, handler: nil)
XCTAssertGreaterThan(app.tables.cells.count, 0)
```

**Xcode** will wait up to <i>5 seconds</i> for the **predicate** we've passed in to be **true** (for there to be more than 0 **cells** in our **table**). After that the **XCTAssert** will be executed and evaluated.

We can change the simulated **orientation** of the **device** like this:

``` swift
XCUIDevice.sharedDevice().orientation = .LandscapeLeft
```

Quite helpful for testing all that great new Adaptive UI code!

Finally, let's look at performing some interactions beyond simple **taps**. We can do things like **long press** an **element**:

``` swift
app.buttons["+"].pressForDuration(0.5)
```

or perform simple pans using the convenience **swipe** **functions**:

``` swift
app.tables["Crew"].swipeDown()
```

We can even execute more complex **pan gestures** using the `pressForDuration(duration:thenDragToCoordinate:)` **function**:

``` swift
  let point = table.coordinateWithNormalizedOffset(CGVectorMake(0, 2)
  table.pressForDuration(0.5, thenDragToCoordinate: point)
```
