我有一个关于Cypress断言的问题,最近我刚刚开始使用这个测试平台,但是当URL返回一个随机数时,我被卡住了,如下所示。
/Geocortex/Essentials/REST/sites/SITE?f=json&deep=true&token=SK42f-DZ_iCk2oWE8DVNnr6gAArG277W3X0kGJL1gTZ7W5oQAAV9iC4Zng4mf0BlulglN-10NK&dojo.preventCache=1575947662312如您所见,dojo.preventCache是随机的,也是随机字符串。我想检测这个url,并检查deep=true是否有标记号,但我不知道如何实现。
cy.location('origin', {timeout: 20000}).should('contain', '/Geocortex/Essentials/REST/sites/SITE?f=json&deep=true&token=**&dojo.preventCache=**');有人知道吗?
发布于 2019-12-10 19:58:51
您可以这样检查路径和查询(请注意,cy.location('origin')不会从原始问题中生成pathname或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;
});https://stackoverflow.com/questions/59259780
复制相似问题