Skip to content

Commit

Permalink
Improve API and bump version.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dag Ågren committed Nov 16, 2016
1 parent 1bc134d commit 456706b
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 7 deletions.
6 changes: 6 additions & 0 deletions Monkey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public class Monkey {
var regularActions: [(interval: Int, action: (Void) -> Void)]
var actionCounter = 0

public convenience init(frame: CGRect) {
let time = Date().timeIntervalSinceReferenceDate
let seed = UInt32(UInt64(time * 1000) & 0xffffffff)
self.init(seed: seed, frame: frame)
}

public init(seed: UInt32, frame: CGRect) {
self.r = Random(seed: seed)
self.frame = frame
Expand Down
16 changes: 15 additions & 1 deletion MonkeyUIAutomation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,21 @@ private let eventGenerator: UIASyntheticEvents = {
}()

extension Monkey {
public func addUIAutomationSingleTapActionWithWeight(weight: Double) {
public func addDefaultUIAutomationActions() {
addUIAutomationTapAction(weight: 50)
addUIAutomationDragAction(weight: 1)
addUIAutomationFlickAction(weight: 1)
addUIAutomationPinchCloseAction(weight: 1)
addUIAutomationPinchOpenAction(weight: 1)
//addUIAutomationRotateAction(weight: 1) // TODO: Investigate why this is broken.
addUIAutomationOrientationAction(weight: 1)
addUIAutomationClickVolumeUpAction(weight: 1)
addUIAutomationClickVolumeDownAction(weight: 1)
addUIAutomationShakeAction(weight: 1)
addUIAutomationLockAction(weight: 1)
}

public func addUIAutomationSingleTapAction(weight: Double) {
addAction(weight: weight) { [weak self] in
eventGenerator.sendTap(self!.randomPoint())
}
Expand Down
2 changes: 1 addition & 1 deletion MonkeyXCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Foundation
import XCTest

extension Monkey {
public func addXCTestTapAlertActionWithInterval(_ interval: Int, application: XCUIApplication) {
public func addXCTestTapAlertAction(interval: Int, application: XCUIApplication) {
addAction(interval: interval) { [weak self] in
// The test for alerts on screen and dismiss them if there are any.
for i in 0 ..< application.alerts.count {
Expand Down
12 changes: 11 additions & 1 deletion MonkeyXCTestPrivate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@ import XCTest
var orientationValue: UIDeviceOrientation = .portrait

extension Monkey {
var sharedXCEventGenerator: XCEventGenerator {
private var sharedXCEventGenerator: XCEventGenerator {
let generatorClass = unsafeBitCast(NSClassFromString("XCEventGenerator"),to: XCEventGenerator.Type.self)
return generatorClass.sharedGenerator()
}

public func addDefaultXCTestPrivateActions() {
addXCTestTapAction(weight: 25)
addXCTestLongPressAction(weight: 1)
addXCTestDragAction(weight: 1)
addXCTestPinchCloseAction(weight: 1)
addXCTestPinchOpenAction(weight: 1)
addXCTestRotateAction(weight: 1)
//addXCTestOrientationAction(weight: 1) // TODO: Investigate why this does not work.
}

public func addXCTestTapAction(weight: Double, multipleTapProbability: Double = 0.05,
multipleTouchProbability: Double = 0.05) {
addAction(weight: weight) { [weak self] in
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ To be written.
- Find clickable view and click them directly instead of
clicking random locations, to compensate for the slow
event generation.
- Try to stabilise the event generation code.
- Re-investigate private XCTest APIs.
- Once Swift Package Manager has iOS support, update project
to support it properly.

Expand Down
2 changes: 1 addition & 1 deletion SwiftMonkey.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SwiftMonkey"
s.version = "0.0.3"
s.version = "0.1.0"
s.summary = "Monkey testing framework for iOS apps"
s.description = <<-DESC
A framework for generating randomised user
Expand Down
2 changes: 1 addition & 1 deletion SwiftMonkey.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@
isa = PBXGroup;
children = (
OBJ_9 /* Monkey.swift */,
OBJ_10 /* MonkeyUIAutomation.swift */,
OBJ_11 /* MonkeyXCTest.swift */,
OBJ_12 /* MonkeyXCTestPrivate.swift */,
OBJ_10 /* MonkeyUIAutomation.swift */,
OBJ_13 /* Random.swift */,
);
name = SwiftMonkey;
Expand Down

0 comments on commit 456706b

Please sign in to comment.