Testing 在TestCafe中无法解析第二个URL时,断言URL重定向

Testing 在TestCafe中无法解析第二个URL时,断言URL重定向,testing,automated-tests,e2e-testing,testcafe,browser-automation,Testing,Automated Tests,E2e Testing,Testcafe,Browser Automation,我想断言下一个URL已解析。它是SendGrid生成的URL,在浏览器中搜索时会更改该URL。问题是,要访问第二个,您需要访问我们的VPN。出于安全原因,我不想在我们的VPN后面运行测试,但我想断言来自SendGrid的重定向是否成功(我确切地知道解析的URL将是什么样子) 使用ClientFunction(()=>document.location.href)时会出现问题,您将只获得一个已成功解决的URL,并且由于我未连接到VPN,最后一个URL将不会显示,也无法断言 即使我无法解析第二个UR

我想断言下一个URL已解析。它是SendGrid生成的URL,在浏览器中搜索时会更改该URL。问题是,要访问第二个,您需要访问我们的VPN。出于安全原因,我不想在我们的VPN后面运行测试,但我想断言来自SendGrid的重定向是否成功(我确切地知道解析的URL将是什么样子)

使用
ClientFunction(()=>document.location.href)
时会出现问题,您将只获得一个已成功解决的URL,并且由于我未连接到VPN,最后一个URL将不会显示,也无法断言

即使我无法解析第二个URL,是否有办法在重定向完成后创建断言

等待t.navigateTo(URL);
const getLocation=ClientFunction(()=>document.location.href);
wait t.expect(getLocation()).contains('expected-url');

在这种情况下,预期的url是:
https://app-uat.novemberfirst.cloud.ec/#/public/reset-密码/208100002/61849181@abc.com/F1PMDC05GYHLQH82UDNL183/dan

找到了此问题的解决方案

基本上,当发出http请求时,您必须禁用任何重定向以获取url

private async resolveRedirectLink(url) {
    let redirectedURL;
    try{
        let response = await fetch(url, {redirect: 'manual'});
        let link = await response.text();
        let matches = link.match(/"(.*?)"/);
        redirectedURL = matches[1];
    }
    catch(error){
        redirectedURL = url;
        console.warn('Error redirecting URL: ' + error.message );
    }
    return redirectedURL;
}

这是我的代码中使用的剪贴

尝试wait t.expect(wait getLocation()).contains('expected-url');如果尝试过,getLocation将无法获取位置,除非浏览器能够解析url。您是否尝试过记录重定向url的方法?
private async resolveRedirectLink(url) {
    let redirectedURL;
    try{
        let response = await fetch(url, {redirect: 'manual'});
        let link = await response.text();
        let matches = link.match(/"(.*?)"/);
        redirectedURL = matches[1];
    }
    catch(error){
        redirectedURL = url;
        console.warn('Error redirecting URL: ' + error.message );
    }
    return redirectedURL;
}