有没有办法在量角器测试中绕过Chrome地理位置对话框? [英] Is there a way to bypass Chrome geolocation dialog in Protractor tests?

查看:86
本文介绍了有没有办法在量角器测试中绕过Chrome地理位置对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用量角器使应用程序自动化时,我遇到了这个问题.

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}传递给您的protractor.config.js中的capabilities对象

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆