cypress-axe icon indicating copy to clipboard operation
cypress-axe copied to clipboard

`cy.then() timed out after waiting 4000ms. Your callback function returned a promise that never resolved.` on some tests using `axe-core` 4.7.1.

Open todd-m-kemp opened this issue 1 year ago • 11 comments

I'm trying to upgrade axe-core to version 4.7.1 but I'm finding that some of my Cypress a11y tests are now unexpectedly failing with this error:

cy.then() timed out after waiting 4000ms.

Your callback function returned a promise that never resolved.

The callback function was:

function (win) {
        if (isEmptyObjectorNull(context)) {
            context = undefined;
        }
        if (isEmptyObjectorNull(options)) {
            options = undefined;
        }
        if (isEmptyObjectorNull(violationCallback)) {
            violationCallback = undefined;
        }
        var _a = options || {}, includedImpacts = _a.includedImpacts, interval = _a.interval, retries = _a.retries, axeOptions = __rest(_a, ["includedImpacts", "interval", "retries"]);
        var remainingRetries = retries || 0;
        function runAxeCheck() {
            return win.axe
                .run(context || win.document, axeOptions)
                .then(function (_a) {
                var violations = _a.violations;
                var results = summarizeResults(includedImpacts, violations);
                if (results.length > 0 && remainingRetries > 0) {
                    remainingRetries--;
                    return new Promise(function (resolve) {
                        setTimeout(resolve, interval || 1000);
                    }).then(runAxeCheck);
                }
                else {
                    return results;
                }
            });
        }
        return runAxeCheck();
    }

It seems that the checks that axe-core is doing now takes longer than 4 seconds which causes then to timeout.

It looks like a workaround is to change the value of Cypress' defaultCommandTimeout but having to change this suite-wide or on a case-by-case basis for impacted tests is not a practical solution.

Another option could be to use the timeout option for uses of then in checkA11y but hardcoding it probably isn't a great idea and how long the timeout should be would also be unclear. 🤔

todd-m-kemp avatar May 18 '23 21:05 todd-m-kemp

I only see this behaviour when the scan finds something wrong so far - I corrected an obvious issue on a new page and this error went away. I'm not sure what versioning is causing the difference in behaviour because we've recently done some upgrades to major dependencies across the board. We've been on the latest version of cypress-axe for awhile but we're now on Cypress v12.11.

MattTreichelYeah avatar May 26 '23 18:05 MattTreichelYeah

I'm unable to find an issue within the page that's being scanned when we run into this problem. When I scan the page with the axe DevTools Chrome extension (axe-core version 4.7.1) no issues are identified. But, when I use cypress-axe with axe-core version 4.7.1 I get this time out error.

We're using Cypress 12.8.1 in Chrome 113 and cypress-axe 1.4.0, running on macOS 13.3.1 (a). We are trying to upgrade from axe-core version 4.4.2 (where we are not experiencing this problem) to version 4.7.1.

todd-m-kemp avatar May 29 '23 15:05 todd-m-kemp

Any updates on this?

frodehansen2 avatar Jun 19 '23 13:06 frodehansen2

@frodehansen2 @todd-m-kemp were you able to solve this? I've been running into this same issue 😞

martinfer-newsuk avatar Aug 11 '23 13:08 martinfer-newsuk

@martinfer-newsuk Sadly, I have not been able to solve this.

todd-m-kemp avatar Aug 11 '23 13:08 todd-m-kemp

@todd-m-kemp guess I'll increase the defaultCommandTimeout on the test to avoid the error. Thanks for the response 🙏

martinfer-newsuk avatar Aug 11 '23 13:08 martinfer-newsuk

@martinfer-newsuk It just started working on the project where I had the issue. Now i have the same issue on another project, so I guess i just have to wait until it resolves it self again :)

frodehansen2 avatar Aug 15 '23 10:08 frodehansen2

I just discovered that there are some scenarios this error occurs. Specifically a test where i waited for a named intercept. If i moved the cy.checkA11y() to the next test (which had the same rendered html), everything was fine. Just a tip.

frodehansen2 avatar Aug 15 '23 14:08 frodehansen2

Thanks for the replies @frodehansen2 and @todd-m-kemp. The workaround of increasing the defaultCommandTimeout solved the errors we were having

martinfer-newsuk avatar Aug 16 '23 09:08 martinfer-newsuk

Thanks for the replies @frodehansen2 and @todd-m-kemp. The workaround of increasing the defaultCommandTimeout solved the errors we were having

That's good to hear! I just don't want to take that approach in our projects. 😂 Patiently awaiting a proper resolution here...

todd-m-kemp avatar Aug 16 '23 12:08 todd-m-kemp

I have the same issue on a page where a webshop-chat is implemented. When chat element is disabled the test is working fine. workaround of increasing the defaultCommandTimeout doesnot solve it

marcovdbunt avatar May 16 '24 14:05 marcovdbunt