Skip to content

Commit

Permalink
Minor teaks
Browse files Browse the repository at this point in the history
  • Loading branch information
eonist committed Oct 19, 2024
1 parent 1f7e45c commit b2093ca
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 38 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ runner.iterate() // 🏃


### Todo:
- Add example project (See TabNav-project, playlist-project, UITesting-project) 👈👈👈
- Add example project (See TabNav-project, playlist-project, UITesting-project, or make a new one) 👈👈👈
- Maybe add ideas from AccessRunner project, might have advanced ways of doing things etc 👈
- Maybe use semaphore to make async -> sync ? 👈
- Create a test project in SwiftUI
- Error Handling and Logging in Scene Execution
The Scene class's run method currently uses a placeholder implementation that simply throws a fatal error if not overridden. This could be improved by adding error handling capabilities, which would allow for better debugging and error logging.
- SwiftUI Migration: The AppDelegate in the TestRunnerApp uses UIKit and has a comment suggesting migration to SwiftUI. This could improve maintainability and modernize the codebase.
- Testing Enhancements: The SceneRunner class could include more robust testing features, such as support for launch options to customize the app's launch configuration. This would allow for more flexible and comprehensive testing scenarios.
- SwiftLint Integration: The GitHub Actions workflow mentions an issue with SwiftLint integration. Addressing this could help maintain code quality and consistency across the project.
- UI Testing Enhancements: The UI tests could be expanded to cover more scenarios and utilize the capabilities of UITestSugar more effectively. This would ensure that the UI components work as expected under various conditions.
22 changes: 18 additions & 4 deletions Sources/TestRunner/Scene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,30 @@ open class Scene: SceneKind {
public var sceneRunner: SceneRunnerKind
/**
* Initializes a new instance of the Scene class.
* - Description: This initializer is used to create an instance of the Scene class. It takes a SceneRunnerKind instance as a parameter, which is responsible for managing the sequence and execution of scenes. This linkage allows for a coordinated progression through a series of scenes.
* - Parameter sceneRunner: A reference to the SceneRunnerKind instance that manages the sequence and execution of scenes. This parameter is crucial as it links the scene with its controlling runner, enabling coordinated progression through a series of scenes.
* - Description: This initializer is used to create an instance of the
* Scene class. It takes a SceneRunnerKind instance as a
* parameter, which is responsible for managing the sequence
* and execution of scenes. This linkage allows for a
* coordinated progression through a series of scenes.
* - Parameter sceneRunner: A reference to the SceneRunnerKind instance that
* manages the sequence and execution of scenes.
* This parameter is crucial as it links the scene
* with its controlling runner, enabling coordinated
* progression through a series of scenes.
*/
public required init(sceneRunner: SceneRunnerKind) {
self.sceneRunner = sceneRunner // Assigning the sceneRunner parameter to the sceneRunner property of the Scene instance.
}
/**
* This is a method to run the scene.
* - Description: This method is responsible for initiating the execution of the scene. It is called by the SceneRunner during the iteration process. The specific actions performed during the execution of this method are defined by the individual scene implementation.
* - Fixme: ⚠️️ Maybe add throws? so we can log errors etc? This is a note suggesting that the method could be updated to throw errors, which would allow for better error handling and logging.
* - Description: This method is responsible for initiating the execution
* of the scene. It is called by the SceneRunner during the
* iteration process. The specific actions performed during
* the execution of this method are defined by the individual
* scene implementation.
* - Fixme: ⚠️️ Maybe add throws? so we can log errors etc? This is a note
* suggesting that the method could be updated to throw errors,
* which would allow for better error handling and logging.
*/
open func run() {
// This is a placeholder implementation of the run method.
Expand Down
20 changes: 16 additions & 4 deletions Sources/TestRunner/SceneRunner+Action.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ import Foundation
extension SceneRunner {
/**
* Initiates the process of iterating over the scenes.
* - Description: This method initiates the iteration over the collection of scenes. It continues to iterate until all scenes have been processed. The iteration is recursive; for each scene, it initializes and executes the scene, and if there are no more scenes left, it triggers the completion handler to indicate that the iteration is complete.
* - Remark: Utilizes recursion to manage the iteration of scenes. Each scene is initialized and executed in sequence.
* - Remark: Upon completion of all scenes, the `complete` method is invoked to signify the end of the scene processing.
* - Description: This method initiates the iteration over the collection
* of scenes. It continues to iterate until all scenes have
* been processed. The iteration is recursive; for each scene,
* it initializes and executes the scene, and if there are no
* more scenes left, it triggers the completion handler to
* indicate that the iteration is complete.
* - Remark: Utilizes recursion to manage the iteration of scenes. Each
* scene is initialized and executed in sequence.
* - Remark: Upon completion of all scenes, the `complete` method is
* invoked to signify the end of the scene processing.
*/
public func iterate() {
// Check if there is a next scene
Expand All @@ -22,7 +29,12 @@ extension SceneRunner {
}
/**
* Executes the run method of a given scene.
* - Description: This method is responsible for executing the run method of the scene passed to it. It is a crucial part of the scene iteration process in the `iterate` method, where it is invoked for each scene in the sequence. This ensures that each scene is run in the order they appear in the sequence.
* - Description: This method is responsible for executing the run method
* of the scene passed to it. It is a crucial part of the
* scene iteration process in the `iterate` method, where it
* is invoked for each scene in the sequence. This ensures
* that each scene is run in the order they appear in the
* sequence.
* - Parameters:
* - scene: The scene to be executed, conforming to the `SceneKind` protocol.
*/
Expand Down
21 changes: 17 additions & 4 deletions Sources/TestRunner/SceneRunner+Create.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,23 @@ import XCTest
extension SceneRunner {
/**
* Creates a single reference to the `XCUIApplication`, essential for consistent application state during tests.
* - Abstract: This method initializes the `XCUIApplication` and stores it in the `app` property. This approach prevents the creation of multiple instances during tests, ensuring that all test actions and verifications are performed on the same application instance.
* - Description: This method is responsible for creating and launching an instance of `XCUIApplication`. It ensures that only a single instance of the application is created and used throughout the testing process, providing a consistent application state for accurate testing results.
* - Remark: Instantiating `XCUIApplication` directly creates a new application instance each time. To maintain test consistency, it is initialized once and reused throughout the testing process.
* - Remark: This method also allows for the interaction with other applications by using their specific bundle identifiers. For instance, the SpringBoard application can be accessed with `XCUIApplication(bundleIdentifier: "com.apple.springboard")`, facilitating tests that involve multiple applications.
* - Abstract: This method initializes the `XCUIApplication` and stores it
* in the `app` property. This approach prevents the creation of
* multiple instances during tests, ensuring that all test actions
* and verifications are performed on the same application instance.
* - Description: This method is responsible for creating and launching an
* instance of `XCUIApplication`. It ensures that only a single
* instance of the application is created and used throughout
* the testing process, providing a consistent application state
* for accurate testing results.
* - Remark: Instantiating `XCUIApplication` directly creates a new application
* instance each time. To maintain test consistency, it is initialized
* once and reused throughout the testing process.
* - Remark: This method also allows for the interaction with other applications
* by using their specific bundle identifiers. For instance, the
* SpringBoard application can be accessed with `XCUIApplication(bundleIdentifier:
* "com.apple.springboard")`, facilitating tests that involve multiple
* applications.
*/
@objc open func createXCUIApp() -> XCUIApplication {
let app: XCUIApplication = .init() // Creates a new instance of XCUIApplication
Expand Down
10 changes: 8 additions & 2 deletions Sources/TestRunner/SceneRunner+Type.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ import Foundation
extension SceneRunner {
/**
* `Completed` Typealias
* - Description: This typealias is used to define a callback function signature for completion events in the `SceneRunner` class. It specifies a function that is invoked when a sequence of scenes has been fully processed and completed.
* - Details: The function defined by this typealias takes no parameters and does not return a value. It is typically used to perform cleanup, logging, or update UI elements upon the completion of scene sequences.
* - Description: This typealias is used to define a callback function
* signature for completion events in the `SceneRunner` class.
* It specifies a function that is invoked when a sequence of
* scenes has been fully processed and completed.
* - Details: The function defined by this typealias takes no parameters
* and does not return a value. It is typically used to perform
* cleanup, logging, or update UI elements upon the completion
* of scene sequences.
* - Usage:
* ```
* let completion: SceneRunner.Completed = {
Expand Down
54 changes: 42 additions & 12 deletions Sources/TestRunner/SceneRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,72 @@ import Iterator
import XCTest
/**
* `SceneRunner` is a class that "plays" through scenes like a playlist.
* - Description: `SceneRunner` is a utility class that sequentially executes a series of scenes, which are types conforming to `SceneKind`. It can be used to simulate a sequence of events or actions in an application, making it a useful tool for automated testing or demoing purposes.
* - Note: It is a subclass of `ArrayIterator` with `SceneKind.Type` as the generic parameter.
* - Description: `SceneRunner` is a utility class that sequentially
* executes a series of scenes, which are types conforming to
* `SceneKind`. It can be used to simulate a sequence of events
* or actions in an application, making it a useful tool for
* automated testing or demoing purposes.
* - Note: It is a subclass of `ArrayIterator` with `SceneKind.Type` as the
* generic parameter.
* - Note: It also conforms to `SceneRunnerKind` protocol.
* ## Examples:
* SceneRunner(scenes: [LoginScene.self, LogoutScene.self]) { Swift.print("All scenes completed 🏁") }.iterate(callBack: { _,_ in })
*/
open class SceneRunner: ArrayIterator<SceneKind.Type>, SceneRunnerKind {
/**
* Convenient accessor to the app
* - Description: This is a lazy property that creates and returns an instance of `XCUIApplication`. This instance is used to interact with the application's user interface for testing purposes.
* - Description: This is a lazy property that creates and returns an
* instance of `XCUIApplication`. This instance is used to
* interact with the application's user interface for testing
* purposes.
*/
public lazy var app: XCUIApplication = createXCUIApp()
/**
* Stores the scenes in the sequence
* - Description: An array of `SceneKind.Type` that represents the sequence of scenes to be executed by the `SceneRunner`.
* - Description: An array of `SceneKind.Type` that represents the
* sequence of scenes to be executed by the `SceneRunner`.
*/
public var scenes: [SceneKind.Type] { collection }
/**
* Optional XCTestCase instance
* - Description: An optional reference to an `XCTestCase` instance that allows the `SceneRunner` to integrate with XCTest for additional testing functionalities, such as performance testing or asserting conditions.
* - Description: An optional reference to an `XCTestCase` instance that
* allows the `SceneRunner` to integrate with XCTest for
* additional testing functionalities, such as performance
* testing or asserting conditions.
*/
public var testCase: XCTestCase?
/**
* A callback that notifies the user when the sequence has completed
* - Description: This is a callback function that is triggered when the sequence of scenes has been fully executed. It allows for any necessary cleanup or follow-up actions to be performed after the sequence has completed.
* - Description: This is a callback function that is triggered when the
* sequence of scenes has been fully executed. It allows for
* any necessary cleanup or follow-up actions to be performed
* after the sequence has completed.
*/
public var complete: Completed
/**
* Initializes the scene-runner with a sequence of scenes, an optional test case, and a completion handler.
* - Abstract: This initializer sets up the scene-runner to execute a series of scenes, which are types conforming to `SceneKind`. It optionally accepts a test case for integrating with XCTest functionalities. The completion handler is called once all scenes have been processed.
* - Description: This initializer is used to create an instance of SceneRunner. It takes a sequence of scenes, an optional test case, and a completion handler as parameters. The sequence of scenes is an array of types conforming to `SceneKind` which represents the scenes to be executed. The optional test case can be used for additional testing capabilities during scene execution. The completion handler is invoked when all scenes in the sequence have been completed.
* - Fixme: ⚠️️ Consider adding support for launch options to customize the app's launch configuration.
* - Abstract: This initializer sets up the scene-runner to execute a series
* of scenes, which are types conforming to `SceneKind`. It
* optionally accepts a test case for integrating with XCTest
* functionalities. The completion handler is called once all
* scenes have been processed.
* - Description: This initializer is used to create an instance of
* SceneRunner. It takes a sequence of scenes, an optional test
* case, and a completion handler as parameters. The sequence
* of scenes is an array of types conforming to `SceneKind`
* which represents the scenes to be executed. The optional
* test case can be used for additional testing capabilities
* during scene execution. The completion handler is invoked
* when all scenes in the sequence have been completed.
* - Fixme: ⚠️️ Consider adding support for launch options to customize the
* app's launch configuration.
* - Parameters:
* - sequence: An array of `SceneKind.Type` representing the scenes to be executed.
* - onComplete: A callback that is invoked when all scenes in the sequence have been completed.
* - testCase: An optional `XCTestCase` instance that can be used for additional testing capabilities during scene execution.
* - sequence: An array of `SceneKind.Type` representing the scenes
* to be executed.
* - onComplete: A callback that is invoked when all scenes in the
* sequence have been completed.
* - testCase: An optional `XCTestCase` instance that can be used for
* additional testing capabilities during scene execution.
*/
@discardableResult
public init(sequence: [SceneKind.Type], testCase: XCTestCase? = nil, onComplete: @escaping Completed) { /*, launchArgs: [String] = [], launchEnvironment: [String: String] = [:]*/
Expand Down
10 changes: 8 additions & 2 deletions Sources/TestRunner/protocol/SceneKind+Getter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ import XCTest
extension SceneKind {
/**
* The `app` computed property returns the `XCUIApplication` instance associated with the `sceneRunner`
* - Description: Provides a convenient way to access the `XCUIApplication` instance
* - Note: The `SceneKind` protocol can be utilized in various testing scenarios. For instance, it can be used to simulate user interactions in a UI test or to verify the state of the app at different stages of the scene lifecycle. This flexibility allows developers to create comprehensive test suites that cover a wide range of user experiences.
* - Description: Provides a convenient way to access the `XCUIApplication`
* instance
* - Note: The `SceneKind` protocol can be utilized in various testing
* scenarios. For instance, it can be used to simulate user
* interactions in a UI test or to verify the state of the app at
* different stages of the scene lifecycle. This flexibility allows
* developers to create comprehensive test suites that cover a wide
* range of user experiences.
*/
public var app: XCUIApplication {
sceneRunner.app
Expand Down
Loading

0 comments on commit b2093ca

Please sign in to comment.