thebrowsercompany / swift-webdriver

A Swift library for communicating with WebDriver (Appium/WinAppDriver) endpoints
BSD 3-Clause "New" or "Revised" License
104 stars 3 forks source link

swift-webdriver

Build & Test

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.

Usage

A swift-webdriver "Hello world" using WinAppDriver might look like this:

let session = try Session(
    webDriver: WinAppDriver.start(), // Requires WinAppDriver to be installed on the machine
    desiredCapabilities: WinAppDriver.Capabilities.startApp(name: "notepad.exe"))
try session.findElement(locator: .name("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.

CMake

To build with CMake, use the Ninja generator:

cmake -S . -B build -G Ninja
cmake --build .\build\

Architecture

The library has two logical layers:

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.

Timeouts

For UI testing, it is often useful to support retrying some operations until a timeout elapses (to account for animations or asynchrony). swift-webdriver offers two such mechanisms:

Contributing

We welcome contributions for:

Please include tests with your submissions. Tests launching apps should rely only on GUI applications that ship with the Windows OS, such as notepad.