3

Fastlane claims to take screenshots for me for all screen sizes and localizations.

According to the guide, I created a UI test case like this:

override func setUp() {
    super.setUp()
    continueAfterFailure = false
    setupSnapshot(XCUIApplication())
    XCUIApplication().launch()
}

override func tearDown() {
    super.tearDown()
}

func testExample() {
    let app = XCUIApplication()
    app.collectionViews.staticTexts["13"].swipeRight()
    snapshot("calendar")
    let staticText = app.collectionViews.staticTexts["26"]
    staticText.tap()
    snapshot("preview")
    app.buttons["Editor"].tap()
    snapshot("editor")
    app.navigationBars["2016/6/26"].buttons["Cancel"].tap()
    app.navigationBars["My Diaries"].buttons["search filled"].tap()

    let tablesQuery = app.tables
    tablesQuery.textFields["Search"].tap()
    tablesQuery.textFields["Search"].typeText("beach")
    snapshot("search")

    app.navigationBars["Search"].buttons["search colored"].tap()
    app.navigationBars["Results - 1 / 2"].buttons["right"].tap()

    snapshot("result")
}

When I run the test in an English Simulator, it succeeds. When I run the test in a Chinese Simulator (I localized my app to Chinese. That's why I want to run it in Chinese), the test doesn't work because it can't find those English words in my app.

But from the guide, I would imagine it would handle this for me, using NSLocalizedString or something like that.

So I cd to the project directory, snapshot, then chose a target and it starts taking screenshots...

... until it reaches the part where it should tap on the "Editor" button, because it couldn't find the English word. And it crashed.

So do I need to add if statements to check which localization is the app in? That would be a pain in the neck to do! I'd rather take screenshots myself if that's the case.

I think I must be misunderstanding fastlane. What is the correct way of taking screenshots using Snapshot?

Sweeper
  • 213,210
  • 22
  • 193
  • 313

1 Answers1

0

This an old question and you most likely already found a solution but, in case anyone facing a similar issue sees this, I'll give my two cents. You can modify your code to not rely on localized strings, it's not ideal but since we are talking about a more controlled scope (generating screenshots) it's applicable and can be quite easy.

For example, the expressions on top could be translated to the ones below by only finding the correct index:

app.buttons["Editor"].tap()
// translates to...
app.buttons.element(boundBy: 5)

app.navigationBars["2016/6/26"].buttons["Cancel"].tap()
// translates to...
app.navigationBars.buttons.element(boundBy: 0).tap()

Again, it is not ideal but can be useful, especially in cases the text changes among different executions. Another trick you can use is described here.

Mateus
  • 2,640
  • 5
  • 44
  • 62