Skip to content

Commit

Permalink
Merge pull request zalando#1 from zalando/master
Browse files Browse the repository at this point in the history
Merge current state.
  • Loading branch information
DwayneCoussement authored Sep 5, 2018
2 parents dbde004 + d5cf644 commit 05eb65c
Show file tree
Hide file tree
Showing 14 changed files with 429 additions and 72 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ specific command line flag is used.

### Requirements

SwiftMonkey uses Swift 3.0. It has no dependencies other than
SwiftMonkey uses Swift 4.0. It has no dependencies other than
iOS itself (8.0 and up should work). SwiftMonkeyPaws doesn't
have any dependencies, either; you can even use on its own,
without SwiftMonkey.
Expand Down
3 changes: 2 additions & 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 = "1.1.0"
s.version = "2.1.0"
s.summary = "Monkey testing framework for iOS apps"
s.description = <<-DESC
A framework for generating randomised user
Expand All @@ -17,4 +17,5 @@ Pod::Spec.new do |s|
s.source_files = "SwiftMonkey/*.swift"
s.exclude_files = "SwiftMonkey/Package.swift"
s.framework = "XCTest"
s.pod_target_xcconfig = { 'ENABLE_BITCODE' => 'NO' }
end
39 changes: 33 additions & 6 deletions SwiftMonkey/Monkey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import UIKit
import XCTest

/**
A general-purpose class for implementing randomised
Expand Down Expand Up @@ -59,13 +60,15 @@ import UIKit
```
*/
public class Monkey {
public typealias ActionClosure = () -> Void

var r: Random
let frame: CGRect

var randomActions: [(accumulatedWeight: Double, action: () -> Void)]
var randomActions: [(accumulatedWeight: Double, action: ActionClosure)]
var totalWeight: Double

var regularActions: [(interval: Int, action: () -> Void)]
var regularActions: [(interval: Int, action: ActionClosure)]
var actionCounter = 0

/**
Expand Down Expand Up @@ -191,9 +194,9 @@ public class Monkey {
- parameter action: The block to run when this event
is generated.
*/
public func addAction(weight: Double, action: @escaping () -> Void) {
public func addAction(weight: Double, action: @escaping ActionClosure) {
totalWeight += weight
randomActions.append((accumulatedWeight: totalWeight, action: action))
randomActions.append((accumulatedWeight: totalWeight, action: actInForeground(action)))
}

/**
Expand All @@ -205,8 +208,32 @@ public class Monkey {
- parameter action: The block to run when this event
is generated.
*/
public func addAction(interval: Int, action: @escaping () -> Void) {
regularActions.append((interval: interval, action: action))
public func addAction(interval: Int, action: @escaping ActionClosure) {
regularActions.append((interval: interval, action: actInForeground(action)))
}

/**
Wrap your action with this function to make sure your actions are dispatched inside the app under test
and not in some other app that the Monkey randomly opened.
*/
func actInForeground(_ action: @escaping ActionClosure) -> ActionClosure {
return {
guard #available(iOS 9.0, *) else {
action()
return
}
let closure: ActionClosure = {
if XCUIApplication().state != .runningForeground {
XCUIApplication().activate()
}
action()
}
if Thread.isMainThread {
closure()
} else {
DispatchQueue.main.async(execute: closure)
}
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion SwiftMonkey/MonkeyXCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extension Monkey {
let alert = application.alerts.element(boundBy: i)
let buttons = alert.descendants(matching: .button)
XCTAssertNotEqual(buttons.count, 0, "No buttons in alert")
let index = UInt(self!.r.randomUInt32() % UInt32(buttons.count))
let index = self!.r.randomInt(lessThan: buttons.count)
let button = buttons.element(boundBy: index)
button.tap()
}
Expand Down
4 changes: 2 additions & 2 deletions SwiftMonkey/SwiftMonkey.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TARGET_NAME = SwiftMonkey;
};
name = Debug;
Expand All @@ -198,7 +198,7 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TARGET_NAME = SwiftMonkey;
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0920"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "OBJ_17"
BuildableName = "SwiftMonkey.framework"
BlueprintName = "SwiftMonkey"
ReferencedContainer = "container:SwiftMonkey.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "OBJ_17"
BuildableName = "SwiftMonkey.framework"
BlueprintName = "SwiftMonkey"
ReferencedContainer = "container:SwiftMonkey.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "OBJ_17"
BuildableName = "SwiftMonkey.framework"
BlueprintName = "SwiftMonkey"
ReferencedContainer = "container:SwiftMonkey.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
27 changes: 22 additions & 5 deletions SwiftMonkeyExample/SwiftMonkeyExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,13 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0810;
LastUpgradeCheck = 0810;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = "Zalando SE";
TargetAttributes = {
C929B5301DD0A764004B256F = {
CreatedOnToolsVersion = 8.1;
DevelopmentTeam = 9LW237982J;
LastSwiftMigration = 0900;
ProvisioningStyle = Automatic;
};
C929B5461DD0A764004B256F = {
Expand Down Expand Up @@ -386,15 +387,22 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -436,15 +444,22 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -483,7 +498,8 @@
PRODUCT_BUNDLE_IDENTIFIER = org.zalando.SwiftMonkeyExample;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -500,7 +516,8 @@
PRODUCT_BUNDLE_IDENTIFIER = org.zalando.SwiftMonkeyExample;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -513,7 +530,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = org.zalando.SwiftMonkeyExampleUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TEST_TARGET_NAME = SwiftMonkeyExample;
};
name = Debug;
Expand All @@ -527,7 +544,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = org.zalando.SwiftMonkeyExampleUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TEST_TARGET_NAME = SwiftMonkeyExample;
};
name = Release;
Expand Down
2 changes: 1 addition & 1 deletion SwiftMonkeyPaws.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SwiftMonkeyPaws"
s.version = "1.0.1"
s.version = "2.1.0"
s.summary = "Visualisation of input events, especially useful during UI testing."
s.description = <<-DESC
Visualise all touch events in a layer on top of
Expand Down
59 changes: 59 additions & 0 deletions SwiftMonkeyPaws/Configuration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// Configuration.swift
// SwiftMonkeyPaws
//
// Created by Daniel.Metzing on 11.02.18.
//

import UIKit

public struct Configuration {
// Customise the appearance of the paws
public struct Paws {

/// Define the colour of the Paws
///
/// - randomized: random colour for each paw
/// - constant: same colour for the paws
public enum Color {
case randomized
case constant(UIColor)
}
// Colour of the paws
public let color: Color

// Brightness of a particular paw
public let brightness: CGFloat

// Maximum visible paws at one time
public let maxShown: Int

public init(colour: Color = .randomized, brightness: CGFloat = 0.5, maxShown: Int = 15) {
self.color = colour
self.brightness = brightness
self.maxShown = maxShown
}
}

public struct Radius {

/// Radius of the cross draw upon canceling a touch event
public let cross: CGFloat

/// Radius of the circle draw upon ending a touch event
public let circle: CGFloat

public init(cross: CGFloat = 7, circle: CGFloat = 7) {
self.cross = cross
self.circle = circle
}
}

public let paws: Paws
public let radius: Radius

public init(paws: Paws = Paws(), radius: Radius = Radius()) {
self.paws = paws
self.radius = radius
}
}
Loading

0 comments on commit 05eb65c

Please sign in to comment.