【问题标题】:Webdriverio/chimpjs - Launch Google Chrome with Gelocation permittedWebdriverio/chimp js - 在允许地理位置的情况下启动 Google Chrome
【发布时间】:2016-05-23 21:46:09
【问题描述】:

我正在编写一个严重依赖地理位置的 Web 应用程序。我正在使用 chimpjs(黄瓜、webdriverio、chai 的组合)来做我的 BDD。我想启动允许地理位置的谷歌浏览器。我想我必须这样做,因为我无法单击 chrome 中的“允许”按钮来允许地理定位。

我的黄瓜目录中有一个 chimp.js 配置文件。以下是它的内容:

module.exports = {
  webdriverio: {
    desiredCapabilities: {
      chromeOptions: {
        deviceName: 'Google Nexus 5'
      }
    }
  },
  browser: 'chrome',
  watch: false,
  path: './features',
  chai: true,
  screenshotsPath: '.screenshots'
};

我知道:

  • chrome 使用可能在运行时提供的配置文件信息
  • 有一个选项“地理位置”必须设置为 1
  • 其他一些相关的嵌套是 'prefs' 和 'default_content_setting_values',这是我通过挖掘我的 chrome 首选项了解到的

我无法弄清楚其中哪些需要传递给 chromeOptions,哪些需要嵌套在哪里。

我确信我不会是唯一需要使用 webdriver 启动 chrome 并启用地理定位的人。

【问题讨论】:

    标签: selenium-chromedriver webdriver-io chimp.js


    【解决方案1】:

    您可以在chromeOptions 中使用profile.default_content_setting_values.geolocation 简单地配置它。

    chromeOptions: {
      deviceName: 'Google Nexus 5'
      prefs: {
        "profile.default_content_setting_values.geolocation": 1,
      }
    },
    

    【讨论】:

    • 这个为我修好了。虽然我这样使用它: chromeOptions: { prefs: { 'credentials_enable_service': false, 'profile': { 'password_manager_enabled': false, 'default_content_setting_values': { 'geolocation': 1 } } } }
    【解决方案2】:

    此问题与此问题重复:How do I enable geolocation support in chromedriver for Selenium?

    我已将答案翻译为 WebdriverIO 语法:

    browser.execute(function() {
      window.navigator.geolocation.getCurrentPosition = function(success) {
        var position = { coords : { latitude: "40.748440", longitude: "-73.984559" } }; 
        success(position);
      }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-22
      • 2012-04-17
      • 1970-01-01
      • 1970-01-01
      • 2017-07-21
      • 1970-01-01
      相关资源
      最近更新 更多