Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

267
Visualizações
Cypress won't show an array contents into the console

I'm trying to add the titles of an iframe header into an array to then print the array with it's element into the console. The elements are added just fine, the problem is that the console is showing "Array[9]" instead of "[Home, Courses, ...]". Is there any way to show the elements rather than the object? This is the code:

    it("Get the elements from the header of the iframe and add them to an array", () => {

    cy.visit("https://www.rahulshettyacademy.com/AutomationPractice/")
    let headerArray = []
    cy.frameLoaded("#courses-iframe")
    cy.iframe("#courses-iframe").find(".nav-outer > .main-menu > .navbar-collapse > ul > li").each(($row, index, $rows) => {
        headerArray.push($row.text())
    })
        cy.log(headerArray)
})

And this is the console response:

And here is the console response

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

cy.log() is not great for debugging purposes, the general form for messages is name (left column) and description (right column). Anything nested gets abbreviated.

Try stringifying

cy.log(JSON.stringify(headerArray))

or joining

cy.log(headerArray.join(', '))

or if you just want to debug use console

console.log(headerArray)

The other reason why cy.log() is not good for this, the code as shown will log an empty array.

The cy.log() takes value of headerArray before the commands run so you must use a .then()

const headerArray = []
cy.iframe("#courses-iframe").find(".nav-outer > .main-menu > .navbar-collapse > ul > li")
  .each(($row, index, $rows) => {
    headerArray.push($row.text())
  })
  .then(() => {
    cy.log(headerArray)
  })
about 4 years ago · Juan Pablo Isaza Relatório

0

Thanks for your answer. I also came up with the idea of using .toString(). In that way i can show the contents in the same way as join do. Still, join is better because it separates all the contents of the array with coma properly, while toString doesn't do that.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda