iOS UI 测试:如何查看日历中的约会?

iOS UI Test: How can I check an appointment in the calendar?

我正在 运行 UI 测试Xcode,在 iPad 上使用 XCTest。此测试中的操作导致在 iOS 的标准日历应用程序中设置约会。日期将始终与测试日期相同 运行.

如果日历应用程序中的日期设置正确,是否有办法检查相同的测试功能?

使用 Xcode 9,您现在可以访问 UITest 中的其他应用程序。因此,要测试事件是否已正确添加到日历中,您可以编写一个简单的测试:

(我为此使用了一个小型演示应用程序。它只有一个按钮 "Add Event",用于添加当天早上 5 点到早上 7 点的事件)

import XCTest

class CalendarUITestDemoUITests: XCTestCase {

    override func setUp() {
        super.setUp()
        continueAfterFailure = false
    }

    func testIfEventIsAddedToCalendar() {
        let app = XCUIApplication()
        let calendarApp = XCUIApplication(bundleIdentifier: "com.apple.mobilecal")

        app.launch()

        // add event
        app.buttons["Add Event"].tap()

        // check if event is in calendar
        calendarApp.launch()
        let event = calendarApp.buttons["Demo Event, from 5:00 AM to 7:00 AM"]
        XCTAssert(event.exists)

        // delete event
        event.tap()
        calendarApp.toolbars.buttons["Delete Event"].tap()
        calendarApp.sheets.buttons["Delete Event"].tap()
    }
}