首页 > 解决方案 > 在 Cypress 的 `route` 函数中获取匹配的 URL

问题描述

route我们可以指定regexorminimatch字符串来捕获任何匹配的 URL 时,我怎样才能完全获取匹配的 URL?

标签: urlroutescypress

解决方案


您可以像这样从 xhr 获取它:

    cy.route('/users/**').as('getPage');
    cy.wait("@getPage").then((xhr) => {
      url = xhr.url;
      console.log('Matched url: ' + url);
    });

希望能帮助到你 :)


推荐阅读