bahmutov / cypress-if

Easy conditional if-else logic for your Cypress tests when there is no other way
https://cypress.tips/courses/cypress-plugins
99 stars 12 forks source link

Cypress-if no longer working after upgrade to Cypress 12.0.1 #58

Closed borecz closed 1 year ago

borecz commented 1 year ago
image image

Gleb's update

Everyone, it is not up to me - Cypress internal command API has changed a lot and it is problematic for me to do the same functionality right now. I have played with newer Cypress versions trying to find a way to implement the same feature in the PR https://github.com/bahmutov/cypress-if/pull/62 but without any success. If anyone can achieve it and fix it, I will happily merge your PR and release the new version.

obajaddi commented 1 year ago

image

I haven't seen that before ? I'm interested Gleb how it can be fixed :)

Thanks

bahmutov commented 1 year ago

Well, I will open an issue for Cypress team, it is weird not to allow overwriting commands like cy.get

estefafdez commented 1 year ago

Thanks for the quick 👀 if there's anything I can do to help please let me know :)

bahmutov commented 1 year ago

Ask on Cypress discord about itSent from my iPhoneOn Dec 7, 2022, at 08:01, Estefanía Fdez @.***> wrote: Thanks for the quick 👀 if there's anything I can do to help please let me know :)

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

estefafdez commented 1 year ago

done @bahmutov ! I will let you know and also try to ask about it in the ambassador meeting today.

estefafdez commented 1 year ago

Any update on this problem @bahmutov? it still doesn't work with cypress 12.1.0

bahmutov commented 1 year ago

@estefafdez this is blocked by Cypress itself and can be fixed if the test runner allows https://github.com/cypress-io/cypress/issues/25078

ghost commented 1 year ago

When does Cypress-if plugin will be compatible with Cypress version 12.0.1, I am not to update Cypress version to latest one.

bahmutov commented 1 year ago

@sumankMSI please see the blocking issue. I know it is frustrating, i cannot upgrade my projects to v12 to use cypress-map and cypress-if :( Either Cypress allows overwriting queries, or someone comes up with an alternative implementation for cypress-if and opens a pull request here, and I will quickly merge it if it works

mjustin commented 1 year ago

Looks like yesterday's 12.6.0 release of Cypress added the ability to override queries.

It is now possible to overwrite query commands using Cypress.Commands.overwriteQuery. Addressed in #25078.

darialuzan commented 1 year ago

I am still experiencing this issue after upgrading to Cypress v12.6.0 image image

aleksandar-embroker commented 1 year ago

Any news on this?

bahmutov commented 1 year ago

No progress, v12.6.0 added query overwrite but removed some other things so I still don’t understand how to change the behavior Sent from my iPhoneOn Feb 22, 2023, at 06:47, Aleksandar Veselinovic @.***> wrote: Any news on this?

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>

aleksandar-embroker commented 1 year ago

Thx for an answer @bahmutov , I appreciate it. Will keep watching on this issue

Cookuricoo1 commented 1 year ago

Same here

ghost commented 1 year ago

Cypress updates are available frequently but unfortunately major add-ons, not works(cypress-if). It is time to think that we will go for a new update or fix the bug. The fix is essential otherwise it might not possible to use the latest version.

mateustalles commented 1 year ago

Indeed, even with the latest version it still doesn't work.

danut-dumitru commented 1 year ago

Guys, just read the reply from Gleb, it's not yet done, of course it won't work with the latest version of Cypress.

cmesav commented 1 year ago

I have the same issue, cypress version v12.6.0. any update?? image

fleks-dev commented 1 year ago

@cmesav be patient bro, we're all waiting.

estefafdez commented 1 year ago

hey @bahmutov, how is this issue going? the new version (12.8.0) was just released today. Thanks!

ghost commented 1 year ago

hey @bahmutov, how is this issue going? the new version (12.8.0) was just released today. Thanks!

Same Cypress-if issue as previous.

nikepol commented 1 year ago

people, be patient and stop asking Gleb about the status, if you want to help - create a merge request, or look at the progress at Pull requests, while this issue is open that means there is no fix yet

update: @bahmutov described a great workaround for conditional testing in this article https://glebbahmutov.com/blog/upgrade-cypress-v9-to-v12/

Fruehwirth commented 1 year ago

When will this be fixed?

bahmutov commented 1 year ago

@Fruehwirth it will be fixed when Cypress internal code supports it, so far I could not figure out a hack to make it work

bogdan-lucaci commented 1 year ago

Hope this helps someone 🙃 I really needed the conditional existence for my tests and the workaround suggested here by using .should(Cypress._.noop) was breaking Cypress's retry mechanism, but this aproach, using MutationObserver and a 2 Promises race worked for me:

const _waitForElement = (document, CSSselector) => {
    const throwOnTimeout = new Promise((_, reject) =>
        setTimeout(() => {
            const _errMsg = `WARNING: Timeout - Optional element [ ${CSSselector} ] not present, continuing...`
            cy.log(_errMsg)
            reject(new Error(_errMsg))
        }, Cypress.config('defaultCommandTimeout'))
    )
    const getElement = new Promise(resolve => {
        if (document.querySelector(CSSselector)) {
            return resolve(document.querySelector(CSSselector))
        }

        const observer = new MutationObserver(mutations => {
            if (document.querySelector(CSSselector)) {
                resolve(document.querySelector(CSSselector))
                observer.disconnect()
            }
        })

        observer.observe(document.body, {
            childList: true,
            subtree: true
        })
    })

    return Promise.race([getElement, throwOnTimeout])
}

and consumed it like this:

cy
  .document()
  .then($doc => {
      return _waitForElement($doc, CSSselector)
          .then(elem => elem)
          .catch(error => { console.log(error) })
  })
  .then(elem => {
      if (elem)
          // handle found element
  })
jaime1702 commented 1 year ago

Good morning everyone, do we have an estimate for when Cypress will be operational again? I need this condition for my automation, and depending on the situation, I might need to find another solution!

bahmutov commented 1 year ago

I promise if someone opens a pull request with a fix for Cypress v12, I will merge it immediately as soon as the tests pass.

mateustalles commented 1 year ago

@bahmutov With Cypress v12.15.0 think all we need is to merge your PR now?! I just replaced the overwrite with overwriteQuery locally and it worked! image image

bahmutov commented 1 year ago

I still cannot figure out how to fix it, but I don't have much time for it

FMuellerBK commented 1 year ago

Hey guys, I could get it to run for Cypress 12.17.1 and Angular 16.1.5. All your tests are passing, all of our tests too (from simple to complex ones).

I already created a branch locally, but I don't have access to push it. Can you add me to the contributers, so I can create a PR for this?

Many thanks in advance!

appdirectorsantosh commented 1 year ago

FMuellerBK

I think, you should be able to raise a PR after creating fork like below example- https://github.com/bahmutov/cypress-if/pull/19

FMuellerBK commented 1 year ago

FMuellerBK

I think, you should be able to raise a PR after creating fork like below example- #19

Yes, you're right. Just created the PR. Thanks for your help!

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 1.10.5 :tada:

The release is available on:

Your semantic-release bot :package::rocket: