Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCTestCase: Wait for app to idle

My UI-test fails because the test waits endless until the app idles. I can not see that there is anything happening in the background, like a loading spinner.

It just occurs on one tab. All others tabs are tapable but the test fails on Screen 3. I I click on another tab after the test is caught on Screen 3 the test resumes and finishes successfully.

Any ideas?

- (void)testExample
{

    XCUIElementQuery* tabBarsQuery = self.app.tabBars;

    [tabBarsQuery.buttons[@"Screen2"] tap];
    [tabBarsQuery.buttons[@"Screen3"] tap];
    [tabBarsQuery.buttons[@"Screen1"] tap];
    [tabBarsQuery.buttons[@"Screen4"] tap];

}
like image 816
netshark1000 Avatar asked Nov 10 '15 07:11

netshark1000


2 Answers

Perhaps you have some animation or some other background (or foreground) activity that updates your UI on the main thread frequently. This causes the app to never be "quiesce" - at least on this tab. In our application we had UIView animation with option Repeat. CPU usage was fine and it wasn't a battery drain, but it made the test fail every time. Disabling the animation fixed the issue. I couldn't find a way to force the test not to wait to be idle, so we ended up disabling the animation using #ifdef for the UI test target using runtime arguments as described here: https://stackoverflow.com/a/33466038/168996

like image 154
Kamil Nomtek.com Avatar answered Oct 26 '22 11:10

Kamil Nomtek.com


let tabBarsQuery = self.app.tabBars
let button = tabBarsQuery.buttons[@"Screen2"]

while writing UI test cases, system taking time to make it hittable so we are creating a predicate for it and waiting for the button.

let predicate = NSPredicate(format: "isHittable == 1") expectation(for: 
predicate, evaluatedWith: button, handler: nil)
waitForExpectations(timeout:10, handler: nil)
button.tap()
like image 33
Ravi Tailor Avatar answered Oct 26 '22 09:10

Ravi Tailor