Lightweight UITests framework based on XCTest to help you write and maintain UITests quickly and easily with well organised code structure.
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler. To add a package dependency to your Xcode project, select File > Swift Packages > Add Package Dependency and enter https://github.com/treatwell/twuitests.git
or add dependency to your Package.swift
import PackageDescription
let package = Package(
name: "MySPMLibrary",
dependencies: [
.package(url: "https://github.com/treatwell/twuitests.git", from: "0.20.0")
]
)
- Add
git "https://github.com/treatwell/twuitests.git"
to your Cartfile. - Run
carthage update
to fetch & build. Append--platform iOS
if only iOS build is needed.
- Build settings: in Runpath Search Paths add
$(PROJECT_DIR)/Carthage/Build/iOS
to tell linker where to find frameworks. - Build phases: drag and drop TWUITests and Swifter frameworks in Link binaries and frameworks phase. Frameworks are in
Carthage/Build/iOS
. - Info plist file: add
App Transport Security Settings
dictionary and key-valueNSAllowsLocalNetworking
=true
to allow loading of local resources.
- Create Configuration class to hold parameters and initial API stubs.
- Create project specific parameters to be injected into main app.
- Create API stubs structure.
- Tip: use template to generate UITests code. Add template to Xcode by running add_ui_tests_templates.sh script (in
Xcode Templates
folder).
Server API local responses should be kept at path: LIBRARY_DIR + "/Developer/CoreSimulator/Devices/" + DEVICE_ID + "/data/Library/Caches/ApiStubs/"
Tip: have a script to copy stubs to required destination in build phase. Python script example can be found here.
Working example project can be found in Example
folder.
Test:
final class LoginUITests: UITestCase {
func testSomething() throws {
try start(with: Configuration())
.loginStep.someAction()
.loginStep.loginPageIsVisible()
}
}
Step:
final class LoginStep: UITestBase, Step {
private lazy var loginPage = LoginPage(app: app)
func tapSomeButton() -> Self {
loginPage.someButton.tap()
return self
}
}
// MARK: - Validation
extension LoginStep {
func loginPageIsVisible() {
loginPage.someView.existsAfterDelay()
loginPage.someButton.existsAfterDelay()
}
}
Page:
final class LoginPage: UITestBase, Page {
var someView: XCUIElement {
return app.otherElements[LoginAccessibilityIndetifiers.View.some]
}
var someButton: XCUIElement {
return app.buttons[LoginAccessibilityIndetifiers.Button.some]
}
}
Ignas Urbonas - [email protected]
Marius Kažemėkaitis - [email protected]
The contents of this repository is licensed under the Apache License, version 2.0.