有没有办法绕过量角器测试中的 Chrome 地理定位对话框? [英] Is there a way to bypass Chrome geolocation dialog in Protractor tests?
问题描述
我在使用量角器自动化应用程序时遇到了这个问题.
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
事实证明,这个对话框不是警报实例,这就是 browser.switchTo().alert().confirm()
不起作用的原因
It turned out, that this dialog is not an instance of alert, that's why browser.switchTo().alert().confirm()
didn't work
将 '--disable-notifications'
参数传递给 Chrome 也没有解决问题
Passing '--disable-notifications'
argument to Chrome also didn't solve the problem
在线研究没有给出任何积极的结果.如何解决?
Research online didn't give any positive results. How to solve it?
推荐答案
解决问题的方法是将"prefs": {'profile.default_content_setting_values.geolocation': 2}
传递给capabilities
在 protractor.config.js 中的对象
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.
所以 chrome 可能需要一个参数 --user-data-dir=/tmp/chrome
指定配置文件来打开 chrome.如果指定目录中不存在配置文件,则会创建默认配置文件.然后,如果您打开/tmp/chrome/Default/Preferences,您将看到一个带有首选项的对象.您需要将 default_content_setting_values.geolocation
设置为 2
(不是 1 或 0)以使其不提示该对话框
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
这篇关于有没有办法绕过量角器测试中的 Chrome 地理定位对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!