我如何使用柏树'应该(“包含”)检查两个字符串中的任何一个? 我有一个测试,可以检查各个参数在页面的URL中。 例如: const Expect Path =“ MyParam = some%20product%20NAME”; cy.url()。应该('include',预期path); 但是,最近这些...

问题描述 投票:0回答:1

最近,这些参数已更改,现在不再将URL空间编码为链接上URL的一部分,例如:

<a href="someproduct?myParam=some product name">
出于某种原因,浏览器以太将其转换为

myParam=some%20product%20name

myParam=some+product+name
,因此有时我的测试可以工作,有时它们不行。

有一种方法可以测试这两种情况吗?例如:

const expectedPathA = "myParam=some%20product%20name";
const expectedPathB = "myParam=some+product+name";
cy.url().should('include', (expectedPathA || expectedPathB);
    

本页

评论给出了各种复杂断言的例子。
最直接的可能是
cy.url().should('be.oneOf', [baseUrl + expectedPathA, baseUrl + expectedPathB])`
automated-tests cypress
1个回答
0
投票
或如果要应用一些额外的JavaScript,以宣称的值:

cy.url().should('satisfy', (url) => { return url.endsWith(expectedPathA) || // using string function endsWith() url.includes(expectedPathB) // OR using string function includes() })

显然您选择了适合您需求的内部功能,例如上面的一对夫妇。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.