使用量角器测试验证页面上的信标(https请求) [英] Verify beacon(https request) on the page using a protractor test

查看:71
本文介绍了使用量角器测试验证页面上的信标(https请求)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个量角器测试来验证请求是否在页面加载时触发/出现。有没有办法通过量角器测试来捕获请求?

I am writing a protractor test to verify that a request is firing/present on the page load. Is there any way to capture the request by a protractor test?

通过监视网络选项卡(开发工具)中的请求调用,可以看到它在页面加载时触发。希望自动化这种情况。

Manually by monitoring the request calls in network tab (dev tool) it can be seen firing on page load. Looking to automate this case.

另一方面,我尝试在页面上找到该链接,但由于其内部是iframe内容(#iframe_id> html> head> script> src =https ...),它无法访问(可以访问吗?)。

On the other hand, I tried locating that link on the page, but since its inside an iframe content(#iframe_id > html > head > script > src= "https..."), it's not accessible(can it be accessed?).

任何建议和帮助都表示赞赏。

Any suggestion and help is appreciated.

推荐答案

根据@Kirill的回答,我在量角器it测试中创建了这个剪辑可用的:

Based on the answer from @Kirill I created this snipped usable within a protractor "it" test:

import { browser } from 'protractor';
import { MyPage } from './pages/myPage.po';

describe('Test my Page', () => 
{
  let page: MyPage;

  beforeAll(() => {
    page = new MyPage();
  });

  it('should display my page and print generated resource traffic', () => {
    page.navigateTo();

    page.clickSomeThingToGenerateResourceCalls();
    page.clickSomeThingelseToGenerateResourceCalls();

    browser.driver.executeScript(function()
    {
      return window.performance.getEntriesByType("resource"); // returns an array of PerformanceResourceTiming objects
    }
    ).then(function (requests)
    {
      console.log(requests);
    });
  });
});






文档链接:


Documentation links:

performance.getEntriesByType('resource ')

PerformanceResourceTiming对象

如果您想过滤请求你可以这样做:

In case you want to filter the requests you could do so by:

browser.driver.executeScript(function()
{
  return window.performance.getEntriesByType("resource"); // returns an array of PerformanceResourceTiming objects
}
).then(function (requests)
{
  for (let index = 0; index < requests.length; index++)
  {
    const element = requests[index];
    if(element.name.indexOf('mydomain') !== -1)
    {
      console.log(element);
    }
  }
});

这篇关于使用量角器测试验证页面上的信标(https请求)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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