Skip to content
Discussion options

You must be logged in to vote

Browser console.log method is "live", if the object is changed later, it shows the updated values. Thus console.log(test) will show at first {} then when the asynchronous Cypress commands finish will switch to showing { fname: 'Jane', lname: 'Doe' }.

But this is only because it printed the object. When it prints a primitive value like a string, it cannot change it later, thus console.log(test.fname) prints undefined and never changes.

In your example the correct code would put console.log statements into .then callbaco so they execute AFTER .each completes

const test = {}
cy.get('tbody > tr').each(($el, index, $list) => {
  test.fname = 'Jane'
  test.lname = 'Doe'
})
.then(() => {
  console.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@martialbb
Comment options

Answer selected by bahmutov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants