使用量角器从chromedriver获取HTTP请求(性能日志) [英] Get HTTP requests (performance logs) from chromedriver with protractor

查看:355
本文介绍了使用量角器从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 doc的链接: 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文件,资产等时发出的任何get请求。

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请求(性能日志)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆