PistolPete PistolPete - 2 years ago 670
Swift Question

Possible to bring the app from background to foreground?

When running an XCT UI test it is possible to put the application under test in the background with:


It it possible in some way to bring the app back to foreground (active state) without relaunching the application?

Answer Source

Yes, it is. But, you'll need XCUIElement's private headers (which are available via header dump from Facebook here). In order to foreground the app, you need to call resolve which I believe resolves the element's query (which for applications means foregrounding the app).

For Swift, you'll have to import the XCUIElement.h into your bridging header. For Objective-C you'll just need to import XCUIElement.h.

With the app backgrounded:




[[XCUIApplication new] resolve];

If this is the only functionality you need, you could just write a quick ObjC category.

@interface XCUIElement (Tests) {
    - (void) resolve;

If you need to launch / resolve another app. Facebook has an example of that here by going through the Springboard.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download