UI Test localization screenshots fail - they're between screens

I'd like to use the new localization screenshots and test plans feature to take screenshots in different languages, for the app store. I end up with images that are half one screen and half another, like it's some kind of timing issue. My test code is below. Is it missing something that would give it the right timing on the screenshots?


I wrote a UI test and set "Localization Screenshots" to "On" in the test plan's settings. The UI test walks through a few screens and the resulting test report has a few image files attached labeled "Localization screenshot". Some images are are split so that the left side is one view controller and the right side is another, like it captured a push navigation transition. Another image has two overlaid screens, each half faded.


I'm running in the simulator. My test code looks like:


    func testTakeScreenshots() {
        let app = XCUIApplication()
        app.launch()       
        // At workouts page
        app.tables["workouts"].cells.element(boundBy: 0).tap()
        // At first workout
        app.navigationBars.buttons["edit"].tap()
        // At workout edit screen, click first exercise
        app.tables.cells.element(boundBy: 0).tap()
        ... 
    }

Replies

I would suggest using waitForExistence to wait for an element to appear on screen before taking the screenshot: https://developer.apple.com/documentation/xctest/xcuielement/2879412-waitforexistence

This will ensure that your screen has landed on a definite state, and is not capturing a screen mid-transition