问题描述
有没有人有一个关于如何使用的正确示例。 IO /> WebDriverIO ?这样我就可以捕获网络流量。我以前曾使用,它本质上是。
Does anyone have a proper example on how to configure BrowserMobProxy with WebDriverIO? This is so I can capture network traffic. I previously had it working with WebDriverJS, which is essentially a deprecated version of WebDriverIO.
推荐答案
您可以使用以下代码执行此操作。确保您的 browsermob代理
和 selenium服务器
正在运行。然后在 test.js
文件中的代码下面复制粘贴,并将其放入 webdriverio
安装文件夹中。从 cmd
转到该文件夹并运行 node test.js
。应该在 test.js
所在位置生成 stuff.har
。
You can use the below code to do that. Make sure your browsermob proxy
and selenium server
is running. Then copy paste below code in a test.js
file and put it in webdriverio
installed folder. From cmd
go to that folder and run node test.js
. stuff.har
should be generated where test.js
is located.
var Proxy = require('browsermob-proxy').Proxy
, webdriverio = require("./node_modules/webdriverio/")
, fs = require('fs')
, proxy = new Proxy()
;
proxy.cbHAR('search.yahoo.com', doSeleniumStuff, function(err, data) {
if (err) {
console.error('ERR: ' + err);
} else {
fs.writeFileSync('stuff.har', data, 'utf8');
}
});
function doSeleniumStuff(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);
}
这篇关于使用BrowserMobProxy配置WebDriverIO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!