我有一个关于 Cypress 断言的问题,最近才开始使用这个测试平台,但是当 URL 返回一个随机数时卡住了,如下所示。
/Geocortex/Essentials/REST/sites/SITE?f=json&deep=true&token=SK42f-DZ_iCk2oWE8DVNnr6gAArG277W3X0kGJL1gTZ7W5oQAAV9iC4Zng4mf0BlulglN-10NK&dojo.preventCache=1575947662312
Như bạn có thể thấy,token 是随机的,dojo.preventCache 也是一个随机字符串。我想检测此 url 并检查 deep=true 是否与 token 号无关,但我不知道如何实现此目的。
cy.location('origin', {timeout: 20000}).should('contain', '/Geocortex/Essentials/REST/sites/SITE?f=json&deep=true&token=**&dojo.preventCache=**');
有人知道吗?
您可以像这样检查路径和查询(注意 cy.location('origin')
不会产生 pathname
Và query
来自你原来的问题,所以我使用 cy.url()
:
cy.url()
.should('contain', '/Geocortex/Essentials/REST/sites/SITE')
.should('contain', 'deep=true');
或分别检查:
cy.location('pathname').should('contain', '/Geocortex/Essentials/REST/sites/SITE');
cy.location('search').should('contain', 'deep=true');
或者,使用自定义回调,您可以在其中执行和断言任何您想要的:
cy.url().should( url => {
expect(/* do something with url, such as parse it, and access the `deep` prop */)
.to.be.true;
});
Tôi là một lập trình viên xuất sắc, rất giỏi!