Skip to content

Instantly share code, notes, and snippets.

Avatar

Jean Mainguy jhandguy

View GitHub Profile
View StoryRobot.swift
final class StoryRobot: Robot {
private lazy var stackView = app.otherElements["StoryView.stackView"]
private lazy var multimediaImage = stackView.images["StoryView.multimediaImageView"]
private lazy var titleLabel = stackView.staticTexts["StoryView.titleLabel"]
private lazy var abstractLabel = stackView.staticTexts["StoryView.abstractLabel"]
private lazy var bylineLabel = stackView.staticTexts["StoryView.bylineLabel"]
@discardableResult
func checkStoryImage() -> Self {
View StoryUITest.swift
final class StoryUITest: XCTestCase {
private lazy var app = XCUIApplication()
func testStory() {
StoryRobot(app)
.start()
.checkTitle(contains: "U.S. - Politics")
.checkStoryImage()
.checkStoryTitle(contains: "A Trump Endorsement Can Decide a Race. Here’s How to Get One.")
View Predicate.swift
enum Predicate {
case contains(String), doesNotContain(String)
case exists, doesNotExist
case isHittable, isNotHittable
var format: String {
switch self {
case .contains(let label):
return "label == '\(label)'"
case .doesNotContain(let label):
View Robot.swift
class Robot {
private static let defaultTimeout: Double = 30
var app: XCUIApplication
lazy var navigationBar = app.navigationBars.firstMatch
lazy var navigationBarButton = navigationBar.buttons.firstMatch
lazy var navigationBarTitle = navigationBar.otherElements.firstMatch
View UglyUITest.swift
func uglyUITest() {
...
app.launch()
let title = app.navigationBars.firstMatch.otherElements.firstMatch
XCTAssert(title.isHittable)
XCTAssertEqual(title.label, "U.S. - Politics")
let stackView = app.otherElements["StoryView.stackView"]
let multimediaImage = stackView.images["StoryView.multimediaImageView"]
XCTAssert(multimediaImage.isHittable)
let titleLabel = stackView.staticTexts["StoryView.titleLabel"]
View PrettyUITest.swift
func prettyUITest() {
...
StoryRobot(app)
.start()
.checkTitle(contains: "U.S. - Politics")
.checkStoryImage()
.checkStoryTitle(contains: "A Trump Endorsement Can Decide a Race. Here’s How to Get One.")
.checkStoryAbstract(contains: "The president’s grip on G.O.P. primary voters is as strong as it has been since he seized the party’s nomination.")
.checkStoryByline(contains: "By JONATHAN MARTIN and MAGGIE HABERMAN")
.takeScreenshot(named: "Story")
@jhandguy
jhandguy / SomethingViewController.swift
Last active Apr 15, 2019
SomethingViewController
View SomethingViewController.swift
final class SomethingViewController: UIViewController, Accessible {
@IBOutlet private weak var titleLabel: UILabel!
@IBOutlet private weak var descriptionLabel: UILabel!
@IBOutlet private weak var doneButton: UIButton!
override func viewDidLoad() {
generateAccessibilityIdentifiers()
}
}
View Accessible.swift
protocol Accessible {
func generateAccessibilityIdentifiers()
}
extension Accessible {
func generateAccessibilityIdentifiers() {
#if DEBUG
let mirror = Mirror(reflecting: self)
@jhandguy
jhandguy / SomethingViewController.swift
Last active Apr 15, 2019
SomethingViewController
View SomethingViewController.swift
final class SomethingViewController: UIViewController {
@IBOutlet private weak var titleLabel: UILabel!
@IBOutlet private weak var descriptionLabel: UILabel!
@IBOutlet private weak var doneButton: UIButton!
override func viewDidLoad() {
titleLabel.accessibilityIdentifier = "SomethingViewController.titleLabel"
descriptionLabel.accessibilityIdentifier = "SomethingViewController.descriptionLabel"
doneButton.accessibilityIdentifier = "SomethingViewController.doneButton"
View Request+Url.swift
extension Request {
var absoluteUrl: String {
guard let query = parameters.query else {
return url
}
return "\(url)?\(query)"
}
}