使用 testCafe 'requestLogger' 检索 chrome 性能日志失败
Using testCafe 'requestLogger' to retrieve chrome performance logs fails
这是此线程的延续:Is there a way in TestCafe to validate Chrome network calls?
这是我的 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 的图片,用于说明我正在努力实现的目标。我导航到 google.com 并打开开发人员工具> 网络选项卡。然后我点击商店 link 并捕获日志。我尝试收集的请求 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
如果有人能指出正确的方向,我将不胜感激?
您在测试页 ('https://appURL.com/app/home/students') 和记录器 ('https://studenthome.com') 中使用了不同的 url。这可能是原因。
您的请求记录器仅记录对 'https://studenthome.com'.
的请求
在您的屏幕截图中,我看到 url 'http://store.google.com',它与记录器 url 不同,因此记录器不处理它。
您可以将 RegExp 作为 RequestLogger 构造函数的第一个参数传递给所有匹配您的 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));
});
这是此线程的延续:Is there a way in TestCafe to validate Chrome network calls?
这是我的 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 的图片,用于说明我正在努力实现的目标。我导航到 google.com 并打开开发人员工具> 网络选项卡。然后我点击商店 link 并捕获日志。我尝试收集的请求 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
如果有人能指出正确的方向,我将不胜感激?
您在测试页 ('https://appURL.com/app/home/students') 和记录器 ('https://studenthome.com') 中使用了不同的 url。这可能是原因。 您的请求记录器仅记录对 'https://studenthome.com'.
的请求在您的屏幕截图中,我看到 url 'http://store.google.com',它与记录器 url 不同,因此记录器不处理它。
您可以将 RegExp 作为 RequestLogger 构造函数的第一个参数传递给所有匹配您的 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));
});