问题
I faced this problem, when automating an application with protractor.
Once I open a home page I get geolocation dialog with Block/Allow buttons, which didn't let proceed without selection either option
It turned out, that this dialog is not an instance of alert, that's why browser.switchTo().alert().confirm()
didn't work
Passing '--disable-notifications'
argument to Chrome also didn't solve the problem
Research online didn't give any positive results. How to solve it?
回答1:
The solution to the problem is to pass "prefs": {'profile.default_content_setting_values.geolocation': 2}
to capabilities
object in your protractor.config.js
Below is another option that does pretty much the same thing.
So chrome may take an argument --user-data-dir=/tmp/chrome
which specifies profile to open chrome with. If profile doesn’t exist at specified directory it creates default one.
Then if you open /tmp/chrome/Default/Preferences you’ll see an object with preferences. You needed to set default_content_setting_values.geolocation
to 2
(not 1 or 0) to make it NOT prompt that dialog
来源:https://stackoverflow.com/questions/55731421/is-there-a-way-to-bypass-chrome-geolocation-dialog-in-protractor-tests