Skip to content
プロジェクト

概要

iOSのタッチイベント合成ライブラリ

Web・アプリ開発

この数値の測り方

計測したスター増加

24時間
0
7日間
0
15日間
+2
1か月
履歴を収集中

期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。

Hammer

If you can't touch this, it's Hammer time!

Demo

Hammer is a touch, stylus and keyboard synthesis library for emulating user interaction events. It enables better ways of triggering UI actions in unit tests, replicating a real world environment as much as possible.

  • Real events: touches and key presses go through UIKit like a user's, so gesture recognizers, controls and SwiftUI handle them as they would on a device.
  • Tests: tap, swipe, drag, pinch and type in XCTest or Swift Testing, finding views by accessibility identifier, label, value or traits.
  • Running apps: the hammer command line tool and AI agents can drive an app that runs Hammer's agent, see what's on screen and try view changes live.

⚠️ IMPORTANT: This library makes extensive use of private APIs and should never be included in a production app.

Installation

Hammer requires Swift 6.0 and iOS 17.0 or later. Add it with SwiftPM. The hammer tool also drives Android apps that run Hammer's Android agent, com.lyft.hammer:hammer-agent-android, attached to each release, see Android.

.package(url: "https://github.com/lyft/Hammer.git", from: "2.0.0")

Add the Hammer product to your test target, and HammerAgent to your app to drive it with the command line tool. CocoaPods is deprecated.

Writing tests

Hammer tests need a host application to send touches. Create an EventGenerator for the view, view controller, SwiftUI view or window you test, then send it events:

@MainActor
final class SignInTests: XCTestCase {
    func testSignIn() async throws {
        let eventGenerator = try await EventGenerator(viewController: SignInViewController())

        try await eventGenerator.fingerTap(at: "email_field")
        try await eventGenerator.keyType("[email protected]")
        try await eventGenerator.fingerTap(at: .label("Sign In", traits: .button))
        try await eventGenerator.waitUntilVisible("home_title")
    }
}

Locations can be an accessibility identifier, an AccessibilityQuery, a view or a point. A few more of what you can do:

try await eventGenerator.fingerSwipe(at: "list", direction: .up)
try await eventGenerator.fingerEdgeSwipe(direction: .right)
try await eventGenerator.fingerDrag(from: "card", to: "trash", duration: 0.5)
try await eventGenerator.fingerPinch(fromDistance: 100, toDistance: 50, duration: 0.5)
try await eventGenerator.keyPress(.returnOrEnter)
try await eventGenerator.waitUntilHittable("checkout_button")

Learn more:

Driving a running app

Start the agent in a debug build of your app. By default it only runs in the simulator and only accepts connections from the same Mac:

#if DEBUG
import HammerAgent

let agent = HammerAgent()
try await agent.start()
#endif

On Android

Add the agent to your app's debug builds, and it starts when a debug build launches. It requires Android 9 (API 28) or later and works with Views and Jetpack Compose:

dependencies {
    debugImplementation("com.lyft.hammer:hammer-agent-android:<version>")
}

Then add --android to the commands below, such as hammer describe --android.

The command line tool

Install the prebuilt hammer tool from the latest release:

mkdir -p ~/.local/bin
curl -fsSL https://github.com/lyft/Hammer/releases/latest/download/hammer-macos.zip -o /tmp/hammer-macos.zip
unzip -o /tmp/hammer-macos.zip -d ~/.local/bin

On Linux, which drives Android only, take the build for your CPU, x86_64 or aarch64:

mkdir -p ~/.local/bin
curl -fsSL https://github.com/lyft/Hammer/releases/latest/download/hammer-linux-x86_64.tar.gz | tar -xz -C ~/.local/bin

Then see what's on screen and act on it:

hammer describe                      # Elements on screen, each with a ref such as e12
hammer tap --ref e12
hammer type-text --identifier email --text "[email protected]"
hammer wait-for --identifier home_title --condition visible
hammer screenshot --output screen.png
hammer help swipe                    # Arguments and examples of a command

To give an AI agent the same commands as tools, run hammer mcp as an MCP server. For example, with Claude Code:

claude mcp add hammer -- ~/.local/bin/hammer mcp

Learn more:

Documentation

Every guide is in docs.

License

Hammer is released under the Apache License. See LICENSE

関連プロジェクトを探す

読み込み中…