Javascript 使用testCafe';请求记录器';检索chrome性能日志失败

Javascript 使用testCafe';请求记录器';检索chrome性能日志失败,javascript,google-chrome,automated-tests,e2e-testing,testcafe,Javascript,Google Chrome,Automated Tests,E2e Testing,Testcafe,这是此线程的延续: 下面是我的testCafe尝试从chrome中检索所有网络日志(即开发者工具中的网络选项卡)。我在控制台上打印任何内容时遇到问题 const logger = RequestLogger('https://studenthome.com',{ logRequestHeaders: true, logRequestBody: true, logResponseHeaders: true, logResponseBody:

这是此线程的延续:

下面是我的testCafe尝试从chrome中检索所有网络日志(即开发者工具中的网络选项卡)。我在控制台上打印任何内容时遇到问题

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.com,打开了开发者工具>网络选项卡。然后我点击商店链接并捕获日志。我试图收集的请求URL将突出显示。我可以得到所有的网址,然后过滤到一个我需要的

下面,我已经试过了

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

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

您在测试页面中使用了不同的URLhttps://appURL.com/app/home/students)和你的博客https://studenthome.com'). 这可能就是原因。 您的请求记录器仅记录到的请求'https://studenthome.com"

在您的截图中,我看到了url的http://store.google.com,它与记录器url不同,因此记录器不处理它

可以将RegExp作为构造函数的第一个参数传递给与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));
    });

当我执行此步骤“让url=wait page\u studentList。单击\u tab()”时,生成的页面具有此url“”。我想我不清楚什么时候开始跟踪请求。我想跟踪在单击_tab()函数后出现的页面请求。此外,使用google的插图只是为了说明(一种图像表示)我试图从中实现什么。我真的不能透露任何应用程序信息,因为它是保密的,因此必须编造一些东西,包括谷歌的例子。希望,我是有道理的。我尝试了一些类似于你的东西:wait t t t.addRequestHooks(logger); 让url=等待页面\学生列表。单击\选项卡();const c=wait logger.requests.length;等待控制台日志(c);wait console.log(logger.requests.map(r=>r.request.url));这是控制台中打印的内容:['',这意味着RequestLogger可以工作。你点击了一个标签。浏览器请求了“studenthome.com”,记录器保存了此信息。这是我理解的正确行为。我准备了另一个样品。请看一下我设置了日志记录器来记录所有请求。设置记录器后,测试将导航到您的url。然后我添加了超时,这是所有图像所必需的。结果,我收到了68个请求。我的68个请求和你的72个请求之间存在差异,但我认为这可能与你测试的具体情况有关。