codeceptjs / CodeceptJS

Supercharged End 2 End Testing Framework for NodeJS
http://codecept.io
MIT License
4.11k stars 723 forks source link

CodeceptJS test fails because it tries to click a button it already has clicked #2410

Closed Maxi-droid closed 2 years ago

Maxi-droid commented 4 years ago

What are you trying to achieve?

Clicks in tests should be recognised as executed.

What do you get instead?

Tests fail randomly when clicking a link/button that take the user to a new page with the error "could not find selector abc". When checking screenshots, I see that CodeceptJS is already on the new page so the link/button HAS been clicked. This doesn't happen all the time and cannot be reproduced locally. It seems to happen more often the "warmer" a system is and the faster the tests run so my first idea was that it happens so fast that CodeceptJS doesn't get the message that the link/button has been clicked.

What I've tried so far

  1. increased delayBefore and delayAfter --> didn't help
  2. Upgraded CodeceptJS and dependencies (to the versions stated below) --> I feel like this helped a little
  3. Commented out retryFailedSteps because I thought that perhaps the link/button is clicked, nothing happens for a moment, CodeceptJS tries to click it again but in the meantime the new page has been loaded. --> I didn't see the problem described in a full run of all tests but overall more failures, so this is not an option.

Provide test source code if related

Scenario('add a product to the basket', async () => {
    productDetailPage.goToPDP() // go to product detail page

    productDetailPage.addToBasket() // add product to basket - this is where the test fails because the button cannot be found
    I.seeElement(basketPage.addedProducts.product) // according to the screenshot we actually are in the basket and the product has been added
})

Details

const delegationFileName = require('./customModules/pageObjectDelegation').getDelegationFileName()

exports.config = {
    name: 'codecept',
    tests: './tests/**/*.test.js',
    timeout: 10000,
    output: './output',
    grep: process.env.GREP,
    plugins: {
        autoDelay: {
            enabled: true,
            delayBefore: '100', // default would be 100ms
            delayAfter: '200', // default would be 200ms
            methods: [
                'click',
                'fillField',
                'checkOption',
                'pressKey',
                'selectOption',
            ],
        },
        retryFailedStep: {
            enabled: true,
            retries: 3,
            minTimeout: 500,
            maxTimeout: 1000,
        },
        screenshotOnFail: {
            enabled: true,
            uniqueScreenshotNames: true,
            fullPageScreenshots: true,
        },
        wdio: {
            enabled: process.env.SELENIUM_STANDALONE === 'true' ? true : false,
            services: ['selenium-standalone'],
        },
    },
    helpers: {
        WebDriver: require('./webdriverio.conf'),
        REST: require('./rest.conf'),
        Mochawesome: {
            uniqueScreenshotNames: true,
        },
    },
    include: {
        [omitted]
    },
    bootstrapAll: './customModules/bootstrap/bootstrap.js',
    mocha: require('./mocha.conf'),
    multiple: require('./multiple.conf'),
}
ChilinaDP commented 3 years ago

I have exactly the same issue. Someone knows?

I just try to run a test, it passed, and 5 minutes later try to run the same test and it failed on the second step because it didn't reconized the same button.

More than that, I have the other problem. I have a test that clik a button, the test pass this step, and failed the next step because, on the screenshot, you can see that it didn't click and can't make the next step.

Please help!

gkushang commented 3 years ago

I am having the same issue with Codeceptjs@3.0.2 with Webdriver. It clicks on Element and tries to click again and then fails.

TobiasLaving commented 2 years ago

We also have similar issues.

Sometimes the click will fail, but the failure picture captured is on the next page, indicating that the click worked fine. Was this ever resolved?

TobiasLaving commented 2 years ago

Done some more investigation on my end;

Lowering the cpu allocated to the test seems to let me get a fail every time; cpulimit -i -l 40 -- npm run test:t

This align with the fact that tests fail a lot more in our CI environment than on our dev machines.

TobiasLaving commented 2 years ago

Actually, nvm, when updating to latest the issue seems to have been resolved for me

kobenguyent commented 2 years ago

Cool. Let's conclude this then.

PatrickBauer commented 1 year ago

@TobiasLaving Did this error return for you? It happens for us, exactly in the same way as described by you. Any ideas how to solve this?

E: For anyone else stumbling on this. I found my solution here: https://github.com/codeceptjs/CodeceptJS/issues/3244

It happens because Playwrights default timeout is only 5 seconds long. If your web page is slow (thanks Docker on Mac :D), it does not register the new page load and retries the button click. You can change this in your config file (see link above).