Appium :check app is background of foreground?

how do i check the app is in foreground or background ? is there any python appium API for this ?

@Laxmi_Rukka when you app in foreground you can see some element specific to your app. if you can not see them => your app is in background OR crashed OR closed OR …

@Aleksei, but i would like to know from the API level, or do you know any API which will make the foreground always ?

@Laxmi_Rukka with Android you can check

((AppiumDriver) driver).currentActivity()

and see if it yours :slight_smile:

@Aleksei you means that will foreground the app ?

@Laxmi_Rukka yes. this should return current activity in foreground. for iOS only left check screen for elements of your app.

sorry to ask tomany Q, what happens if i call this method on the activity which is already active?

i mean in the device the activity is in the foreground and i assumed and tried to launch the activity. will it would be ignored that the activity is already opened ?

@Laxmi_Rukka i do not understand - why you can not test yourself?

i tested with mine app:

        System.out.println(((AndroidDriver)driver).currentActivity());
        ((AndroidDriver)driver).pressKeyCode(AndroidKeyCode.HOME);
        sleep(3);
        System.out.println(((AndroidDriver)driver).currentActivity());
        sleep(100);

got output:

my_package_name.activity.SplashScreenActivity
    sleep - 3
.Launcher
    sleep - 100

“.Launcher” is LG phone launcher activity

@Aleksei do you have python code on this?

anyways i will try similar with python
thanks a lot

Hi , How to find forground activity on ios ?