Get HTTP requests (performance logs) from chromedriver with protractor(使用量角器从 chromedriver 获取 HTTP 请求(性能日志))
问题描述
我正在使用量角器进行带角度的 e2e 测试,并且我正在拼命地尝试获取带有标头和正文的 HTTP 请求日志.我已经像这样配置量角器:
I'm using protractor for my e2e tests with angular and I'm trying desperately to get HTTP requests logs with headers and body. I've configured protractor like this:
{
useAllAngular2AppRoots: true,
ignoreUncaughtExceptions: true,
maxSessions: 1,
multiCapabilities: [
{
'name': 'desktop',
'browserName': 'chrome',
loggingPrefs: {"driver": "ALL", "browser": "ALL", 'performance': 'ALL'},
chromeOptions: {
binary: process.env.CHROME_BIN,
args: ["--headless", "--disable-gpu", "--no-sandbox"],
perfLoggingPrefs: {
'traceCategories': 'blink.console,disabled-by-default-devtools.timeline'
}
}
}
],
framework: "custom",
frameworkPath: require.resolve("protractor-cucumber-framework"),
//...
};
在每个场景之后,我都在执行这个钩子:
After each scenario, I'm executing this hook:
browser.manage().logs().get("browser").then(logs =>
//...
)
但我得到的只是控制台日志,但没有 http 请求.有没有办法从量角器中的 chromedriver 获取这些?
But all I get are console logs but no http requests. Is there any way to get those from chromedriver within protractor?
这里是 chromedriver 文档的链接,其中提到了性能日志:https://sites.google.com/a/chromium.org/chromedriver/logging/performance-log
Here is a link to chromedriver doc mentioning performance logs: https://sites.google.com/a/chromium.org/chromedriver/logging/performance-log
推荐答案
您需要添加以下 chromeOptions
包括 perfLoggingPrefs
和 loggingPrefs
如 https://github.com/angular/protractor-cookbook/blob/master/protractor-javascript/example-network/conf.js
You will need to add the following chromeOptions
including perfLoggingPrefs
and loggingPrefs
as shown in https://github.com/angular/protractor-cookbook/blob/master/protractor-javascript/example-network/conf.js
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'perfLoggingPrefs': {
'enableNetwork': true,
'enablePage': false,
'enableTimeline': false
}
},
loggingPrefs: {
performance: 'ALL',
browser: 'ALL'
}
},
在获取日志时,我编写的示例在 afterEach
方法中记录日志,以便在每次测试后输出.
When getting the logs, the example I wrote has the logging in an afterEach
method to output after each test.
afterEach(() => {
browser.manage().logs().get('performance').then((browserLogs) => {
browserLogs.forEach((browserLog) => {
var message = JSON.parse(browserLog.message).message;
if (message.method == 'Network.responseReceived') {
console.log(message);
}
});
});
});
从日志中您应该能够看到加载 javascript 文件、资产等时发出的任何获取请求.
From the logs you should be able to see any get requests made when loading javascript files, assets, etc.
根据评论更新答案.如果你使用 'Network.requestWillBeSent'
,你可以查看 POST.
Updating answer per comment. If you use 'Network.requestWillBeSent'
, you can view POSTs.
这篇关于使用量角器从 chromedriver 获取 HTTP 请求(性能日志)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用量角器从 chromedriver 获取 HTTP 请求(性能日志)
基础教程推荐
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 直接将值设置为滑块 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01