WebdriverIO & Browsermob

2019-05-23 03:09发布

I'm currently trying to use Browsermob with WebdriverIO and I found this code on another answer, but when I run it, the firefox browser comes up and I see activity in the console windows I have selenium and browsermob-proxy running, but it does not go to the search.yahoo.com page. It just sits at a blank page and the tests ends (which says it passed, but that's something else) I'm running the latest WebdriverIO and Browsermob on a Mac Here's the code

var Proxy = require('browsermob-proxy').Proxy
    , webdriverio = require('webdriverio')
    , fs = require('fs')
    , proxy = new Proxy()
;

proxy.cbHAR('search.yahoo.com', doWebio, function(err, data) {
        if (err) {
            console.error('ERR: ' + err);
        } else {
            fs.writeFileSync('stuff.har', data, 'utf8');
        }
});

function doWebio(proxy, cb) {

    var browser = webdriverio.remote({
        host: 'localhost'
        , port: 4444
        , desiredCapabilities: { browserName: 'firefox', seleniumProtocol: 'WebDriver', proxy: { httpProxy: proxy } }
    });

    browser
        .init()
        .url("http://search.yahoo.com")
        .setValue("#yschsp", "javascript")
        .submitForm("#sf")
        .end().then(cb);        

}

1条回答
Emotional °昔
2楼-- · 2019-05-23 03:37

have you tried using chrome. Maybe it'll work. To do so:

  • Add chromedriver from here to your /usr/bin
  • make change to above code like below (note upper case P in proxy)
  • start selenium server and browserMob as usual and run the test

    desiredCapabilities: { browserName: 'chrome', seleniumProtocol: 'WebDriver', Proxy: { httpProxy: proxy } }

查看更多
登录 后发表回答