Thanks to visit codestin.com
Credit goes to github.com

Skip to content
/ Rafinad Public

A DSL for UI testing of iOS and tvOS apps, featuring a simplified, chainable, and compile-time-safe syntax.

License

hhru/Rafinad

Repository files navigation

Rafinad

Build Status SPM compatible Carthage compatible Cocoapods Platforms Xcode Swift License

Rafinad is a DSL for UI testing of iOS and tvOS apps, featuring a simplified, chainable, and compile-time-safe syntax.

Contents

Requirements

  • iOS 15.0+ / tvOS 15.0+
  • Xcode 16.0+
  • Swift 5.9+

Installation

Swift Package Manager

The Swift Package Manager is a tool for managing the distribution of Swift code. It’s integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.

To integrate Rafinad into your Xcode project using Swift Package Manager, add it to the dependencies value of your Package.swift or the Package list in Xcode:

.package(url: "https://github.com/hhru/Rafinad.git", from: "1.0.0")

Then specify the dependencies for the corresponding targets of your project:

  • RafinadTesting for the UI testing target
  • Rafinad for both the app target and the UI testing target

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks. You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate Rafinad into your Xcode project using Carthage, specify it in your Cartfile:

github "hhru/Rafinad" ~> 1.0.0

Then run carthage update --use-xcframeworks to build the frameworks.

Finally, drag the built .xcframework bundles from the Carthage/Build folder into the "Frameworks and Libraries" section of your project's corresponding targets:

  • RafinadTesting.xcframework for the UI testing target
  • Rafinad.xcframework for both the app target and the UI testing target

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate Rafinad into your Xcode project using CocoaPods, specify its subspecs in your Podfile:

platform :ios, '15.0'
use_frameworks!

target '<Your App Target Name>' do
    pod 'Rafinad/Accessibility', '~> 1.0.0'
end

target '<Your UI Testing Target Name>' do
    pod 'Rafinad', '~> 1.0.0'
end

Finally, run the following command:

$ pod install

Usage

Documentation

Quick Start

Let's walk through a simple example screen, that displays user information. For simplicity, we'll only show the user's name and position. To use Rafinad on this screen in your tests, the first step is to create an accessibility scheme by subclassing the base ScreenAccessibility class:

import Rafinad

// Accessibility scheme for the user screen
class UserAccessibility: ScreenAccessibility {

    let name = TextAccessibility()
    let position = TextAccessibility()
}

Next, set accessibility keys to the components on the screen, using the key-paths from your scheme:

import SwiftUI

struct UserView: View {

    let user: User

    var body: some View {
        VStack(spacing: 4) {
            Text(user.name)
                .font(.largeTitle)
                // Set accessibility key for user name
                .accessibilityKey(\UserAccessibility.name)

            Text(user.position)
                .font(.subheadline)
                .foregroundStyle(.secondary)
                // Set accessibility key for user position
                .accessibilityKey(\UserAccessibility.position)
        }
    }
}

Now your screen is ready for UI testing. You can write tests as follows:

import XCTest
import RafinadTesting

@MainActor
final class UserScreenTests: XCTestCase {

    let application = XCUIApplication()

    func testThatUserNameIsCorrect() {
        application.launch()

        application
            .screen(of: UserAccessibility.self) // get the user screen
            .name // get the name component
            .waitForExistence() // wait for component to appear
            .assert(text: "Steve Jobs") // verify name
    }

    func testThatUserPositionIsCorrect() {
        application.launch()

        application
            .screen(of: UserAccessibility.self) // get the user screen
            .position // get the position component
            .waitForText("CEO") // wait for position text
    }
}

Example App

Example app is a simple iOS and tvOS app that demonstrates how Rafinad works in practice. It's also a good place to start playing with the framework.

Communication

  • If you need help, open an issue.
  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

📬 Feel free to reach out to us on Telegram. We're here to help: https://t.me/hh_tech

License

Rafinad is available under the MIT license. See the LICENSE file for more info.

About

A DSL for UI testing of iOS and tvOS apps, featuring a simplified, chainable, and compile-time-safe syntax.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published