Skip to content
This repository has been archived by the owner on Dec 5, 2022. It is now read-only.

Is there a way to get monkeyAround function to have scrolling as one of its generic actions? #74

Open
ldasilvaNZ11 opened this issue Feb 19, 2019 · 0 comments

Comments

@ldasilvaNZ11
Copy link

ldasilvaNZ11 commented Feb 19, 2019

I noticed Monkey seems to always tap on the very first element of my screen. Is there a way to get it to scroll down randomly so that it won't always tap on the same element of my screen?

func monkeyAround(_ iterationsToMonkey: Int) {
bringAppToForeground()
// Rotate back to Portrait, to avoid Plus size iPhone locking issues
XCUIDevice.shared.orientation = UIDeviceOrientation.portrait
// Sleep while the animation completes
sleep(1)

    // Now we setup the Monkey, to tap objects randomly, and - if an alert displays - tap a random button on any alert that pops-up
    _ = app.descendants(matching: .any).element(boundBy: 0).frame
    let monkey = Monkey(frame: app.frame)
    //monkey.addDefaultXCTestPrivateActions()
    monkey.addXCTestTapAlertAction(interval: 100, application: app)
    monkey.addUIAutomationShakeAction(weight: 3)
    monkey.addUIAutomationLockAction(weight: 2)
    //monkey.addUIAutomationClickVolumeDownAction(weight: 5)
    monkey.addUIAutomationTapAction(weight: Double(arc4random_uniform(UInt32(80) - UInt32(60)) + UInt32(60)))
    monkey.addUIAutomationDragAction(weight: 4)
    monkey.addUIAutomationFlickAction(weight: 2)
    
    // Begin taking a screenshot each second, until timer is stopped below with stopTimer()
    // If persistScreenshotsOnSuccess = true, then we'll save the values of the screenshots even if the test passes
    // If persistScreenshotsOnSuccess = false, then we'll only save the values of the screenshots if the tests fail. Otherwise, we'll ditch the screenshots
    startTimerToTakeScreenshots()
    
    // Don't set this much lower than 10, as sometimes it can't escape what's already on-screen
    monkey.monkeyAround(iterations: iterationsToMonkey)
    
    // Stop the timer, then ensure the app is foregrounded again, just in case it's gone off to Safari or the home screen
    stopTimer()
    bringAppToForeground()
}

Cheers,
Lucas

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant