Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
190
rated 0 times [  194] [ 4]  / answers: 1 / hits: 64197  / 6 Years ago, mon, july 9, 2018, 12:00:00

I am automating Google Calculator.
And from time to time Cypress is not able to execute click on button.
The tests click on buttons (0 to 9 ) and do some simple math operations.
And in 30% chance it can not click on element and the test will fail.



I also recorded a video when issue appears.



Video here



My Project is located here:
https://github.com/afiliptsov/test-project



To run the test run : npm run test:e2e:functional


I tried to use different locator. Initially i was using just ID ex(#cwbt15 ) but after i made more specific locator ( #cwbt15 > .cwbtpl > .cwbts) and still having same issue.



Does anyone knows why it happens and how to avoid such behavior?



The project structure is :




  • cypress/PageObject.js - place where all elements declared.

  • cypress/support/commands.js - place where function click created and
    verification of value getting updated.

  • cypress/integration/functional/delete.spec.js - test which was on the
    video


More From » testing

 Answers
0

For those whore are using cypress version since/after "6.x.x"


You could use { force: true } like:


cy.get("YOUR_SELECTOR").click({ force: true });

but this might not solve it ! The problem might be more complex, that's why check below


My solution:


cy.get("YOUR_SELECTOR").trigger("click");

Explanation:


In my case, I needed to watch a bit deeper what's going on. I started by pin the click action like this:


enter


Then watch the console, and you should see something like:
enter


Now click on line Mouse Events, it should display a table:
enter


So basically, when Cypress executes the click function, it triggers all those events but somehow my component behave the way that it is detached the moment where click event is triggered.


So I just simplified the click by doing:


cy.get("YOUR_SELECTOR").trigger("click");

And it worked 🎉


Hope this will fix your issue or at least help you debug and understand what's wrong.


[#54023] Thursday, July 5, 2018, 6 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
joanneamiyaa

Total Points: 532
Total Questions: 127
Total Answers: 98

Location: Guam
Member since Tue, Nov 3, 2020
4 Years ago
;