A
A
Alexey2020-11-29 23:21:55
React
Alexey, 2020-11-29 23:21:55

Not counting DOM elements in React using Cypress?

It is not possible to count the number of DOM elements on a site written in React.

/// <reference types="cypress" />

context('Checking all components', () => {
    beforeEach(() => {
        cy.visit('https://news-israel.com');
    });

    it('Checking posts', () => {
        cy.get('.post-wrapper').find('a').should('exist');
        cy.get('.post-wrapper').find('a').its('length').should('be.gte', 100);
    });
});


In this case, it doesn't find "a" tags because React renders them asynchronously and dynamically.
The "post-wrapper" class finds, then the exception follows:


The following error originated from your application code, not from Cypress.

> Cannot read property 'substr' of undefined

When Cypress detects uncaught errors originating from your application it will automatically fail the current test.


Tell me how to correctly calculate the number of elements in this case, so that you can "wait for the elements"?
The site I'm testing is in production - https://news-israel.com
Any constructive response is appreciated!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2020-11-30
@azovl

The error was in the site itself, it was necessary to fix it or ignore it:

Cypress.on('uncaught:exception', (err, runnable) => {
  return false
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question