Tuesday 21 June 2016

Block Push Notification on Chrome in Selenium Webdriver


Many of you might already know that Chrome browser supports push notification  almost on all platforms from version 42  and many sites including Facebook and Google+ have already started delivering push notification for end users. So when it comes to automating such sites/apps first thing that you notice is browser asking permission to deliver push notification.


Block Push Notification on Chrome in Selenium Webdriver
Facebook asking for permission to show push notification

Problem Statement:-


As you can observe in above image that it would be impossible to perform immediate next action in browser after login as it’s been blacked-out. Chrome driver will wait for sometime (implicit wait) and then try to perform next step in browser, whatever it may be, it will fail and if you missed the step in execution which might cause failure of next step and result would be failed test/test suite.

Also push notification badges are not getting displayed as part of web document, so clicking on those button displayed is not possible through selenium.



Workaround:-

    Simple thing to do, is find body element of page [which exist for all the pages :-) ], and perform double click on it. But as mentioned, it would be just workaround.



Better Approach:-

    What you would have done if you have to do same thing again and again manually in this case? Consider testing ten different app and login scenarios for them. Any sane person would have searched for how to do the same manually.
Manually disable/block Push Notification in Chrome
Manually disable/block Push Notification in Chrome



Whatever you would have done manually, would it be possible to set this up while invoking chromedriver instance? Yes, This is where chromedriver Capabilities and ChromeOptions comes into the picture.
Almost for each user customizable setting there is ChromeOption available. You can check all options here. Now to prevent or block push notifications on Chrome we can use disable-notifications option.

This is all for now.
Cheers!!

0 comments:

Post a Comment

Copyrights held by Amol Chavan. Powered by Blogger.