dimanche 28 mars 2021

How to compare values (aliases) in Cypress.io?

I have two views on my application, a grid with just profile pictures and a name overlayed.

The first view, from the grid, I have saved to an alias called username1

I then want to click on the profile and then make sure that the name property that shows up is the same as the grid view. I have that name saved as a variable profile1Username.

grabbing username from grid view

cy.get('[data-cy=grid-profile-name]')
      .first()
      .then(($name) => {
        return $name.text()
      })
      .as('username1')
    cy.get('@username1').then(($name) => {
      cy.log($name)
    })

clicking on the profile

cy.get('[data-cy=profile-tile]').first().click()
    cy.get('[data-cy=text-display-name]')
      .then(($name) => {
        return $name.text()
      })
      .as('profile1Username')
 cy.get('@profile1Username').then(($name) => {
      cy.log($name)

cy.get('@profile1Username').should('have.value', '@username1')

This should call just checks to see if the profile1username = the string of 'username1' and NOT the value.

What am I doing wrong here? I am able to log the values correctly, but then I am apparently not being able to get the values in the .should() I use at the end to compare.

Cheers!

Aucun commentaire:

Enregistrer un commentaire