Aluminum 1.2.2

Aluminum 1.2.2

Maintained by Bas van Kuijck.



Aluminum 1.2.2

  • By
  • Bas van Kuijck

Aluminum

Aluminum is part of the E-sites iOS Suite.


Applying the robot pattern to your UI XCTests.
Special thanks to Rob Whitaker.

forthebadge forthebadge

Platform CocoaPods Compatible Carthage compatible Travis-ci

Installation

Podfile:

target 'YourUITestTarget' do
    pod 'Aluminum'
end

And then

pod install

Implementation

Create your robots

import Foundation
import XCTest
import Aluminum

class WelcomeRobot: Aluminum.Robot {
    lazy var startButton = app.buttons["WelcomeStartButton"]

    override func requiredElements() -> [XCUIElement] {
        return [ startButton ]
    }

    @discardableResult
    func openList() -> ListRobot {
        startButton()
        return ListRobot(app: app)
    }
}

class ListRobot: Aluminum.Robot {
    lazy var cell0 = app.cells["Cell0"]

    override func requiredElements() -> [XCUIElement] {
        return [ cell0 ]
    }

    @discardableResult
    func openDetail() -> DetailRobot {
        cell0.tap()
        return DetailRobot(app: app, parent: self)
    }
}

class DetailRobot: Aluminum.Robot, Aluminum.NavigableRobot {
    lazy var titleLabel = app.staticTexts["DetailTitleLabel"]
	
    var parent: ListRobot!

    required convenience init(app: XCUIApplication, parent: ListRobot) {
        self.init(app: app)
        self.parent = parent
    }

    override func requiredElements() -> [XCUIElement] {
        return [ titleLabel ]
    }
    
    @discardableResult
    func checkTitle() -> DetailRobot {
        XCTAssertEqual(titleLabel.label, "Desired text")
    }
}

Run the test

func testUI() {
    let app = XCUIApplication()
	
    WelcomeRobot(app: app)
    .openList()
    .openDetail()
    .checkTitle()
}