本文介绍了har文件问题与webdriverio一起使用browsermob-proxy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正尝试通过和和webdriverio。它运行正常,但没有生成 har
文件。我尝试更改下面的行
I was trying to use browsermob-proxy using this and this with webdriverio. It runs fine , but theres no har
file generated. I tried changing the below line
fs.writeFileSync('stuff.har', data, 'utf8');
到
fs.writeFile('/Users/abc/xyz/stuff.har', data, 'utf8');
在以下代码中(来自上面的链接)
in the below code (from above links)
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(cb);
}
但仍然没有 har
将生成该位置的文件。
but still no har
file at the location is generated. What is missing here?
推荐答案
我终于能够运行以下代码来生成har文件。注意将 doSeleniumStuff
函数从 .end(cb);
更改为 .end() .then(cb);
I finally was able to run the below code to generate the har file. Note minor change to doSeleniumStuff
function from .end(cb);
to .end().then(cb);
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');
//fs.writeFile('/Users/hanu/Desktop/amit/webdriverio/webdriverio-test/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);
}
这篇关于har文件问题与webdriverio一起使用browsermob-proxy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!