Is there any way to close notification tray in Android using Appium?

Hello,

I just want to open the notification and then close it without doing any action on it… Is there any way to do so, through appium?

Don’t suggest ADB commands, since I am running my tests over clouds.

Many thanks!

((AndroidDriver) driver).openNotifications();
((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.BACK);
3 Likes

Yes, this worked! I completely forgot about AndroidKeyCode.

You can also use -

androidDriver.pressKey(new KeyEvent(AndroidKey.BACK));

I tried using -

((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.BACK);

but AndroidKeyCode class wasn’t available in the dependencies which I have added.

My dependencies are:

<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
		<dependency>
			<groupId>io.appium</groupId>
			<artifactId>java-client</artifactId>
			<version>7.2.0</version>
		</dependency>
1 Like