在多台设备上测试轮换

时间:2018-01-29 15:56:23

标签: ios swift xcode9 xcode-ui-testing

我想创建一个测试例程,它将从我最重要的屏幕创建一个屏幕截图。然后,我将分别查看这些屏幕截图,以确保我没有弄乱。

我的问题是如何在整个测试功能中正确启动轮换。出于某种原因,当我修改旋转时,我得到各种奇怪的布局显示错误。

有更好的方法吗?

func testMainView() {

    XCUIDevice.shared.orientation = .portrait

    XCTContext.runActivity(named: "Main Button is tapped portrait", block: { _ in

        XCUIApplication().buttons["Main"].tap()

        // takes a second for screen to load
        sleep(3)

        let screenshot = XCUIScreen.main.screenshot()
        let attachment = XCTAttachment(screenshot: screenshot)
        attachment.lifetime = .keepAlways
        add(attachment)

    })

    // going back to the menu
    XCUIApplication().buttons["Menu"].tap()

    // rotate device
    XCUIDevice.shared.orientation = .landscape

    // give time for rotation to finish
    sleep(3)

    XCTContext.runActivity(named: "Main Button is tapped landscape", block: { _ in

        XCUIApplication().buttons["Main"].tap()

        // takes a second for screen to load
        sleep(3)

        let screenshot = XCUIScreen.main.screenshot()
        let attachment = XCTAttachment(screenshot: screenshot)
        attachment.lifetime = .keepAlways
        add(attachment)

    })

}

然后我使用xcodebuild调用测试并使用多个destinationresultBundlePath选项

如何在多个方向的许多设备上测试UI布局呢?谢谢

约瑟夫

0 个答案:

没有答案