代码之家  ›  专栏  ›  技术社区  ›  random-forest-cat

带有WebdriverIO和Selenium的Browsermob代理

  •  4
  • random-forest-cat  · 技术社区  · 6 年前

    我正在尝试使用selenium、webdriver io和browsermob代理在har文件中记录网络流量

    var webdriverio = require('webdriverio');
    
    var Proxy = require('browsermob-proxy').Proxy
    , fs = require('fs')
    , proxy = new Proxy()
    ;
    
    proxy.cbHAR('scratchpads.eu', doSeleniumStuff, function(err, data) {
      console.log('running cb')
      if (err) {
        console.error('ERR: ' + err);
      } else {
        fs.writeFileSync('stuff.har', data, 'utf8');
      }
    });
    
    const opts = {
      desiredCapabilities: {
        browserName: 'chrome',
      },
      host: 'localhost',
      port: '4444',
      protocol: 'http',
      coloredLogs: true,
    }
    
    function doSeleniumStuff(proxy, cb) {
      var browser = webdriverio.remote(opts);
    
      browser
        .init()
        .url('http://scratchpads.eu')
        .getTitle().then(function(title) {
          console.log('Title was: ' + title);
        })
        .end().then(cb).catch(e => console.log(e));
    }
    

    HAR文件已创建,但没有记录在条目中的任何有关网络请求的信息。

    我错过了什么?代理在8080上运行,selenium在4444上运行

    0 回复  |  直到 6 年前