Reputation: 2164
Background
I am investigating migration of our Appium-based automation to Xcode UI Testing. Given that our app is written in Objective C I need to use Objective-C for the test code as well.
The app I am automating tests for, has a progress bar whose values I want to read. It's not a UIAProgressIndicator, just a UIAStaticText
whose value increases from "0" to "100%".
The XCUIElement
corresponding to this staticText can be accessed as
[[app staticTexts] elementBoundByIndex:1]
The progress bar will take different amounts of time - and I need to monitor the progress, which will involve reading the value (and parsing it of course).
I tried getting the value using various methods - [XCUIElement value]
and [XCUIElement label]
.
NSString *prog = [[[app staticTexts] elementBoundByIndex:1] label];
The label
approach is getting me the progress string, so I am doing this in a loop, for e.g.
int i=0;
while (i<5) {
//custom sleep method
[self.helper threadSleepForSeconds:[NSNumber numberWithInt:2]];
//now get progress text
NSString *prog = [[[app staticTexts] elementBoundByIndex:1] label];
i++;
}
However, as the progress changes, the label
attribute does not update - it seems to keep showing the first value that was read, as though it was cached somewhere.
i.e the log output shows (assuming the first value read was 19%):
19%
19%
19%
19%
I am quite unable to figure out why this happens. Any help?
Upvotes: 3
Views: 855
Reputation: 522
There is no synthesized event, so Xcode doesn't attempt to take a new snapshot of the UI elements on the screen. This is by design so that assigning multiple ui element variables in a specific view doesn't overwork your computer.
Unfortunately, manual testing may be your only option if you're not satisfied with unit testing.
Upvotes: 2