### Basic monkey test setup with Monkey Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/docsets/SwiftMonkey.docset/Contents/Resources/Documents/index.html Creates a test case that uses the Monkey object to configure and run input event generation. It adds default XCTest private actions, an alert action, and runs indefinitely. The example includes commented-out alternatives for seeding and UIAutomation actions. ```swift func testMonkey() { let application = XCUIApplication() // Workaround for bug in Xcode 7.3. Snapshots are not properly updated // when you initially call app.frame, resulting in a zero-sized rect. // Doing a random query seems to update everything properly. // TODO: Remove this when the Xcode bug is fixed! _ = application.descendants(matching: .any).element(boundBy: 0).frame // Initialise the monkey tester with the current device // frame. Giving an explicit seed will make it generate // the same sequence of events on each run, and leaving it // out will generate a new sequence on each run. let monkey = Monkey(frame: application.frame) //let monkey = Monkey(seed: 123, frame: application.frame) // Add actions for the monkey to perform. We just use a // default set of actions for this, which is usually enough. // Use either one of these, but maybe not both. // XCTest private actions seem to work better at the moment. // UIAutomation actions seem to work only on the simulator. monkey.addDefaultXCTestPrivateActions() //monkey.addDefaultUIAutomationActions() // Occasionally, use the regular XCTest functionality // to check if an alert is shown, and click a random // button on it. monkey.addXCTestTapAlertAction(interval: 100, application: application) // Run the monkey test indefinitely. monkey.monkeyAround() } ``` -------------------------------- ### Configure and run SwiftMonkey test Source: https://github.com/zalando/swiftmonkey/blob/master/README.md Basic SwiftMonkey test setup: create an XCUIApplication, initialize a Monkey with the application frame (optionally with a seed for reproducible events), add default public XCTest actions (required after Xcode 10.1), add an alert-tap action every 100 events, and run indefinitely with monkeyAround(). ```swift func testMonkey() { let application = XCUIApplication() // Initialise the monkey tester with the current device // frame. Giving an explicit seed will make it generate // the same sequence of events on each run, and leaving it // out will generate a new sequence on each run. let monkey = Monkey(frame: application.frame) //let monkey = Monkey(seed: 123, frame: application.frame) // Add actions for the monkey to perform. We just use a // default set of actions for this, which is usually enough. // Use either one of these but maybe not both. // XCTest private actions seem to work better at the moment. // before Xcode 10.1, you can use // monkey.addDefaultXCTestPrivateActions() // after Xcode 10.1 We can only use public API monkey.addDefaultXCTestPublicActions() // UIAutomation actions seem to work only on the simulator. //monkey.addDefaultUIAutomationActions() // Occasionally, use the regular XCTest functionality // to check if an alert is shown, and click a random // button on it. monkey.addXCTestTapAlertAction(interval: 100, application: application) // Run the monkey test indefinitely. monkey.monkeyAround() } ``` -------------------------------- ### Podfile for SwiftMonkey and SwiftMonkeyPaws Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/docsets/SwiftMonkey.docset/Contents/Resources/Documents/index.html CocoaPods configuration for installing SwiftMonkeyPaws into the app target and SwiftMonkey into the test target. Use this in your Podfile with app and test targets named App and Tests. ```ruby target "App" do pod "SwiftMonkeyPaws", "~> 1.0" end target "Tests" do pod "SwiftMonkey", "~> 1.0" end ``` -------------------------------- ### Instantiate MonkeyPaws with command-line flag Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkeyPaws/Documentation/Classes.html Example usage of MonkeyPaws. Instantiate it conditionally based on a command-line flag to avoid affecting normal app behavior. Keep a reference to prevent deinitialization. ```swift var paws: MonkeyPaws? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { if CommandLine.arguments.contains("--MonkeyPaws") { paws = MonkeyPaws(view: window!) } return true } ``` -------------------------------- ### Basic Monkey Test with XCTest Private Actions Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/docsets/SwiftMonkey.docset/Contents/Resources/Documents/Classes.html Example of a basic monkey test using the Monkey class. It creates an XCUIApplication, works around an Xcode 7.3 snapshot bug, initializes Monkey with the application frame (optionally with a seed), adds default XCTest private actions, adds an alert-tap action every 100 events, and runs indefinitely with monkeyAround(). ```swift func testMonkey() { let application = XCUIApplication() // Workaround for bug in Xcode 7.3. Snapshots are not properly updated // when you initially call app.frame, resulting in a zero-sized rect. // Doing a random query seems to update everything properly. // TODO: Remove this when the Xcode bug is fixed! _ = application.descendants(matching: .any).element(boundBy: 0).frame // Initialise the monkey tester with the current device // frame. Giving an explicit seed will make it generate // the same sequence of events on each run, and leaving it // out will generate a new sequence on each run. let monkey = Monkey(frame: application.frame) //let monkey = Monkey(seed: 123, frame: application.frame) // Add actions for the monkey to perform. We just use a // default set of actions for this, which is usually enough. // Use either one of these but maybe not both. // XCTest private actions seem to work better at the moment. // UIAutomation actions seem to work only on the simulator. monkey.addDefaultXCTestPrivateActions() //monkey.addDefaultUIAutomationActions() // Occasionally, use the regular XCTest functionality // to check if an alert is shown, and click a random // button on it. monkey.addXCTestTapAlertAction(interval: 100, application: application) // Run the monkey test indefinitely. monkey.monkeyAround() } ``` -------------------------------- ### init(view:tapUIApplication:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkeyPaws/Documentation/Classes/MonkeyPaws.html Initializes a MonkeyPaws instance to visualise input events on a given view, with an option to disable automatic event interception. ```APIDOC ## init(view:tapUIApplication:) ### Description Creates a MonkeyPaws object that visualises input events. The view parameter specifies the view to place the visualisation layer in, typically the main UIWindow. The tapUIApplication parameter controls whether MonkeyPaws swizzles UIApplication methods to intercept events automatically. ### Declaration ```swift public init(view: UIView, tapUIApplication: Bool = true) ``` ### Parameters - **view** (UIView) - Required - The view to put the visualisation layer in. Usually, you will want to pass your main `UIWindow` here. - **tapUIApplication** (Bool) - Optional - By default, MonkeyPaws will swizzle some methods in UIApplication to intercept events so that it can visualise them. If you do not want this, pass `false` here and provide it with events manually. ``` -------------------------------- ### init(frame:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Creates a Monkey object with a randomised seed, generating a different stream of events each time. The frame parameter should be set to the size of the device being tested. ```APIDOC ## init(frame:) ### Description Creates a Monkey object with a randomised seed. This instance will generate a different stream of events each time it is created. ### Declaration ```swift public convenience init(frame: CGRect) ``` ### Parameters - **frame** (CGRect) - Required - The frame to generate events in. Should be set to the size of the device being tested. ``` -------------------------------- ### init(seed:frame:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Creates a Monkey object with a fixed seed, generating the exact same stream of events each time. The seed parameter determines the event stream, and the frame specifies the generation area. ```APIDOC ## init(seed:frame:) ### Description Creates a Monkey object with a fixed seed. This instance will generate the exact same stream of events each time it is created. ### Declaration ```swift public init(seed: UInt32, frame: CGRect) ``` ### Parameters - **seed** (UInt32) - Required - The random seed to use. Each value will generate a different stream of events. - **frame** (CGRect) - Required - The frame to generate events in. Should be set to the size of the device being tested. ``` -------------------------------- ### Monkey init(frame:) Declaration Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html The convenience initializer that creates a Monkey with a randomised seed. ```swift public convenience init(frame: CGRect) ``` -------------------------------- ### Monkey init(seed:frame:) Declaration Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html The initializer that creates a Monkey with a fixed seed. ```swift public init(seed: UInt32, frame: CGRect) ``` -------------------------------- ### MonkeyPaws init declaration Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkeyPaws/Documentation/Classes/MonkeyPaws.html Initializer for MonkeyPaws. The view parameter is typically the main UIWindow. By default, tapUIApplication is true, which swizzles UIApplication methods to intercept events; set to false to provide events manually. ```swift public init(view: UIView, tapUIApplication: Bool = true) ``` -------------------------------- ### addUIAutomationClickVolumeUpAction(weight:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a volume up click event using the private UIAutomation API. ```APIDOC ## addUIAutomationClickVolumeUpAction(weight:) ### Description Adds an action that generates a volume up click event using the private UIAutomation API. ### Method addUIAutomationClickVolumeUpAction ### Parameters - **weight** (Double) - Required - The relative probability of this event being generated. Can be any value larger than zero. Probabilities will be normalised to the sum of all relative probabilities. ### Declaration ```swift public func addUIAutomationClickVolumeUpAction(weight: Double) ``` ``` -------------------------------- ### addUIAutomationPinchOpenAction(weight:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a pinch open gesture at a random screen position using the private UIAutomation API. ```APIDOC ## addUIAutomationPinchOpenAction(weight:) ### Description Adds an action that generates a pinch open gesture at a random screen position using the private UIAutomation API. ### Declaration ```swift public func addUIAutomationPinchOpenAction(weight: Double) ``` ### Parameters - **weight** (Double) - The relative probability of this event being generated. Can be any value larger than zero. Probabilities will be normalised to the sum of all relative probabilities. ``` -------------------------------- ### addUIAutomationPinchOpenAction(weight:) Declaration Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a pinch open gesture at a random screen position using the private UIAutomation API. The weight parameter is the relative probability of this event being generated; it can be any value larger than zero and probabilities are normalised to the sum of all relative probabilities. ```swift public func addUIAutomationPinchOpenAction(weight: Double) ``` -------------------------------- ### Pass --MonkeyPaws launch argument in test Source: https://github.com/zalando/swiftmonkey/blob/master/README.md Set the --MonkeyPaws launch argument on an XCUIApplication in a test case to enable MonkeyPaws for that test run. ```swift let application = XCUIApplication() application.launchArguments = ["--MonkeyPaws"] ``` -------------------------------- ### Add XCTest pinch open action Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a pinch open gesture at a random screen position using the private XCTest API. The weight is the relative probability of this event being generated; probabilities are normalized to the sum of all relative probabilities. ```swift public func addXCTestPinchOpenAction(weight: Double) ``` -------------------------------- ### addXCTestPinchOpenAction(weight:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a pinch open gesture at a random screen position using the private XCTest API. ```APIDOC ## addXCTestPinchOpenAction(weight:) ### Description Adds an action that generates a pinch open gesture at a random screen position using the private XCTest API. ### Declaration ```swift public func addXCTestPinchOpenAction(weight: Double) ``` ### Parameters - **weight** (Double) - Required - The relative probability of this event being generated. Can be any value larger than zero. Probabilities will be normalised to the sum of all relative probabilities. ``` -------------------------------- ### addUIAutomationClickVolumeDownAction(weight:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a volume down click event using the private UIAutomation API. ```APIDOC ## addUIAutomationClickVolumeDownAction(weight:) ### Description Adds an action that generates a volume down click event using the private UIAutomation API. ### Method addUIAutomationClickVolumeDownAction ### Parameters - **weight** (Double) - Required - The relative probability of this event being generated. Can be any value larger than zero. Probabilities will be normalised to the sum of all relative probabilities. ### Declaration ```swift public func addUIAutomationClickVolumeDownAction(weight: Double) ``` ``` -------------------------------- ### Add UIAutomation Click Volume Up Action Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/docsets/SwiftMonkey.docset/Contents/Resources/Documents/Classes/Monkey.html Adds a volume up click event action using the private UIAutomation API. The weight parameter controls the relative probability of this event being generated; probabilities are normalized to the sum of all relative probabilities. ```swift public func addUIAutomationClickVolumeUpAction(weight: Double) ``` -------------------------------- ### Add XCTest orientation action (not working) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a device rotation event using the private XCTest API. Does not currently work. The weight is the relative probability of this event being generated; probabilities are normalized to the sum of all relative probabilities. ```swift public func addXCTestOrientationAction(weight: Double) ``` -------------------------------- ### addUIAutomationPinchCloseAction(weight:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a pinch close gesture at a random screen position using the private UIAutomation API. ```APIDOC ## addUIAutomationPinchCloseAction(weight:) ### Description Adds an action that generates a pinch close gesture at a random screen position using the private UIAutomation API. ### Declaration ```swift public func addUIAutomationPinchCloseAction(weight: Double) ``` ### Parameters - **weight** (Double) - The relative probability of this event being generated. Can be any value larger than zero. Probabilities will be normalised to the sum of all relative probabilities. ``` -------------------------------- ### Workaround for XCTest Frame Bug with Fixed Seed Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Shows how to obtain the application frame while working around an Xcode 7.3 snapshot bug, then create a Monkey with a fixed seed. ```swift let application = XCUIApplication() // Workaround for bug in Xcode 7.3 and later. Snapshots are not properly // updated when you initially call app.frame, resulting in a zero-sized rect. // Doing a random query seems to update everything properly. _ = application.descendants(matching: .any).element(boundBy: 0).frame let monkey = Monkey(seed: 0, frame: application.frame) ``` -------------------------------- ### addUIAutomationShakeAction(weight:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a shake event using the private UIAutomation API. ```APIDOC ## addUIAutomationShakeAction(weight:) ### Description Adds an action that generates a shake event using the private UIAutomation API. ### Method addUIAutomationShakeAction ### Parameters - **weight** (Double) - Required - The relative probability of this event being generated. Can be any value larger than zero. Probabilities will be normalised to the sum of all relative probabilities. ### Declaration ```swift public func addUIAutomationShakeAction(weight: Double) ``` ``` -------------------------------- ### monkeyAround(forDuration:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Generates random events or fixed-interval events based forever, for a specific duration or until the app crashes. ```APIDOC ## monkeyAround(forDuration:) ### Description Generates random events or fixed-interval events based forever, for a specific duration or until the app crashes. ### Declaration ```swift public func monkeyAround(forDuration duration: TimeInterval = .infinity) ``` ### Parameters - **duration** (TimeInterval) - Optional - The duration for which to generate the random events. Set to `.infinity` by default. ``` -------------------------------- ### addUIAutomationSingleTapAction(weight:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a single tap event using the private UIAutomation API. ```APIDOC ## addUIAutomationSingleTapAction(weight:) ### Description Adds an action that generates a single tap event using the private UIAutomation API. ### Declaration ```swift public func addUIAutomationSingleTapAction(weight: Double) ``` ### Parameters - **weight** (Double) - The relative probability of this event being generated. Can be any value larger than zero. Probabilities will be normalised to the sum of all relative probabilities. ``` -------------------------------- ### Workaround for XCTest Frame Bug with Random Seed Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Shows how to obtain the application frame while working around an Xcode 7.3 snapshot bug, then create a Monkey with a randomised seed. ```swift let application = XCUIApplication() // Workaround for bug in Xcode 7.3 and later. Snapshots are not properly // updated when you initially call app.frame, resulting in a zero-sized rect. // Doing a random query seems to update everything properly. _ = application.descendants(matching: .any).element(boundBy: 0).frame let monkey = Monkey(frame: application.frame) ``` -------------------------------- ### SwiftMonkeyPaws: Disable swizzling with tapUIApplication: false Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/index.html Create MonkeyPaws with swizzling disabled. Pass tapUIApplication: false to avoid swizzling UIApplication methods when you already have a source of UIEvents. ```swift paws = MonkeyPaws(view: window!, tapUIApplication: false) ``` -------------------------------- ### addUIAutomationPinchCloseAction(weight:) Declaration Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a pinch close gesture at a random screen position using the private UIAutomation API. The weight parameter is the relative probability of this event being generated; it can be any value larger than zero and probabilities are normalised to the sum of all relative probabilities. ```swift public func addUIAutomationPinchCloseAction(weight: Double) ``` -------------------------------- ### Monkey Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/docsets/SwiftMonkey.docset/Contents/Resources/Documents/Classes.html A general-purpose class for implementing randomised UI tests. It allows scheduling blocks to be run at random or fixed intervals and provides helper functions to generate random coordinates. ```APIDOC ## Monkey ### Description A general-purpose class for implementing randomised UI tests. This class lets you schedule blocks to be run at random or fixed intervals, and provides helper functions to generate random coordinates. ### Declaration ```swift public class Monkey ``` ### Usage Example ```swift func testMonkey() { let application = XCUIApplication() // Workaround for bug in Xcode 7.3. Snapshots are not properly updated // when you initially call app.frame, resulting in a zero-sized rect. // Doing a random query seems to update everything properly. // TODO: Remove this when the Xcode bug is fixed! _ = application.descendants(matching: .any).element(boundBy: 0).frame // Initialise the monkey tester with the current device // frame. Giving an explicit seed will make it generate // the same sequence of events on each run, and leaving it // out will generate a new sequence on each run. let monkey = Monkey(frame: application.frame) //let monkey = Monkey(seed: 123, frame: application.frame) // Add actions for the monkey to perform. We just use a // default set of actions for this, which is usually enough. // Use either one of these but maybe not both. // XCTest private actions seem to work better at the moment. // UIAutomation actions seem to work only on the simulator. monkey.addDefaultXCTestPrivateActions() //monkey.addDefaultUIAutomationActions() // Occasionally, use the regular XCTest functionality // to check if an alert is shown, and click a random // button on it. monkey.addXCTestTapAlertAction(interval: 100, application: application) // Run the monkey test indefinitely. monkey.monkeyAround() } ``` ### Initializers - `Monkey(frame: CGRect)` - Initializes a monkey tester with the given frame. - `Monkey(seed: Int, frame: CGRect)` - Initializes a monkey tester with a specific seed and frame. ### Methods - `addDefaultXCTestPrivateActions()` - Adds a default set of actions using XCTest private API. - `addDefaultUIAutomationActions()` - Adds a default set of actions using UIAutomation (simulator only). - `addXCTestTapAlertAction(interval: Int, application: XCUIApplication)` - Adds an action to tap random buttons on alerts at a given interval. - `monkeyAround()` - Runs the monkey test indefinitely. ``` -------------------------------- ### Disable swizzling and manually append events Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/docsets/SwiftMonkey.docset/Contents/Resources/Documents/index.html Shows how to disable swizzling by passing tapUIApplication: false to MonkeyPaws init, and then how to manually append UIEvent objects to the paws instance. ```swift paws = MonkeyPaws(view: window!, tapUIApplication: false) ``` ```swift paws?.append(event: event) // event is UIEvent ``` -------------------------------- ### addXCTestOrientationAction(weight:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a device rotation event using the private XCTest API. Does not currently work! ```APIDOC ## addXCTestOrientationAction(weight:) ### Description Adds an action that generates a device rotation event using the private XCTest API. Does not currently work! ### Declaration ```swift public func addXCTestOrientationAction(weight: Double) ``` ### Parameters - **weight** (Double) - Required - The relative probability of this event being generated. Can be any value larger than zero. Probabilities will be normalised to the sum of all relative probabilities. ``` -------------------------------- ### addDefaultUIAutomationActions() Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds a sane default set of event generation actions using the private UIAutomation API. ```APIDOC ## addDefaultUIAutomationActions() ### Description Adds a sane default set of event generation actions using the private UIAutomation API. Use this function if you just want to generate some events, and do not have strong requirements on exactly which ones you need. ### Declaration ```swift public func addDefaultUIAutomationActions() ``` ``` -------------------------------- ### addXCTestTapAction(weight:multipleTapProbability:multipleTouchProbability:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a tap, with a possibility for multiple taps with multiple fingers, using the private XCTest API. ```APIDOC ## addXCTestTapAction(weight:multipleTapProbability:multipleTouchProbability:) ### Description Adds an action that generates a tap, with a possibility for multiple taps with multiple fingers, using the private XCTest API. ### Declaration ```swift public func addXCTestTapAction(weight: Double, multipleTapProbability: Double = 0.05, multipleTouchProbability: Double = 0.05) ``` ### Parameters - **weight** (Double) - Required - The relative probability of this event being generated. Can be any value larger than zero. Probabilities will be normalised to the sum of all relative probabilities. - **multipleTapProbability** (Double) - Optional - Probability that the tap event will tap multiple times. Between 0 and 1. Defaults to 0.05. - **multipleTouchProbability** (Double) - Optional - Probability that the tap event will use multiple fingers. Between 0 and 1. Defaults to 0.05. ``` -------------------------------- ### addAction(weight:action:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds a block for generating randomised events with a relative probability weight. ```APIDOC ## addAction(weight:action:) ### Description Add a block for generating randomised events. ### Declaration ```swift public func addAction(weight: Double, action: @escaping (Void) -> Void) ``` ### Parameters - **weight** (Double) - Required - The relative probability of this event being generated. Can be any value larger than zero. Probabilities will be normalised to the sum of all relative probabilities. - **action** (() -> Void) - Required - The block to run when this event is generated. ``` -------------------------------- ### addXCTestPinchCloseAction(weight:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a pinch close gesture at a random screen position using the private XCTest API. ```APIDOC ## addXCTestPinchCloseAction(weight:) ### Description Adds an action that generates a pinch close gesture at a random screen position using the private XCTest API. ### Declaration ```swift public func addXCTestPinchCloseAction(weight: Double) ``` ### Parameters - **weight** (Double) - Required - The relative probability of this event being generated. Can be any value larger than zero. Probabilities will be normalised to the sum of all relative probabilities. ``` -------------------------------- ### addUIAutomationSingleTapAction(weight:) Declaration Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a single tap event using the private UIAutomation API. The weight parameter is the relative probability of this event being generated; it can be any value larger than zero and probabilities are normalised to the sum of all relative probabilities. ```swift public func addUIAutomationSingleTapAction(weight: Double) ``` -------------------------------- ### Add XCTest tap action with multiple tap and touch probabilities Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a tap, with a possibility for multiple taps with multiple fingers, using the private XCTest API. The weight is the relative probability of this event being generated; probabilities are normalized to the sum of all relative probabilities. multipleTapProbability and multipleTouchProbability are between 0 and 1. ```swift public func addXCTestTapAction(weight: Double, multipleTapProbability: Double = 0.05, multipleTouchProbability: Double = 0.05) ``` -------------------------------- ### addUIAutomationOrientationAction(weight:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a device rotation event using the private UIAutomation API. ```APIDOC ## addUIAutomationOrientationAction(weight:) ### Description Adds an action that generates a device rotation event using the private UIAutomation API. ### Method addUIAutomationOrientationAction ### Parameters - **weight** (Double) - Required - The relative probability of this event being generated. Can be any value larger than zero. Probabilities will be normalised to the sum of all relative probabilities. ### Declaration ```swift public func addUIAutomationOrientationAction(weight: Double) ``` ``` -------------------------------- ### randomPoint() Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Generates a random CGPoint inside the frame of the app. ```APIDOC ## randomPoint() ### Description Generate a random `CGPoint` inside the frame of the app. ### Declaration ```swift public func randomPoint() -> CGPoint ``` ### Return Value - (CGPoint) - A random point within the app's frame. ``` -------------------------------- ### addAction(interval:action:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds a block for fixed-interval events. ```APIDOC ## addAction(interval:action:) ### Description Add a block for fixed-interval events. ### Declaration ```swift public func addAction(interval: Int, action: @escaping (Void) -> Void) ``` ### Parameters - **interval** (Int) - Required - How often to generate this event. One of these events will be generated after this many randomised events have been generated. - **action** (() -> Void) - Required - The block to run when this event is generated. ``` -------------------------------- ### randomRect(sizeFraction:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Generates a random CGRect inside the frame of the app, sized to a given fraction of the whole frame. ```APIDOC ## randomRect(sizeFraction:) ### Description Generate a random `CGRect` inside the frame of the app, sized to a given fraction of the whole frame. ### Declaration ```swift public func randomRect(sizeFraction: CGFloat) -> CGRect ``` ### Parameters - **sizeFraction** (CGFloat) - Required - The fraction of the frame size to use for the rectangle. ### Return Value - (CGRect) - A random rectangle within the app's frame with the specified size fraction. ``` -------------------------------- ### addXCTestTapAlertAction(interval:application:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that checks, at a fixed interval, if an alert is being displayed, and if so, selects a random button on it. ```APIDOC ## addXCTestTapAlertAction(interval:application:) ### Description Adds an action that checks, at a fixed interval, if an alert is being displayed, and if so, selects a random button on it. ### Method addXCTestTapAlertAction ### Parameters - **interval** (Int) - Required - How often to generate this event. One of these events will be generated after this many randomised events have been generated. - **application** (XCUIApplication) - Required - The `XCUIApplication` object for the current application. ### Declaration ```swift public func addXCTestTapAlertAction(interval: Int, application: XCUIApplication) ``` ``` -------------------------------- ### addUIAutomationFlickAction(weight:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a flick event from one random screen position to another using the private UIAutomation API. ```APIDOC ## addUIAutomationFlickAction(weight:) ### Description Adds an action that generates a flick event from one random screen position to another using the private UIAutomation API. ### Declaration ```swift public func addUIAutomationFlickAction(weight: Double) ``` ### Parameters - **weight** (Double) - The relative probability of this event being generated. Can be any value larger than zero. Probabilities will be normalised to the sum of all relative probabilities. ``` -------------------------------- ### randomUInt(lessThan:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Generates a random UInt less than the given value. ```APIDOC ## randomUInt(lessThan:) ### Description Generate a random `UInt`. ### Declaration ```swift public func randomUInt(lessThan: UInt) -> UInt ``` ### Parameters - **lessThan** (UInt) - Required - The returned value will be less than this value, and greater than or equal to zero. ### Return Value - (UInt) - A random unsigned integer between 0 and lessThan-1. ``` -------------------------------- ### addUIAutomationFlickAction(weight:) Declaration Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a flick event from one random screen position to another using the private UIAutomation API. The weight parameter is the relative probability of this event being generated; it can be any value larger than zero and probabilities are normalised to the sum of all relative probabilities. ```swift public func addUIAutomationFlickAction(weight: Double) ``` -------------------------------- ### addUIAutomationTapAction(weight:multipleTapProbability:multipleTouchProbability:longPressProbability:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a tap, with a possibility for multiple taps with multiple fingers, or long taps, using the private UIAutomation API. ```APIDOC ## addUIAutomationTapAction(weight:multipleTapProbability:multipleTouchProbability:longPressProbability:) ### Description Adds an action that generates a tap, with a possibility for multiple taps with multiple fingers, or long taps, using the private UIAutomation API. ### Declaration ```swift public func addUIAutomationTapAction(weight: Double, multipleTapProbability: Double = 0.05, multipleTouchProbability: Double = 0.05, longPressProbability: Double = 0.05) ``` ### Parameters - **weight** (Double) - The relative probability of this event being generated. Can be any value larger than zero. Probabilities will be normalised to the sum of all relative probabilities. - **multipleTapProbability** (Double) - Probability that the tap event will tap multiple times. Between 0 and 1. - **multipleTouchProbability** (Double) - Probability that the tap event will use multiple fingers. Between 0 and 1. - **longPressProbability** (Double) - Probability that the tap event will be a long press. Between 0 and 1. ``` -------------------------------- ### Add UIAutomation Click Volume Down Action Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/docsets/SwiftMonkey.docset/Contents/Resources/Documents/Classes/Monkey.html Adds a volume down click event action using the private UIAutomation API. The weight parameter controls the relative probability of this event being generated; probabilities are normalized to the sum of all relative probabilities. ```swift public func addUIAutomationClickVolumeDownAction(weight: Double) ``` -------------------------------- ### Add XCTest Tap Alert Action Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/docsets/SwiftMonkey.docset/Contents/Resources/Documents/Classes/Monkey.html Adds an action that checks at a fixed interval if an alert is displayed and, if so, selects a random button on it. The interval parameter specifies how often to generate this event (after that many randomized events), and the application parameter is the XCUIApplication object for the current application. ```swift public func addXCTestTapAlertAction(interval: Int, application: XCUIApplication) ``` -------------------------------- ### Monkey Class Declaration Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/docsets/SwiftMonkey.docset/Contents/Resources/Documents/Classes.html Declaration of the Monkey class as shown in the documentation. ```swift public class Monkey ``` -------------------------------- ### Add XCTest pinch close action Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a pinch close gesture at a random screen position using the private XCTest API. The weight is the relative probability of this event being generated; probabilities are normalized to the sum of all relative probabilities. ```swift public func addXCTestPinchCloseAction(weight: Double) ``` -------------------------------- ### randomCGFloat(lessThan:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Generates a random CGFloat less than the given value. ```APIDOC ## randomCGFloat(lessThan:) ### Description Generate a random `CGFloat`. ### Declaration ```swift public func randomCGFloat(lessThan: CGFloat = 1) -> CGFloat ``` ### Parameters - **lessThan** (CGFloat) - Optional - The returned value will be less than this value, and greater than or equal to zero. Defaults to 1. ### Return Value - (CGFloat) - A random CGFloat between 0 and lessThan-1 (or lessThan). ``` -------------------------------- ### append(event:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkeyPaws/Documentation/Classes/MonkeyPaws.html Manually provides a UIEvent to MonkeyPaws for visualisation when automatic event tapping is disabled. ```APIDOC ## append(event:) ### Description If you have disabled UIApplication event tapping, use this method to pass in `UIEvent` objects to visualise. ### Declaration ```swift public func append(event: UIEvent) ``` ### Parameters - **event** (UIEvent) - Required - The UIEvent object to visualise. ``` -------------------------------- ### addUIAutomationDragAction(weight:) Declaration Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a drag event from one random screen position to another using the private UIAutomation API. The weight parameter is the relative probability of this event being generated; it can be any value larger than zero and probabilities are normalised to the sum of all relative probabilities. ```swift public func addUIAutomationDragAction(weight: Double) ``` -------------------------------- ### addUIAutomationDragAction(weight:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a drag event from one random screen position to another using the private UIAutomation API. ```APIDOC ## addUIAutomationDragAction(weight:) ### Description Adds an action that generates a drag event from one random screen position to another using the private UIAutomation API. ### Declaration ```swift public func addUIAutomationDragAction(weight: Double) ``` ### Parameters - **weight** (Double) - The relative probability of this event being generated. Can be any value larger than zero. Probabilities will be normalised to the sum of all relative probabilities. ``` -------------------------------- ### Add UIAutomation Orientation Action Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/docsets/SwiftMonkey.docset/Contents/Resources/Documents/Classes/Monkey.html Adds a device rotation event action using the private UIAutomation API. The weight parameter controls the relative probability of this event being generated; probabilities are normalized to the sum of all relative probabilities. ```swift public func addUIAutomationOrientationAction(weight: Double) ``` -------------------------------- ### actRandomly() Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Generates one random event. ```APIDOC ## actRandomly() ### Description Generate one random event. ### Declaration ```swift public func actRandomly() ``` ``` -------------------------------- ### randomPointAvoidingPanelAreas() Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Generates a random CGPoint inside the frame of the app, avoiding the areas at the top and bottom of the screen that trigger a panel pull-out. ```APIDOC ## randomPointAvoidingPanelAreas() ### Description Generate a random `CGPoint` inside the frame of the app, avoiding the areas at the top and bottom of the screen that trigger a panel pull-out. ### Declaration ```swift public func randomPointAvoidingPanelAreas() -> CGPoint ``` ### Return Value - (CGPoint) - A random point within the app's frame, excluding panel areas. ``` -------------------------------- ### addDefaultXCTestPrivateActions() Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds a default set of event generation actions using the private XCTest API. Use this to quickly generate events without specifying individual actions. ```APIDOC ## addDefaultXCTestPrivateActions() ### Description Adds a sane default set of event generation actions using the private XCTest API. Use this function if you just want to generate some events, and do not have strong requirements on exactly which ones you need. ### Declaration ```swift public func addDefaultXCTestPrivateActions() ``` ### Parameters None. ``` -------------------------------- ### addUIAutomationTapAction(weight:multipleTapProbability:multipleTouchProbability:longPressProbability:) Declaration Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a tap, with a possibility for multiple taps with multiple fingers, or long taps, using the private UIAutomation API. The weight parameter is the relative probability of this event being generated; it can be any value larger than zero and probabilities are normalised to the sum of all relative probabilities. The probability parameters for multiple taps, multiple touches, and long press are between 0 and 1. ```swift public func addUIAutomationTapAction(weight: Double, multipleTapProbability: Double = 0.05, multipleTouchProbability: Double = 0.05, longPressProbability: Double = 0.05) ``` -------------------------------- ### Add UIAutomation Shake Action Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/docsets/SwiftMonkey.docset/Contents/Resources/Documents/Classes/Monkey.html Adds a shake event action using the private UIAutomation API. The weight parameter controls the relative probability of this event being generated; probabilities are normalized to the sum of all relative probabilities. ```swift public func addUIAutomationShakeAction(weight: Double) ``` -------------------------------- ### Add XCTest drag action Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a drag event from one random screen position to another using the private XCTest API. The weight is the relative probability of this event being generated; probabilities are normalized to the sum of all relative probabilities. ```swift public func addXCTestDragAction(weight: Double) ``` -------------------------------- ### addUIAutomationRotateAction(weight:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a rotation gesture at a random screen position over a random angle using the private UIAutomation API. ```APIDOC ## addUIAutomationRotateAction(weight:) ### Description Adds an action that generates a rotation gesture at a random screen position over a random angle using the private UIAutomation API. ### Method addUIAutomationRotateAction ### Parameters - **weight** (Double) - Required - The relative probability of this event being generated. Can be any value larger than zero. Probabilities will be normalised to the sum of all relative probabilities. ### Declaration ```swift public func addUIAutomationRotateAction(weight: Double) ``` ``` -------------------------------- ### addXCTestRotateAction(weight:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a rotation gesture at a random screen position over a random angle using the private XCTest API. ```APIDOC ## addXCTestRotateAction(weight:) ### Description Adds an action that generates a rotation gesture at a random screen position over a random angle using the private XCTest API. ### Declaration ```swift public func addXCTestRotateAction(weight: Double) ``` ### Parameters - **weight** (Double) - Required - The relative probability of this event being generated. Can be any value larger than zero. Probabilities will be normalised to the sum of all relative probabilities. ``` -------------------------------- ### addUIAutomationLockAction(weight:) Source: https://github.com/zalando/swiftmonkey/blob/master/SwiftMonkey/Documentation/Classes/Monkey.html Adds an action that generates a lock button click event and subsequent unlock drag event using the private UIAutomation API. ```APIDOC ## addUIAutomationLockAction(weight:) ### Description Adds an action that generates a lock button click event and subsequent unlock drag event using the private UIAutomation API. ### Method addUIAutomationLockAction ### Parameters - **weight** (Double) - Required - The relative probability of this event being generated. Can be any value larger than zero. Probabilities will be normalised to the sum of all relative probabilities. ### Declaration ```swift public func addUIAutomationLockAction(weight: Double) ``` ```