使用testCafe'requestLogger'检索Chrome性能日志失败 [英] Using testCafe 'requestLogger' to retrieve chrome performance logs fails

查看:88
本文介绍了使用testCafe'requestLogger'检索Chrome性能日志失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是该线程的延续: TestCafe中是否可以验证Chrome网络调用?

这是我的testCafe尝试从chrome检索所有网络日志(即开发人员工具中的网络"标签)的方法.我在将任何东西打印在控制台上时遇到问题.

Here is my testCafe attempt to retrieve all the network logs(i.e. network tab in developer tools) from chrome. I am having issues getting anything printed on console.

const logger = RequestLogger('https://studenthome.com',{        
    logRequestHeaders: true,   
    logRequestBody: true,
    logResponseHeaders: true,
    logResponseBody:    true
});
    test  
    ('My  test - Demo', async t => {
        await t.navigateTo('https://appURL.com/app/home/students');//navigate to app launch
        await page_students.click_studentNameLink();//click on student name
        await t
            .expect(await page_students.exists_ListPageHeader()).ok('do something async', { allowUnawaitedPromise: true })       //validate list header
       await t
       .addRequestHooks(logger)     //start tracking requests
       let url = await page_studentList.click_tab();//click on the tab for which requests need to be validated

       let c = await logger.count; //check count of request. Should be 66

       await console.log(c);
        await console.log(logger.requests[2]);    // get the url for 2nd request
    }); 

I see this in console:

    [Function: count]
    undefined

以下是Google的图片,作为我要实现的目标的例证.我导航到google.com,并打开了开发人员工具>网络"标签.然后,我单击了商店链接并捕获了日志.我尝试收集的请求URL突出显示.我可以获取所有网址,然后过滤到所需的网址.

Here is picture from google as an illustration of what I am trying to achieve. I navigate to google.com and opened up developer tools> network tab. Then I clicked on store link and captured logs. The request URLs I am trying to collect are highlighted. I can get all the urls and then filter to the one I require.

以下,我已经尝试过

await console.log(logger.requests); // undefined
await console.log(logger.requests[*]); // undefined
await console.log(logger.requests[0].response.headers); //undefined
await logger.count();//count not a function

如果有人能指出我正确的方向,我将不胜感激?

I would appreciate if someone could point me in the right direction?

推荐答案

您在测试页中使用了不同的网址(' https://studenthome.com ').这可能是原因. 您的请求记录器仅记录对" https://studenthome.com "的请求.

You are using different urls in your test page ('https://appURL.com/app/home/students') and your logger ('https://studenthome.com'). This is probably the cause. Your Request Logger records only requests to 'https://studenthome.com'.

在您的屏幕截图中,我看到了网址" http://store.google.com ",该网址有所不同从记录器的URL中获取,因此记录器不会对其进行处理.

In your screenshot I see the url 'http://store.google.com', which differs from the logger url, so the logger does not process it.

您可以将RegExp作为RequestLogger构造函数的第一个参数传递给与您的RegExp匹配的所有请求.

You can pass a RegExp as a first arg of the RequestLogger constructor to all requests which match your RegExp.

我创建了一个示例:

import { RequestLogger } from 'testcafe';

const logger = RequestLogger(/google/, {
    logRequestHeaders:  true,
    logRequestBody:     true,
    logResponseHeaders: true,
    logResponseBody:    true
});

fixture `test`
    .page('http://google.com');

    test('test', async t => {
        await t.addRequestHooks(logger);

        await t.typeText('input[name="q"]', 'test');
        await t.typeText('input[name="q"]', '1');
        await t.typeText('input[name="q"]', '2');
        await t.pressKey('enter');

        const logRecord = logger.requests.length;

        console.log(logger.requests.map(r => r.request.url));
    });

这篇关于使用testCafe'requestLogger'检索Chrome性能日志失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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