gpt4 book ai didi

automated-tests - 如何使用 Cypress 检查 URL 内容

转载 作者:行者123 更新时间:2023-12-04 16:40:08 25 4
gpt4 key购买 nike

我想检查我的 URL 内容并执行以下操作:

if (URL.include('path')) {
//do something
} else {
// do something else
}
我可以像这样检查我的网址
cy.url().should('include', 'path');
但是当我将它粘贴到 if 运算符中时,它不起作用。

最佳答案

会推荐你使用.includes()方法。它确定一个字符串是否包含指定字符串的字符:

const path = 'user/survey';

cy.url().then(($url) => {
if($url.includes(path)) {
cy.log("Yes")
} else {
cy.log("No")
}
})

关于automated-tests - 如何使用 Cypress 检查 URL 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62571555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com