Possible to bring the app from background to foreground?

PistolPete

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

XCUIDevice().pressButton(XCUIDeviceButton.Home)

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

Chase Holland

Update for Xcode 9: Starting in Xcode 9, you can now simply call activate() on any XCUIApplication.

let myApp = XCUIApplication()
myApp.activate() // bring to foreground

https://developer.apple.com/documentation/xctest/xcuiapplication/2873317-activate


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:

Swift:

XCUIApplication().resolve()

Objective-C

[[XCUIApplication new] resolve];

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

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

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Phonegap - Bring from background to foreground

bring uwp app in foreground

Bring Android app's previous instance to foreground from FCM notification

How to suspend and bring a background process to foreground

Notification to bring Activity into foreground only if it is in background

Windows 10 - bring background task into foreground

beacon detecting in foreground, background and kill (remove from background) app

Bring android app in foreground after receiving respose from third party app in xamarin android

ServiceWorkerRegistration.showNotification in PWA, bring app to foreground

How to bring a nodejs app started with forever to foreground?

iOS10: tapping an action from local notification does not bring app to the foreground

Keep a dialog when a Codename One app goes from background to foreground

Problems while showing activity when app comes from background to foreground

iOS NSNotificationCenter to check whether the app came from background to foreground

How to move app from background to foreground in ionic 2?

How to call method when app enters foreground from background

password view when app come back foreground from background

Bring Chrome tab to foreground from Devtools window

Check if app's in foreground or background

Linux process to background - relogin - how to bring process back to foreground?

Clean way to bring back background process to foreground in shell script

How can I bring my div to the foreground with its background color?

How can I bring the Kivy window to the foreground in a Kivy desktop app?

How can I bring Electron app to foreground every "N" minute?

Android Twilio Video Call, wake up app and bring to foreground

Nativescript - How to bring app to foreground when notification is pressed

How to call api url method so that app reloads every time the app enters from background to foreground?

Push notification received while the app is in the foreground is different from push notification received when the app is in background

Start camera from foreground service if START_ACTIVITIES_FROM_BACKGROUND granted for the app (Android 11+)