【问题标题】:Cypress Assertion柏树断言
【发布时间】:2019-12-10 03:29:43
【问题描述】:

我有一个关于 Cypress 断言的问题,最近才开始使用这个测试平台,但是当 URL 返回一个随机数时卡住了,如下所示。

/Geocortex/Essentials/REST/sites/SITE?f=json&deep=true&token=SK42f-DZ_iCk2oWE8DVNnr6gAArG277W3X0kGJL1gTZ7W5oQAAV9iC4Zng4mf0BlulglN-10NK&dojo.preventCache=1575947662312

如您所见,token 是随机的,dojo.preventCache 也是随机字符串。我想检测这个 url 并检查是否 deep=true 不管令牌编号,但我不知道如何实现这一点。

cy.location('origin', {timeout: 20000}).should('contain', '/Geocortex/Essentials/REST/sites/SITE?f=json&deep=true&token=**&dojo.preventCache=**');

有人知道吗?

【问题讨论】:

    标签: testing autocomplete cypress


    【解决方案1】:

    您可以像这样检查路径和查询(请注意,cy.location('origin') 不会从您的原始问题中产生 pathnamequery,所以我使用的是 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;
    });
    

    【讨论】:

      猜你喜欢
      • 2021-06-28
      • 1970-01-01
      • 1970-01-01
      • 2021-10-29
      • 2021-01-27
      • 2021-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多