【问题标题】:How to intercept a specific URL with wildcards如何拦截带有通配符的特定 URL
【发布时间】:2022-11-21 09:09:39
【问题描述】:

我有一个应用程序,获取了两个不同的 URL。部分 URL 是需要通配符模式的散列,我只想在拦截中捕获一个 URL。

但是字符串的相似性使得很难获得有效的模式。

/api/v1/payment/duedate?type=payment&cache_buster=...
/api/v1/payment/6309503a5c058a702224?cache_buster=...   // capture this one

我试过了

cy.intercept('/api/v1/payment/*?cache_buster=*')

但似乎我需要否定路径名或查询参数的特定部分,但似乎不可能这样做。

【问题讨论】:

    标签: cypress cypress-intercept


    【解决方案1】:

    您确实可以否定 URL 的一部分,但不能在查询参数部分中否定。

    这将选择带有 /payment/* 的任何 URL,但排除带有 /payment/duedate 的 URL。

    cy.intercept('/api/v1/payment/!(duedate*)')
    

    您也可以尝试正则表达式,或在 routeHandler 回调中使用 javascript 代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-20
      • 2014-05-26
      • 1970-01-01
      • 2011-07-15
      • 2012-05-17
      • 1970-01-01
      相关资源
      最近更新 更多