Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Latest commit

 

History

History
55 lines (47 loc) · 1.51 KB

Screenshot.md

File metadata and controls

55 lines (47 loc) · 1.51 KB

Take screenshot

Create UITest scheme

Puma leverages UITest scheme to take screenshot. You are also encouraged to use test plan feature of Xcode 11, but not required.

Use a simple takeScreenshot below to take screenshot, remember to specify life time to keep always

class TestAppUITests: XCTestCase {
    func testFirstScreen() {
        let app = XCUIApplication()
        app.launch()

        takeScreenshot(name: "MainScreen")
    }

    func takeScreenshot(name: String) {
        let screenshot = XCUIScreen.main.screenshot()
        let attach = XCTAttachment(screenshot: screenshot)
        attach.lifetime = .keepAlways
        add(attach)
    }
}

Then in Puma, we can use Screenshot task

Screenshot()
    .project("TestApp")
    .appScheme("TestApp")
    .uiTestScheme("TestAppUITests")
    .saveDirectory(Directory.downloads.appendingPathComponent("PumaScreenshots").path)
    .scenarios(
        .init(
            destination: .init(
                name: Destination.Name.iPhone11,
                platform: Destination.Platform.iOSSimulator,
                os: Destination.OS.iOS13_2_2
            ),
            language: Language.en_US,
            locale: Locale.en_US
        ),
        .init(
            destination: .init(
                name: Destination.Name.iPhone11Pro,
                platform: Destination.Platform.iOSSimulator,
                os: Destination.OS.iOS13_2_2
            ),
            language: Language.ja,
            locale: Locale.ja
        )
    )