https://github.com/e-sites/aluminum
Applying the robot pattern to your UI XCTests
https://github.com/e-sites/aluminum
ios swift uitests xctest
Last synced: 8 months ago
JSON representation
Applying the robot pattern to your UI XCTests
- Host: GitHub
- URL: https://github.com/e-sites/aluminum
- Owner: e-sites
- License: mit
- Created: 2018-11-16T21:30:27.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-05-28T10:22:59.000Z (over 5 years ago)
- Last Synced: 2025-02-15T04:18:43.820Z (8 months ago)
- Topics: ios, swift, uitests, xctest
- Language: Swift
- Size: 24.4 KB
- Stars: 4
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README

Aluminum is part of the **[E-sites iOS Suite](https://github.com/e-sites/iOS-Suite)**.
---
Applying the [robot pattern](https://medium.com/capital-one-tech/robot-pattern-testing-for-xcuitest-4c2f0c40b4ad) to your UI XCTests.
*Special thanks to [Rob Whitaker](https://medium.com/@r.whitaker?source=post_header_lockup).*[](http://forthebadge.com) [](http://forthebadge.com)
[](http://cocoadocs.org/docsets/Aluminum)
[](https://cocoapods.org/pods/Aluminum)
[](https://github.com/Carthage/Carthage)
[](https://travis-ci.com/e-sites/Aluminum)# Installation
Podfile:
```ruby
target 'YourUITestTarget' do
pod 'Aluminum'
end
```And then
```
pod install
```# Implementation
## Create your robots
```swift
import Foundation
import XCTest
import Aluminumclass 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```swift
func testUI() {
let app = XCUIApplication()
WelcomeRobot(app: app)
.openList()
.openDetail()
.checkTitle()
}```