milcgroup/swiftappium
A modern Swift client library for Appium automation with a powerful **Web Recorder** that captures browser interactions and generates executable Swift test code automatically.
β¨ Key Features
- π¬ Web Recorder - Record browser interactions and generate Swift test code automatically
- π One-Command Setup - Just run
swiftappiumto start recording - π Auto-Connect - Automatically discovers and connects to existing Appium sessions
- β‘ Real-time Playback - Replay recorded events instantly in the browser
- π± Cross-Platform - Works on macOS and Linux
- π― Type-safe API - Modern Swift with async/await support
Requirements
- macOS 14.0+ or Linux (Ubuntu 20.04+)
- Swift 5.10+
- Appium Server 2.0+
- Chrome/Chromium browser
π Quick Start
1. Install Dependencies
# Install Node.js and Appium
brew install node # macOS
# or: apt-get install nodejs npm # Linux
npm install -g appium
appium driver install chromium2. Start Appium Server
appium3. Start Recording
# Clone and build SwiftAppium
git clone https://github.com/milcgroup/SwiftAppium.git
cd SwiftAppium
swift build
# Start the web recorder
swift run swiftappiumThat's it! The web recorder will:
- β Auto-open your browser to the recording interface
- β Auto-connect to your Appium session
- β Start recording immediately
4. Record Your First Test
- Navigate to any website in your browser
- Interact normally - click buttons, fill forms, navigate pages
- Watch events appear in real-time in the recording interface
- Click "βΆοΈ Play Events" to replay your interactions
- Click "πΎ Export Swift Code" to download your test
Generated Swift code example:
import SwiftAppium
import Testing
@Test("Recorded browser interactions")
func recordedBrowserTest() async throws {
let session = try await Session(
host: "127.0.0.1",
port: 4723,
driver: Driver.Chromium()
)
// Click login button
try await session.click(
Element(.xpath, Selector("//button[@id='login']"))
)
// Type username
try await session.type(
Element(.xpath, Selector("//input[@name='username']")),
text: "testuser"
)
}π¬ Web Recorder Features
β Automatic Everything
- Auto-connects to existing Appium sessions
- Auto-opens browser interface
- Auto-starts recording when connected
- Auto-generates clean Swift code
β Smart Event Capture
- Click events - Buttons, links, any clickable element
- Text input - Forms, search boxes, text areas
- Element detection - Robust XPath generation with ID prioritization
- Event validation - Filters out invalid or duplicate events
β Real-time Playback
- Instant replay - Test your recorded interactions immediately
- Visual feedback - See events execute in real-time
- Error handling - Graceful handling of missing elements
β Clean Code Generation
- Modern Swift - Uses async/await patterns
- SwiftAppium API - Generated code uses the full SwiftAppium library
- Proper structure - Includes imports, error handling, and test framework integration
- Executable immediately - No manual editing required
π οΈ Advanced Usage
Custom Port
swift run swiftappium --port 9090Custom Appium Server
swift run swiftappium --appium-url http://remote-server:4723Command Line Options
swift run swiftappium --helpπ§ How It Works
The web recorder uses a sophisticated approach to capture and replay browser interactions:
- JavaScript Injection - Injects event listeners into browser pages
- Event Capture - Records genuine user interactions (clicks, typing)
- Smart Selectors - Generates robust XPath selectors (prioritizes element IDs)
- Real-time Sync - Updates the web interface as events are captured
- Code Generation - Converts events to clean, executable Swift code
- Playback Engine - Replays events using WebDriver commands
π Documentation
- Error Handling - Error handling strategies
- Troubleshooting - Common issues and solutions
π¨ Troubleshooting
Common Issues
"No active Appium sessions found"
# Make sure Appium server is running
appium
# In another terminal, create a browser session
# (or use your existing Appium client)"Port 8080 is in use"
# Use a different port
swift run swiftappium --port 9090"Failed to open browser automatically"
- Manually navigate to
http://localhost:8080 - Check that you have a default browser set
Events not being captured
- Make sure you're interacting with the actual browser window (not the recording interface)
- Some sites with strict CSP may block JavaScript injection
- Try refreshing the page and reconnecting
Contributing
We welcome contributions! Please see our contributing guidelines and feel free to submit issues and pull requests.
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Package Metadata
Repository: milcgroup/swiftappium
Default branch: main
README: README.md