appium / appium

Cross-platform automation framework for all kinds of apps, built on top of the W3C WebDriver protocol
http://appium.io/
Apache License 2.0
18.89k stars 6.08k forks source link

Appium - How to dismiss 3rd party push notifications in android. #12689

Closed Faizan-Mamji closed 5 years ago

Faizan-Mamji commented 5 years ago

When performing actions on dashboard or any other screen suddenly push notification comes and my test failed as unable to find element due to notification.

Details

My all cases working fine but whenever application notification comes my test getting failed. The main issue is when i am doing something or performing any actions, suddenly notification comes on the screen and it comes any time but the problem is how would i know that there is notification on the screen? Sometimes my cases passed when notifications didn't come on screen. Is there any way to dismiss the notification as in the screenshot?

[HTTP] {"using":"-android uiautomator","value":"text(\"Latest Approvals\")"} [debug] [W3C (d77228de)] Calling AppiumDriver.findElement() with args: ["-android uiautomator","text(\"Latest Approvals\")","d77228de-3d23-4bb2-88cc-98788e39f048"] [debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator [debug] [BaseDriver] Waiting up to 0 ms for condition [debug] [AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"-android uiautomator","selector":"text(\"Latest Approvals\")","context":"","multiple":false}} [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"-android uiautomator","selector":"text(\"Latest Approvals\")","context":"","multiple":false}} [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'text("Latest Approvals")' using 'ANDROID_UIAUTOMATOR' with the contextId: '' multiple: false [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Parsing selector: text("Latest Approvals") [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] UiSelector coerce type: class java.lang.String arg: "Latest Approvals" [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[TEXT=Latest Approvals] [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Failed to locate element. Clearing Accessibility cache and retrying. [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding 'text("Latest Approvals")' using 'ANDROID_UIAUTOMATOR' with the contextId: '' multiple: false [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Parsing selector: text("Latest Approvals") [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] UiSelector coerce type: class java.lang.String arg: "Latest Approvals" [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Using: UiSelector[TEXT=Latest Approvals] [debug] [AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {"status":7,"value":"No element found"} [debug] [AndroidBootstrap] Received command result from bootstrap [debug] [MJSONWP] Matched JSONWP error code 7 to NoSuchElementError [debug] [W3C (d77228de)] Encountered internal error running command: NoSuchElementError: An element could not be located on the page using the given search parameters. [debug] [W3C (d77228de)] at AndroidDriver.findElOrEls (C:\Users\faizan.mamji\AppData\Roaming\npm\node_modules\appium\node_modules\appium-android-driver\lib\commands\find.js:75:11) [HTTP] <-- POST /wd/hub/session/d77228de-3d23-4bb2-88cc-98788e39f048/element 404 107 ms - 414 [HTTP]

Code To Reproduce Issue

public void mainAll_TaskApproved() { GeneralApprove objSec = new GeneralApprove(driver); MedicalRequestPom objMedical = new MedicalRequestPom(driver); try { objSec.myTask().click(); TimeUnit.SECONDS.sleep(25); objSec.searchMedicalLatestApproval().setValue(medicalRequestID); TimeUnit.SECONDS.sleep(2); driver.pressKeyCode(AndroidKeyCode.ENTER); TimeUnit.SECONDS.sleep(20); objSec.clickMedicalRequest(medicalRequestID).click(); TimeUnit.SECONDS.sleep(20); objMedical.btnRequetsList().get(0).click(); TimeUnit.SECONDS.sleep(10); objMedical.requestSubmittedDialog().click(); TimeUnit.SECONDS.sleep(25); } catch (Exception ex) { ex.getMessage(); } }

image

Faizan-Mamji commented 5 years ago

Sorry by mistakenly clicked on close button.

mykola-mokhnach commented 5 years ago
Faizan-Mamji commented 5 years ago

@mykola-mokhnach My code is working for UiAutomator1 But the thing is how should i add/use explicit alert on screen?

mykola-mokhnach commented 5 years ago

My code is working for UiAutomator1

I cannot understand why one needs to ask something if he already knows the answer...

Philip

Faizan-Mamji commented 5 years ago

Bro, the issue is that i already highlighted above. "My all cases working fine but whenever application notification comes my test getting failed. The main issue is when i am doing something or performing any actions, suddenly notification comes on the screen and it comes any time but the problem is how would i know that there is notification on the screen? Sometimes my cases passed when notifications didn't come on screen. Is there any way to dismiss the notification as in the screenshot?"

This is working fine when there is no push notification but it fails when there is any notification appears. So i dont think this related to UiAutomator1 or UiAutomator2

Faizan-Mamji commented 5 years ago

But the thing is how should i add/use explicit alert on screen?

I was ask you how to use this?

mykola-mokhnach commented 5 years ago

Closed as inactive. Kindly use Appium forum for howto questions

dofamin-1 commented 1 year ago

Hi there. @Faizan-Mamji did you find any solution, friend? I have the same problem... :(

Faizan-Mamji commented 1 year ago

Hi there. @Faizan-Mamji did you find any solution, friend? I have the same problem... :(

I have tried by autodismissalerts capability

dofamin-1 commented 1 year ago

Yea, thank you. But that's for iOS only...