-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PAI-97 Add "Application Is Running Inside a UI Test Environment"
- Loading branch information
Bartosz Janda
committed
Jun 29, 2017
1 parent
6574184
commit 61d5d8a
Showing
39 changed files
with
995 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// | ||
// IsInUITestHandler.swift | ||
// AutoMate-AppBuddy | ||
// | ||
// Created by Bartosz Janda (PGS Software) on 29.06.2017. | ||
// Copyright © 2017 PGS Software. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
// MARK: - IsInUITestHandler | ||
/// Provides information whether the application is running under UI test environment. | ||
/// | ||
/// Handler should be added to `LaunchEnvironmentManager`. | ||
/// | ||
/// Used key: `AM_IS_IN_UI_TEST` / `AutoMateLaunchOptionKey.isInUITest`. | ||
/// | ||
/// Supported values (case insensitive): | ||
/// | ||
/// - `true` | ||
/// - `yes` | ||
/// - `1` | ||
/// - `false` | ||
/// - `no` | ||
/// - `0` | ||
/// | ||
/// **Example:** | ||
/// | ||
/// ```swift | ||
/// let launchManager = LaunchEnvironmentManager() | ||
/// let isInUITest = IsInUITestHandler() | ||
/// launchManager.add(handler: isInUITest, for: .isInUITest) | ||
/// launchManager.setup() | ||
/// ``` | ||
/// | ||
/// Later in the code, you can check whether the application is running in UI test environment, by using below example: | ||
/// | ||
/// **Example:** | ||
/// | ||
/// ```swift | ||
/// if isInUITest.inUITest { | ||
/// ... | ||
/// } | ||
/// ``` | ||
/// | ||
/// - note: | ||
/// `defaultIsInUITestHandler` singleton could be used intead of creating new instance of the `IsInUITestHandler`. | ||
/// | ||
/// - note: | ||
/// Launch environment for the handler can be set by the `IsInUITestLaunchEnvironment` | ||
/// from the [AutoMate](https://github.com/PGSSoft/AutoMate) project. | ||
/// | ||
/// - note: | ||
/// `IsInUITestHandler` should be used with the `AM_IS_IN_UI_TEST` key, but its implementation doesn't require to use it. | ||
/// Any key provided to the `LaunchEnvironmentManager.add(handler:for:)` method will be handled correctly. | ||
/// | ||
/// - seealso: `LaunchEnvironmentManager` | ||
/// - seealso: `defaultIsInUITestHandler` | ||
public class IsInUITestHandler: Handler { | ||
|
||
// MARK: Properties | ||
/// Indicates whether the application is running in UI test environment. | ||
private(set) public var inUITest: Bool = false | ||
|
||
// MARK: Initialization | ||
/// Initialize `IsInUITestHandler`. | ||
public init() { } | ||
|
||
// MARK: Handler | ||
/// Handles value for the `AM_IS_IN_UI_TEST` key and provides information whether the application was run in the UI test environment. | ||
/// | ||
/// - note: | ||
/// `IsInUITestHandler` should be used with the `AM_IS_IN_UI_TEST` key, but its implementation doesn't require to use it. | ||
/// Any key provided to the `LaunchEnvironmentManager.add(handler:for:)` method will be handled correctly. | ||
/// | ||
/// - requires: | ||
/// Method support only given set of values (case insensitive): | ||
/// | ||
/// - `true` | ||
/// - `yes` | ||
/// - `1` | ||
/// - `false` | ||
/// - `no` | ||
/// - `0` | ||
/// | ||
/// - Parameters: | ||
/// - key: `AM_IS_IN_UI_TEST` / `AutoMateLaunchOptionKey.isInUITest` | ||
/// - value: Value for the `key`. | ||
public func handle(key: String, value: String) { | ||
guard let inUITest = value.boolValue else { | ||
assertionFailure("Cannot convert value for key \"\(key)\" to Bool") | ||
return | ||
} | ||
|
||
self.inUITest = inUITest | ||
} | ||
} | ||
|
||
// MARK: - Default IsInUITestHandler | ||
/// Default `IsInUITestHandler` instance. Singleton which will store information whether the application is running in UI test environment. | ||
/// | ||
/// **Example:** | ||
/// ```swift | ||
/// let launchManager = LaunchEnvironmentManager() | ||
/// launchManager.add(handler: defaultIsInUITestHandler, for: .isInUITest) | ||
/// launchManager.setup() | ||
/// ``` | ||
/// | ||
/// - seealso: `IsInUITestHandler` | ||
public let defaultIsInUITestHandler = IsInUITestHandler() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
AutoMate-AppBuddyTests/Test Cases/IsInUITestHandlerTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// IsInUITestHandlerTests.swift | ||
// AutoMate-AppBuddy | ||
// | ||
// Created by Bartosz Janda (PGS Software) on 29.06.2017. | ||
// Copyright © 2017 PGS Software. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
import AutoMate_AppBuddy | ||
|
||
class IsInUITestHandlerTests: XCTestCase { | ||
|
||
// MARK: Properties | ||
var isInUITestHandler: IsInUITestHandler! | ||
|
||
// MARK: Setup | ||
override func setUp() { | ||
super.setUp() | ||
isInUITestHandler = IsInUITestHandler() | ||
UIView.setAnimationsEnabled(true) | ||
} | ||
|
||
override func tearDown() { | ||
UIView.setAnimationsEnabled(true) | ||
super.tearDown() | ||
} | ||
|
||
// MARK: Tests | ||
func testInUiTest() { | ||
isInUITestHandler.handle(key: AutoMateLaunchOptionKey.isInUITest.rawValue, value: "true") | ||
XCTAssertTrue(isInUITestHandler.inUITest) | ||
} | ||
|
||
func testNotInUiTest() { | ||
isInUITestHandler.handle(key: AutoMateLaunchOptionKey.isInUITest.rawValue, value: "false") | ||
XCTAssertFalse(isInUITestHandler.inUITest) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.