首页 > 解决方案 > 带有 WebdriverIO 和 Selenium 的 Browsermob 代理

问题描述

我正在尝试使用 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 上运行,硒在 4444 上运行

标签: node.jsautomationwebdriver-iobrowsermob-proxy

解决方案


推荐阅读