How to invoke Recent apps activity and launch app from recent app list by using appium?

How to invoke Recent apps activity and launch app from recent app list by using appium?

1 Like

driver.pressKey(187); --> driver.findElements(ā€œApp Nameā€).click();

1 Like

Thanks for your reply.

Still Iā€™m facing the problemsā€¦find below code for your reference.

AppiumDriver driver;
AndroidDriver drAndroid;

public void recentApp() {

        // driver.pressKey(187); //getting error after that created " drAndroid"

          drAndroid.pressKeyCode(187);
         
          driver.findElements("Whatsapp").click(); // I'm not able to use driver.findElements

    }

drAndroid.pressKeyCode(187);
drAndroid.findElement(ā€œWhatsappā€).click();

Try aboveā€¦ BTW why do u require two driver instances?

First instance is not working. Thatā€™s why created second instance as AndoridDrvier(will delete AppiumDriver).

Question 1 : ----- not able to use Home package
capabilities.setCapability(ā€œappPackageā€, ā€œcom.android.systemuiā€);
capabilities.setCapability(ā€œappActivityā€, ā€œcom.android.systemui.recents.RecentsActivityā€);

@BeforeClass Setup
org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (Original error: Permission to start activity denied.) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 4.57 seconds
Qaestion 2 -------- if i use launcer activity gettting ā€˜nullā€™ exceptionā€¦plz refer below code

capabilities.setCapability(ā€œappPackageā€, ā€œcom.android.launcherā€);
capabilities.setCapability(ā€œappActivityā€, ā€œcom.android.launcher2.Launcherā€);

Thread.sleep(5000);

         drAndroid.findElement(By.id("com.android.systemui:id/task_view_bar")).click();

recent app list is displaying for a while n getting Exception is - ā€™ null ā€™

Priyank - itā€™s working fine and find below code for all referenceā€¦

Thanks for your suggestion.

AndroidDriver driver;

capabilities.setCapability(ā€œappPackageā€, ā€œcom.android.launcherā€);
capabilities.setCapability(ā€œappActivityā€, ā€œcom.android.launcher2.Launcherā€);

driver = new AndroidDriver(new URL(ā€œhttp://127.0.0.1:4723/wd/hubā€), capabilities);

Thread.sleep(5000);

driver.pressKeyCode(187);
driver.findElement(By.name(ā€œMessagingā€)).click();

Hi Rahul,

I tried out the above code. But getting back:
org.openqa.selenium.InvalidSelectorException: Locator Strategy ā€˜nameā€™ is not supported for this session

Any idea on this?

Byname is depreciated and also, how to get app name ?

   driver.pressKey(new KeyEvent(AndroidKey.APP_SWITCH));

   driver.pressKey(new KeyEvent(AndroidKey.DPAD_DOWN));
   driver.pressKey(new KeyEvent(AndroidKey.DPAD_DOWN));     

   driver.pressKey(new KeyEvent(AndroidKey.ENTER));
1 Like