本文介绍了如何在chromedriver中启用地理位置支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用Selenium测试JS地理位置功能,并且我正在使用chromedriver在最新的Chrome上运行测试。



问题是现在Chrome提示我在测试过程中启用Geolocation,而且我不知道如何在运行时单击该小条,所以我急切地想找到一种方法,使用某些选项或触发器启动chromedriver和chrome,以默认启用它。我只能在上找到如何完全禁用地理位置定位。 p>

如何解决此问题?

解决方案

在已知问题部分他们说的时候,您无法指定自定义配置文件

这就是为什么在我看来,@ Sotomajor关于使用Chrome使用个人资料(就像使用Firefox一样)的答案将不起作用。



在我的一项集成测试中,我遇到了同样的问题。但是因为我不关心真正的地理位置值,所以我要做的就是模拟window.navigator.gelocation



在您的Java测试代码中,为了避免这种情况Chrome geoloc权限信息栏。

 
chromeDriver.executeScript( window.navigator.geolocation.getCurrentPosition =
函数(成功){
var position = { coords:{
纬度: 555,
经度: 999
}
};
success(position);});

此处的纬度(555)和经度(999)值只是测试值


I need to test a JS geolocation functionality with Selenium and I am using chromedriver to run the test on the latest Chrome.

The problem is now that Chrome prompts me to enable Geolocation during the test and that I don't know how to click that little bar on runtime, so I am desperately looking for a way to start the chromedriver and chrome with some option or trigger to enable this by default. All I could find here was however how I can disable geolocation altogether.

How can I solve this issue?

解决方案

In the known issues section of the chromedriver wiki they said that you Cannot specify a custom profile

This is why it seems to me that @Sotomajor answer about using profile with Chrome as you would do with firefox will not work.

In one of my integration tests I faced the same issue. But because I was not bothering about the real geolocation values, all I had to do is to mock window.navigator.gelocation

In you java test code put this workaround to avoid Chrome geoloc permission info bar.

chromeDriver.executeScript("window.navigator.geolocation.getCurrentPosition =
    function(success){
         var position = {"coords" : {
                                       "latitude": "555",
                                       "longitude": "999"
                                     }
                         };
         success(position);}");

latitude (555) and longitude (999) values here are just test value

这篇关于如何在chromedriver中启用地理位置支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 16:22
查看更多