Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
How to update an alias in cypress

I am not sure if I am using this correctly in cypress. What I want to do is update my alias @priceValue so I can use the updated alias later on.

This is what I mean logic wise:

1: Take the text and give it an alias of priceValue 2: Check price value to make sure it contains a string and then (and here is the issue)-> the alias is updated to a fraction by converting. string to a fraction

How do I update the alias so it's now the converted fraction?

priceElements.priceButton().first().invoke("text").as("priceValue");

cy.get("@priceValue").then((priceValue) => {
        expect(priceValue).contains("/");
        math.fraction(priceValue);
})
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can also just change it, no need for a new alias

priceElements.priceButton().first().invoke("text")
  .should('contain', '/')
  .as("priceValue")

cy.get("@priceValue")
  .then(priceValue => math.fraction(priceValue))  // modify
  .as("priceValue")                              // re-save

cy.get("@priceValue")
  .invoke('toString')
  .should('not.contain', '/')                    // different value
about 4 years ago · Juan Pablo Isaza Report

0

You can check this blog out, it discusses in detail how to update an alias - https://ronvalstar.nl/updating-a-cypress-alias.

An easier way would be to wrap the value and create a new alias.

priceElements.priceButton().first().invoke("text").as("priceValue")

cy.get("@priceValue").then((priceValue) => {
  expect(priceValue).contains("/")
  cy.wrap(math.fraction(priceValue)).as("newPriceValue")
})

cy.get("@newPriceValue").then((newPriceValue) => {
  cy.log(newPriceValue)
})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!