How to add monkey test to iOS apps

Issue #484

Use SwiftMonkey which adds random UITests gestures

Add to UITests target

1
2
3
4
target 'MyAppUITests' do
pod 'R.swift', '~> 5.0'
pod 'SwiftMonkey', '~> 2.1.0'
end

Troubleshooting

Failed to determine hittability of Button

Failed to determine hittability of Button: Unable to fetch parameterized attribute XC_kAXXCParameterizedAttributeConvertHostedViewPositionFromContext, remote interface does not have this capability.

This happens when using SwiftMonkey and somewhere in our code uses isHittable, so best to avoid that by having isolated monkey test only

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import XCTest
import SwiftMonkey

class MonkeyTests: XCTestCase {
var app: XCUIApplication!

override func setUp() {
continueAfterFailure = false
app = XCUIApplication()
app.launch()
}

func testMonkey() {
let monkey = Monkey(frame: app.frame)
monkey.addDefaultUIAutomationActions()
monkey.addXCTestTapAlertAction(interval: 100, application: app)
monkey.monkeyAround()
}
}

Another workaround is possibly use addDefaultXCTestPublicActions other than addDefaultUIAutomationActions

UI Test Activity:

Assertion Failure: MonkeyXCTest.swift:33: Failed to get matching snapshots: Timed out while evaluating UI query.

This seems related to SwiftMonkey trying to snapshot. Workaround is to remove

1
monkey.addXCTestTapAlertAction(interval: 100, application: app)

Comments