我是Cypress的新手,我想從一個元素中獲取一個值,然后在測驗中使用,但我無法獲取這個值。有人說我需要使用async await,但這并不奏效,也許我做錯了什么。先謝謝你!
它。 only('should access Time Worked section and insert same Staff Complement value, but negative as Flexitime', function () {
let timeValue = 0;
cy.get('[data-tag="staff-complement-input"] > div > span').invoke('text')。 then(text => text)。 then(($val) => {
//$val = 420
timeValue = $val;
cy.log(timeValue)/420
})
cy.log(timeValue) / 0
//需要時間值為420。
})
uj5u.com熱心網友回復:
你可以使用別名,并保存值并在以后使用它。
cy.get('[data-tag="staff-complement-input"] > div > span'/span>)
.invoke("text"/span>)
.then((text) => text)
.as("someNum"/span>)
cy.get("@someNum").then((someNum) => /span>{
cy.log(someNum) /420
})
需要記住的一點是,cypress在每次測驗后都會清除別名。因此,只有當你在一個it()塊下做所有的事情時,上面的方法才會有效。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/322225.html
標籤:
上一篇:我無法安裝本地反應器
