javascript - How to update an alias in cypress - Stack Overflow

I am not sure if I am using this correctly in cypress. What I want to do is update my alias @priceValue

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);
})

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);
})
Share Improve this question asked Sep 12, 2021 at 9:46 BruceyBanditBruceyBandit 4,33421 gold badges82 silver badges167 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

No need for a new alias just change the old one.

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

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)
})

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745195736a4616078.html

相关推荐

  • javascript - How to update an alias in cypress - Stack Overflow

    I am not sure if I am using this correctly in cypress. What I want to do is update my alias @priceValue

    6小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信