Storing an element's text in Cypress outside of a chainer method

后端 未结 2 1121
花落未央
花落未央 2021-01-29 03:01

How can I store the text value of a div once and use this throughout a cypress test?

Thus far I\'ve managed to do this by nesting the bulk of my test\'s logic within the

2条回答
  •  甜味超标
    2021-01-29 03:45

    Your code will not work as you are not doing the operation within chain. Cypress works in promise chain and that's how the architecture is.... You have to pass on values to chain and do the operation accordingly.

    It will work like below.

    return cy.get(`.locatorClassName`).then(ele => {
          return ele.text()
        }).then(eleValue => {
          cy.log(eleValue);
        });
    

提交回复
热议问题