Joseph
Joseph

Reputation: 9351

Testing UI with Screenshots

I am trying to automate my testing a little. I wrote a simple test that takes a screenshot of my app

func testiPhoneVariants() {
    let screenshot = XCUIScreen.main.screenshot()
    let attachment = XCTAttachment(screenshot: screenshot)
    attachment.lifetime = .keepAlways
    add(attachment)
}

Now I wanted to test it on multiple simulators, so I made the command line:

xcodebuild -workspace MyProject.xcworkspace -scheme MyProjectUITests \
-destination 'platform=iOS Simulator,name=iPhone SE' \
-destination 'platform=iOS Simulator,name=iPhone 7' \
-destination 'platform=iOS Simulator,name=iPhone 7 Plus' \
-destination 'platform=iOS Simulator,name=iPhone X' \
test

The tests run through, but where can I find the screenshots?

Thanks - Joseph

Upvotes: 5

Views: 1492

Answers (2)

Titouan de Bailleul
Titouan de Bailleul

Reputation: 12949

You can also pass the -resultBundlePath to the xcodebuild command to specify where you want the test results to be.

xcodebuild -workspace MyProject.xcworkspace -scheme MyProjectUITests \
-destination 'platform=iOS Simulator,name=iPhone SE' \
-destination 'platform=iOS Simulator,name=iPhone 7' \
-destination 'platform=iOS Simulator,name=iPhone 7 Plus' \
-destination 'platform=iOS Simulator,name=iPhone X' \
-resultBundlePath test_results \
test

You should find in all your test results in the test_results folder. That also includes screenshots

Upvotes: 4

Oletha
Oletha

Reputation: 7639

There will be an .xcactivitylog in your derived data folder, which is usually at the following path:

~/Library/Developer/Xcode/DerivedData//Logs/Test/

In the .xcactivitylog file, there will be objects containing details of your screenshot files including their filenames.

Upvotes: 0

Related Questions