-1

I have a button in a UI test that logs in to an app. The user flow to automate is this:

  1. User taps button
  2. Button text changes from "Log In" to "Processing..."
  3. Button disappears when log in is successful

My UI test code is very simple for the functional test:

let loginButton = app.buttons["LOG IN"]
let welcomeText = app.staticTexts["Welcome!"]
loginButton.tap()
XCTAssertTrue(welcomeText.waitForExistence(10))

However, it does not validate that the button changes state to "Processing...".

If I attempt to put a check in the code like this, it doesn't work because by the time the UI Test has walked the screen looking for the text, it might have disappeared.

let loginButton = app.buttons["LOG IN"]
let loginButtonProcessingText = app.buttons.staticTexts["Processing..."]
let welcomeText = app.staticTexts["Welcome!"]
loginButton.tap()
XCTAssertTrue(loginButtonProcessingText.exists)
XCTAssertTrue(welcomeText.waitForExistence(10))

So my thought is that I need to somehow start the check for the processing test simultaneously with the button tap, or maybe a second before it.

Is there a way to spin up a check like that asynchronously in XCUI testing?

Sean Long
  • 2,163
  • 9
  • 30
  • 49
  • What is the app flow? In which controller `Welcome!` text is in? – dahiya_boy May 20 '20 at 17:04
  • Could you describe what you mean by app flow? There are different controllers for the loginButton and the subsequent Welcome text. The app flow is incredibly simple: WebView instantiates all buttons and fields. loginButton is a webView button loginButton, when tapped, begins authentication and simultaneously changes text to "Processing..." – Sean Long May 20 '20 at 19:01

1 Answers1

1

You can use expectation to test asynchronous task. But first it can be more clear if you separate your steps like below;

let loginButton = app.buttons["LOG IN"]
loginButton.tap()

let loginButtonProcessingText = app.buttons.staticTexts["Processing..."]
XCTAssertTrue(loginButtonProcessingText.exists)

let welcomeText = app.staticTexts["Welcome!"]
XCTAssertTrue(welcomeText.waitForExistence(10))
Omer Faruk Ozturk
  • 1,722
  • 13
  • 25