如何解决赛普拉斯-如何检查在加载新页面之前触发的Google事件
这是场景:
- 用户访问
index.com
- 点击X按钮
- 在此触发了Google Analytic事件
- 用户被重定向到新页面
这是我的代码:
describe("Desktop - Listing details - Google Analytics",() => {
slugs.forEach((slug,index) => {
context(`For ${slugs[index]}`,() => {
beforeEach(() => {
const ga = cy.stub().as("ga");
cy.on("window:before:load",win => {
Object.defineProperty(win,"ga",{
configurable: false,get: () => ga,// always return the stub
set: () => {} // don't allow actual google analytics to overwrite this property
});
});
cy.visit(`/url/a/${slug}/`);
});
context("Navigation tab",() => {
it("Pricing tab",function() {
cy.get(`[class="nav-links"] > li`)
.eq(1)
.click(); // Here a new page loads and the events are not longer present
cy.get("@ga").should(`be.calledWith`,`send`,{
hitType: "event",eventCategory: "navigation-bar",eventAction: "go-to_product_pricing",eventLabel: "navigation-tab"
});
});
});
});
});
});
第二次尝试:
Cypress.on('window:before:load',(win) => {
// because this is called before any scripts
// have loaded - the ga function is undefined
// so we need to create it.
win.ga = cy.stub().as('ga')
})
describe("Desktop - Listing details - Google Analytics",() => {
beforeEach(() => {
cy.visit(`/url/a/${slug}/`);
});
context("Navigation tab",eventLabel: "navigation-tab"
});
});
});
});
});
});
问题是赛普拉斯正在“新建”页面中声明,而我要检查的事件不再存在。
我该如何测试?老实说,我尝试了一切。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。