A Swift library for UI automation of apps and browsers via communication with WebDriver endpoints, such as Selenium, Appium or the Windows Application Driver.
swift-webdriver
is meant to support both the Selenium legacy JSON wire protocol and its successor, the W3C-standard WebDriver protocol, against any WebDriver endpoint. In practice, it has been developed and tested for WinAppDriver-based scenarios on Windows, and may have gaps in other environments.
A swift-webdriver
"Hello world" using WinAppDriver
might look like this:
let session = Session(
webDriver: WinAppDriver.start(), // Requires WinAppDriver to be installed on the machine
desiredCapabilities: WinAppDriver.Capabilities.startApp(name: "notepad.exe"))
session.findElement(byName: "close")?.click()
To use swift-webdriver
in your project, add a reference to it in your Package.swift
file as follows:
let package = Package(
name: "MyPackage",
dependencies: [
.package(url: "https://github.com/thebrowsercompany/swift-webdriver", branch: "main")
],
targets: [
.testTarget(
name: "UITests",
dependencies: [
.product(name: "WebDriver", package: "swift-webdriver"),
]
)
]
)
Build and run tests using swift build
and swift test
, or use the Swift extension for Visual Studio Code.
For additional examples, refer to the Tests\WebDriverTests
directory.
To build with CMake, use the Ninja generator:
cmake -S . -B build -G Ninja
cmake --build .\build\
The library has two logical layers:
- Wire layer: The
WebDriver
andRequest
protocols and their implementations provide a strongly-typed representation for sending REST requests to WebDriver endpoints. Each request is represented by a struct underRequests
. The library can be used and extended only at this layer if desired. - Session API layer: The
Session
andElement
types provide an object-oriented representation of WebDriver concepts with straightforward functions for every supported command such asfindElement(id:)
andclick()
.
Where WebDriver endpoint-specific functionality is provided, such as for launching and using a WinAppDriver instance, the code is kept separate from generic WebDriver functionality as much as possible.
We welcome contributions for:
- Additional command bindings from the WebDriver and Selenium legacy JSON wire protocols
- Improved support for other platforms and WebDriver endpoints
Please include tests with your submissions. Tests launching apps should rely only on GUI applications that ship with the Windows OS, such as notepad.