【问题标题】:iOS UI Test: How can I check an appointment in the calendar?iOS UI 测试:如何查看日历中的约会?
【发布时间】:2017-03-13 11:43:25
【问题描述】:

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

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

【问题讨论】:

    标签: ios swift xctest xcode-ui-testing


    【解决方案1】:

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

    (我为此使用了一个小型演示应用程序。它只有一个“添加事件”按钮,用于添加当天早上 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()
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-05-14
      • 1970-01-01
      • 1970-01-01
      • 2017-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-07
      • 2017-10-14
      相关资源
      最近更新 更多