component-driven / cypress-axe

Test accessibility with axe-core in Cypress
MIT License
618 stars 86 forks source link

`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. #160

Open todd-m-kemp opened 1 year ago

todd-m-kemp commented 1 year ago

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. 🤔

MattTreichelYeah commented 1 year ago

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.

todd-m-kemp commented 1 year ago

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.

frodehansen2 commented 1 year ago

Any updates on this?

martinfer-newsuk commented 1 year ago

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

todd-m-kemp commented 1 year ago

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

martinfer-newsuk commented 1 year ago

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

frodehansen2 commented 1 year ago

@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 commented 1 year ago

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.

martinfer-newsuk commented 1 year ago

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

todd-m-kemp commented 1 year ago

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...

marcovdbunt commented 4 months ago

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