Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Does anyone know how to get rid of Chrome push notifications popup before starting tests on Android Emulator #811

Open
pawlakmaly opened this issue Aug 7, 2024 · 4 comments

Comments

@pawlakmaly
Copy link

Hi all,

I want to get rid of this
image
Which is displayed displayed every time I restart/recreate my emulator in docker.

I was able to bypass the welcome screen using '--disable-fre' flag. I've tried different flags as well, but with any success.

Does any one know how to do dat using adb, capabilities or or any other method that requires clicking ?

@pawlakmaly pawlakmaly changed the title [Question] Does anyone know hot to get rid of Chrome push notifications popup before starting tests on Android Emulator [Question] Does anyone know how to get rid of Chrome push notifications popup before starting tests on Android Emulator Aug 7, 2024
@itkhanz
Copy link

itkhanz commented Jan 22, 2025

I am looking for solution this as well, I reset the chrome browser on real android device after each test execution via ADB shell command adb -s UDID shell pm clear com.android.chrome. This reset is needed so that each test uses a fresh browser without any cache or browser data from the previous test execution.

and then on the next test execution I get this popup which needs to be manually closed before i can interact with the webpage in chrome browser.

@mykola-mokhnach Perhaps you know if there is a way to bypass this popup on android devices? maybe there is some chrome option appium:chromeOptions that is needed to be passed while creating driver session?

@KazuCocoa
Copy link
Member

appium:autoGrantPermissions or https://github.com/appium/appium-uiautomator2-driver?tab=readme-ov-file#mobile-changepermissions command before starting the chrome process would help.

@itkhanz
Copy link

itkhanz commented Jan 23, 2025

https://github.com/appium/appium-uiautomator2-driver?tab=readme-ov-file#mobile-changepermissions command before starting the chrome process would help.

Thank so so much for the hint. I tried with the following permission https://developer.android.com/reference/android/Manifest.permission#POST_NOTIFICATIONS and it worked for me. After the driver session is created, I execued below script which made chrome not to display this Notifications popup on fresh chrome launch. All the other permissions from app under test are not impacted by this, since in this case the app under test is different from chrome.

Command

//Java code
((JavascriptExecutor) driver).executeScript("mobile: changePermissions", ImmutableMap.of(
                "permissions", new String[]{"android.permission.POST_NOTIFICATIONS"}
                ,"appPackage", "com.android.chrome"
                ,"action", "grant"
        ));

Appium Logs:

[1a50e66a][HTTP] --> POST /session/1a50e66a-14dc-4b87-b241-de4ce4444554/execute/sync {"args":[{"appPackage":"com.android.chrome","action":"grant","permissions":["android.permission.POST_NOTIFICATIONS"]}],"script":"mobile: changePermissions"}
[1a50e66a][AndroidUiautomator2Driver@3b7f] Calling AppiumDriver.execute() with args: ["mobile: changePermissions",[{"appPackage":"com.android.chrome","action":"grant","permissions":["android.permission.POST_NOTIFICATIONS"]}],"1a50e66a-14dc-4b87-b241-de4ce4444554"]
[1a50e66a][AndroidUiautomator2Driver@3b7f] Executing native command 'mobile: changePermissions'
[1a50e66a][ADB] Granting permissions ["android.permission.POST_NOTIFICATIONS"] to 'com.android.chrome'
[1a50e66a][ADB] Got the following command chunks to execute: [["pm","grant","com.android.chrome","android.permission.POST_NOTIFICATIONS",";"]]
[1a50e66a][ADB] Running '/Users/xxxx/Library/Android/sdk/platform-tools/adb -P 5037 -s RF8N90E8ZBR shell pm grant com.android.chrome android.permission.POST_NOTIFICATIONS ;'
[1a50e66a][AndroidUiautomator2Driver@3b7f] Responding to client with driver.execute() result: null
[1a50e66a][HTTP] <-- POST /session/1a50e66a-14dc-4b87-b241-de4ce4444554/execute/sync 200 232 ms - 14

@KazuCocoa Not sure if this is indeed the correct way to deal with this problem, but it worked for me so this issue may be closed.

Note: Also I did not pass any server flag like --relaxed-security while starting appium server, and started appium server via just appium --use-drivers=uiautomator2.

@pawlakmaly Please verify if this solution works for you as well.

@KazuCocoa
Copy link
Member

Yes, the method looks correct way. Basically the popup is managed by System's config (permission related), so this is not the same with Desktop's chrome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants