All Projects → joemasilotti → Ui Testing Cheat Sheet

joemasilotti / Ui Testing Cheat Sheet

How do I test this with UI Testing?

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Ui Testing Cheat Sheet

Peasy
A pure Swift mock server for embedding and running directly within iOS/macOS UI tests. Easy peasy.
Stars: ✭ 32 (-98.43%)
Mutual labels:  xctest, xcuitest
ios-ui-automation-overview
An overview of popular iOS UI testing solutions.
Stars: ✭ 23 (-98.87%)
Mutual labels:  xctest, ui-testing
Bookstore Ios
 Sample iOS App - A collection of examples and patterns for Unit Testing, UI Testing, handling Result/Optionals, writing documentation, and more. Details in README.
Stars: ✭ 147 (-92.79%)
Mutual labels:  ui-testing, xctest
Xctesthtmlreport
Xcode-like HTML report for Unit and UI Tests
Stars: ✭ 489 (-76.02%)
Mutual labels:  ui-testing, xctest
dtx codec
A golang based Apple DTX implementation. So you can run on real iOS devices: XCUITests, get CPU metrics, launch and kill apps from any OS without the need for expensive Apple hardware :-)
Stars: ✭ 25 (-98.77%)
Mutual labels:  xctest, xcuitest
AutoMate-AppBuddy
iOS UI automation tests helper framework, designed to work with the AutoMate
Stars: ✭ 31 (-98.48%)
Mutual labels:  xctest, xcuitest
Quiz App
A repository reflecting the progress made on the "How to Build iOS Apps with Swift, TDD & Clean Architecture" YouTube series, by Caio & Mike.
Stars: ✭ 230 (-88.72%)
Mutual labels:  ui-testing, xctest
SimpleIOSCalculator
Simple iOS Calculator
Stars: ✭ 16 (-99.22%)
Mutual labels:  xctest, xcuitest
XCTestHTMLReport
Xcode-like HTML report for Unit and UI Tests
Stars: ✭ 581 (-71.51%)
Mutual labels:  xctest, ui-testing
Uitestingexample
Example code from my blog post about UI testing
Stars: ✭ 57 (-97.2%)
Mutual labels:  ui-testing, xctest
Stanford Cs 221 Artificial Intelligence
VIP cheatsheets for Stanford's CS 221 Artificial Intelligence
Stars: ✭ 1,923 (-5.69%)
Mutual labels:  cheatsheet
Emcee
Emcee is a tool that runs iOS tests in parallel using multiple simulators across many Macs
Stars: ✭ 148 (-92.74%)
Mutual labels:  xctest
Pandocs
The infamous Pan Docs historical document: the single, most comprehensive Game Boy technical reference.
Stars: ✭ 158 (-92.25%)
Mutual labels:  cheatsheet
Ubuntu Cheatsheet
Ubuntu Terminal Cheatsheet
Stars: ✭ 161 (-92.1%)
Mutual labels:  cheatsheet
Stanford Cs 229 Machine Learning
VIP cheatsheets for Stanford's CS 229 Machine Learning
Stars: ✭ 12,827 (+529.08%)
Mutual labels:  cheatsheet
Tensorflow Cheatsheet
My personal reference for Tensorflow
Stars: ✭ 147 (-92.79%)
Mutual labels:  cheatsheet
Dagger2
Kotlin Dagger2 example project
Stars: ✭ 145 (-92.89%)
Mutual labels:  ui-testing
Cheats.rs
Rust Language Cheat Sheet - https://cheats.rs
Stars: ✭ 2,263 (+10.99%)
Mutual labels:  cheatsheet
Hackthebox
Notes Taken for HTB Machines & InfoSec Community.
Stars: ✭ 167 (-91.81%)
Mutual labels:  cheatsheet
Cheatsheets.pdf
📚 Various cheatsheets in PDF
Stars: ✭ 159 (-92.2%)
Mutual labels:  cheatsheet

UI Testing Cheat Sheet

This repository is complementary code for my post, UI Testing Cheat Sheet and Examples. The post goes into more detail with example images for most examples.

The included project highlights working code with a simple Test Host. This was last updated for Swift 5 on Xcode 11.4.1.

Contents

Basic Functionality

Testing if an element exists

XCTAssert(app.staticTexts["Welcome"].exists)

Testing if text with an ellipsis exists

A full text match will find an element even if the displayed text has an ellipsis due to truncation.

let longNameCell = app.staticTexts["Adolph Blaine Charles David Earl Frederick Gerald Hubert Irvin John Kenneth Lloyd Martin Nero Oliver Paul Quincy Randolph Sherman Thomas Uncas Victor William Xerxes Yancy Wolfeschlegelsteinhausenbergerdorff, Senior"]
XCTAssert(longNameCell.exists) // displayed text is "Adolph Blaine Charles David Earl Freder..."

Waiting for an element to appear

"Waiting" is now built into XCTest.

let goLabel = app.staticTexts["Go!"]
XCTAssertFalse(goLabel.exists)

app.buttons["Ready, set..."].tap()
XCTAssert(goLabel.waitForExistence(timeout: 5))

Interacting with System Controls

Tapping buttons

Identify buttons by their accessibility label.

app.buttons["Add"].tap()

Typing text

First make sure the text field has focus by tapping on it.

let textField = app.textFields["Username"]
textField.tap()
textField.typeText("joemasilotti")

Dismissing alerts

app.alerts["Alert Title"].buttons["Button Title"].tap()

Dismissing action sheets

app.sheets["Sheet Title"].buttons["Button Title"].tap()

Handling system alerts

Present a location services authorization dialog to the user and dismiss it with the following code.

Before presenting the alert add a UI Interruption Handler. When this fires, dismiss with the "Allow" button.

addUIInterruptionMonitor(withDescription: "Location Services") { (alert) -> Bool in
  alert.buttons["Allow"].tap()
  return true
}

app.buttons["Request Location"].tap()
app.tap() // need to interact with the app again for the handler to fire

Sliding sliders

This will slide the value of the slider to 70%.

app.sliders.element.adjust(toNormalizedSliderPosition: 0.7)

Interacting with pickers

A picker with one wheel:

app.pickerWheels.element.adjust(toPickerWheelValue: "Picker Wheel Item Title")

A picker with multiple wheels. Make sure to set the accessibility delegate so the framework can identify the different wheels.

let firstPredicate = NSPredicate(format: "label BEGINSWITH 'First Picker'")
let firstPicker = app.pickerWheels.element(matching: firstPredicate)
firstPicker.adjust(toPickerWheelValue: "first value")

let secondPredicate = NSPredicate(format: "label BEGINSWITH 'Second Picker'")
let secondPicker = app.pickerWheels.element(matching: secondPredicate)
secondPicker.adjust(toPickerWheelValue: "second value")

Tapping links in web views

app.links["Tweet this"].tap()

Interactions

Verifying the current controller's title

XCTAssert(app.navigationBars["Details"].exists)

Reordering table cells

If you have a UITableViewCell with default style and set the text to "Title", the reorder control's accessibility label becomes "Reorder Title".

Using this we can drag one reorder control to another, essentially reordering the cells.

let topButton = app.buttons["Reorder Top Cell"]
let bottomButton = app.buttons["Reorder Bottom Cell"]
bottomButton.press(forDuration: 0.5, thenDragTo: topButton)

XCTAssertLessThanOrEqual(bottomButton.frame.maxY, topButton.frame.minY)

Pull to refresh

Create a XCUICoordinate from the first cell in your table and another one with a dy of six. Then drag the first coordinate to the second.

let firstCell = app.staticTexts["Adrienne"]
let start = firstCell.coordinate(withNormalizedOffset: (CGVectorMake(0, 0))
let finish = firstCell.coordinate(withNormalizedOffset: (CGVectorMake(0, 10))
start.press(forDuration: 0, thenDragTo: finish)

Pushing and popping view controllers

Test if a view controller was pushed onto the navigation stack.

app.buttons["More Info"].tap()
XCTAssert(app.navigationBars["Volleyball?"].exists)

Pop a view controller by tapping the back button in the navigation bar and assert that the title in the navigation bar has changed.

app.navigationBars.buttons.elementBoundByIndex(0).tap()
XCTAssert(app.navigationBars["Volley"].exists)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].