By regina_fallangi

2018-10-09 10:48:21 8 Comments

I am currently trying to figure out when an activity indicator is on or off. I realised that, when on, its value is 1, 0 when off.

I am trying to check if that value is 1 or 0 like this:

let app = XCUIApplication()
let predicate = NSPredicate(format: "value == 0")
let expectation = expectation(
        for: predicate, 
        evaluatedWith: app.activityIndicators["activityId"],
        handler: nil)

if XCTWaiter().wait(for:[expectation], timeout: 20) == .completed {
    print ("Activity indicator is off")
} else {
    print ("Activity indicator is on")

The current problem is that the timeout is always reached. Whenever I set a breakpoint at the if and type this in the console:

po app.activityIndicators["activityId"].value

The result is:

- some : 0

However, after I let the test run again, the timeout is reached and the else branch is taken.

Can anyone see what I am doing wrong while accessing the value of the element in the expectation?

Thanks for your help in advance.


@Aleksander 2018-10-11 14:35:45

Assuming you've both launched your app and set the accessibility identifier of your activity indicator correctly (which it seems you've done), the reason your code doesn't work is that value is a string, not an integer.

Replacing your predicate with the following will make your code work:

let predicate = NSPredicate(format: "value == \"0\"")

Related Questions

Sponsored Content

15 Answered Questions

[SOLVED] Swift for loop: for index, element in array?

  • 2014-06-04 03:19:21
  • metaphy
  • 372992 View
  • 706 Score
  • 15 Answer
  • Tags:   arrays swift

16 Answered Questions

[SOLVED] How to check if an element is in an array

  • 2014-06-08 00:52:11
  • jaredsmith
  • 329092 View
  • 435 Score
  • 16 Answer
  • Tags:   arrays swift

1 Answered Questions

1 Answered Questions

1 Answered Questions

[SOLVED] Swift UITest Can not find collectionview inside of tableviewcell

0 Answered Questions

iOS Push Notifications UITesting

1 Answered Questions

[SOLVED] UITest XCUIElementQuery missing elements

1 Answered Questions

XCode UITest will not give NSTextField keyboard focus

2 Answered Questions

[SOLVED] Swift if let evaluates successfully on Optional(nil)

Sponsored Content