testcafe

Should click event be triggered by clicking on a disabled button?


Noticed this request from 2 years ago: https://github.com/DevExpress/testcafe/issues/5240. However, should this be allowed behaviour ?

Case scenario: I have a button that is disabled because user need to accept "terms & conditions", in the browser I can't click or interact with this button (and according to MDN docs that's how it should be) but in testcafe it bypasses disabled attribute and still clicks on that button? Which makes the whole test of "Should not submit unless user accepted terms" and invalid test.

Obviously the workaround is to assert for disabled attribute but I'm still confused if this is intended behaviour?


Solution

  • TestCafe should emulate browser behavior, so a disabled button should not work. I checked this behavior, and it works as expected in the latest TestCafe version. Here is an example:

    <body>
        <button disabled="disabled">click me</button>
        <script>
            document.querySelector('button').addEventListener('click', () => {
                throw new Error('clicked');
            });
        </script>
    </body>
    
    test(`t`, async t => {
        await t.click('button');
    });
    

    Please check it on your machine and share your results. Please also update your TestCafe version if you are not using the latest version.