Back to Skills

writing-xcuitests

verified

This skill should be used when the user asks to "write XCUITest", "create UI tests", "fix flaky tests", "query XCUIElements", "implement Page Object pattern", or mentions XCUITest, UI testing for iOS/macOS apps. Targets experienced iOS developers who want best practices and efficiency improvements.

View on GitHub

Marketplace

writing-xcuitests-marketplace

bradwindy/writing-xcuitests

Plugin

writing-xcuitests

Repository

bradwindy/writing-xcuitests
1stars

skills/writing-xcuitests/SKILL.md

Last Verified

January 20, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/bradwindy/writing-xcuitests/blob/main/skills/writing-xcuitests/SKILL.md -a claude-code --skill writing-xcuitests

Installation paths:

Claude
.claude/skills/writing-xcuitests/
Powered by add-skill CLI

Instructions

# Writing XCUITests

Guide for writing robust, maintainable XCUITests for iOS and macOS applications. This skill focuses on practical patterns, element querying strategies, and techniques to reduce test flakiness.

## Quick Start

### Element Queries

Prefer accessibility identifiers for reliable element queries:

```swift
// Best: Accessibility identifier
app.buttons["loginButton"].tap()

// Good: Text matching (fragile to localization)
app.buttons["Log In"].tap()

// Avoid: Index-based queries (brittle to UI changes)
app.buttons.element(boundBy: 0).tap()
```

Set accessibility identifiers in your app code:

```swift
button.accessibilityIdentifier = "loginButton"
```

Query by element type and identifier:

```swift
let emailField = app.textFields["emailField"]
let passwordField = app.secureTextFields["passwordField"]
let submitButton = app.buttons["submitButton"]
let statusLabel = app.staticTexts["statusLabel"]
```

### Common Interactions

**Tap elements:**

```swift
app.buttons["submitButton"].tap()
```

**Type text:**

```swift
app.textFields["emailField"].tap()
app.textFields["emailField"].typeText("user@example.com")
```

**Clear and type (preferred for input fields):**

```swift
let emailField = app.textFields["emailField"]
emailField.tap()
// Clear existing text by typing delete keys
if let value = emailField.value as? String, !value.isEmpty {
    let deleteString = String(repeating: XCUIKeyboardKey.delete.rawValue,
                              count: value.count)
    emailField.typeText(deleteString)
}
emailField.typeText("new@example.com")
```

**Toggle switches:**

```swift
let toggleSwitch = app.switches["notificationSwitch"]
if toggleSwitch.value as? String == "0" {
    toggleSwitch.tap()
}
```

### Waiting for Elements

Always wait for elements before interacting:

```swift
let loginButton = app.buttons["loginButton"]
XCTAssertTrue(loginButton.waitForExistence(timeout: 5))
loginButton.tap()
```

Wait for element to disappear (loading indicators):

```

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
7217 chars