1
0
mirror of https://github.com/nicoverbruggen/phpmon.git synced 2025-08-07 03:50:08 +02:00

️ Sped up and improved UI test

This commit is contained in:
2022-10-15 16:37:33 +02:00
parent cb3208c008
commit 273070ef27
4 changed files with 91 additions and 45 deletions

View File

@ -0,0 +1,53 @@
//
// UI_Tests.swift
// UI Tests
//
// Created by Nico Verbruggen on 14/10/2022.
// Copyright © 2022 Nico Verbruggen. All rights reserved.
//
import XCTest
final class StartupTest: UITestCase {
override func setUpWithError() throws {
continueAfterFailure = false
}
override func tearDownWithError() throws {}
func testApplicationCanLaunchWithTestConfigurationAndIdles() throws {
let app = XCUIApplication()
app.launchArguments = ["--configuration:working"]
app.launch()
}
func testApplicationCanLaunchWithTestConfigurationAndThrowsAlert() throws {
let app = XCUIApplication()
app.launchArguments = ["--configuration:broken"]
app.launch()
// Dialog 1: "PHP is not correctly installed"
assertAllExist([
app.dialogs["Notice"],
app.staticTexts["PHP is not correctly installed"],
app.buttons["OK"],
])
click(app.buttons["OK"])
// Dialog 2: PHP Monitor failed to start
assertAllExist([
app.dialogs["Notice"],
app.staticTexts["PHP Monitor cannot start due to a problem with your system configuration"],
app.buttons["Retry"],
app.buttons["Quit"]
])
click(app.buttons["Retry"])
// Dialog 1 again
assertExists(app.staticTexts["PHP is not correctly installed"])
// At this point, we can terminate the test
app.terminate()
}
}

30
tests/ui/UITestCase.swift Normal file
View File

@ -0,0 +1,30 @@
//
// UITestCase.swift
// UI Tests
//
// Created by Nico Verbruggen on 15/10/2022.
// Copyright © 2022 Nico Verbruggen. All rights reserved.
//
import XCTest
class UITestCase: XCTestCase {
/** Checks if a single element exists. */
public func assertExists(_ element: XCUIElement, _ timeout: TimeInterval = 0.05) {
XCTAssert(element.waitForExistence(timeout: timeout))
}
/** Checks if all elements exist. */
public func assertAllExist(_ elements: [XCUIElement], _ timeout: TimeInterval = 0.05) {
for element in elements {
XCTAssert(element.waitForExistence(timeout: timeout))
}
}
/** Clicks on a given element. */
public func click(_ element: XCUIElement) {
element.click()
}
}

View File

@ -1,41 +0,0 @@
//
// UI_Tests.swift
// UI Tests
//
// Created by Nico Verbruggen on 14/10/2022.
// Copyright © 2022 Nico Verbruggen. All rights reserved.
//
import XCTest
final class UI_Tests: XCTestCase {
override func setUpWithError() throws {
continueAfterFailure = false
}
override func tearDownWithError() throws {}
func testApplicationCanLaunchWithTestConfigurationAndIdles() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launchArguments = ["--configuration:working"]
app.launch()
// XCTAssert(app.dialogs["Notice"].waitForExistence(timeout: 5))
sleep(10)
}
func testApplicationCanLaunchWithTestConfigurationAndThrowsAlert() throws {
// UI tests must launch the application that they test.
let app = XCUIApplication()
app.launchArguments = ["--configuration:broken"]
app.launch()
XCTAssert(app.dialogs["Notice"].waitForExistence(timeout: 5))
app.buttons["OK"].click()
XCTAssert(app.dialogs["Notice"].waitForExistence(timeout: 5))
XCTAssert(app.buttons["Quit"].waitForExistence(timeout: 1))
// If this UI test presses the "Quit" button, the test takes forever
// because Xcode will attempt to figure out if the app closed correctly.
app.terminate()
}
}