我正在设置一个pin变量,更新它cy.get(),然后尝试在之后使用它cy.get()- 它不允许我这样做。
我也在这里读到这是不可能的:https : //docs.cypress.io/guides/core-concepts/variables-and-aliases.html#Return-Values。
我真的需要使用这个变量才能登录:它是一个生成的 PIN 码,我需要在登录时使用它。
var pin = ""
cy.get('.pin-field').invoke('text').then((text1) => {
pin = text1; //assign text1 value to global pin variable, does not work
cy.log(text1) // this works and logs the value of text1
})
cy.log(pin) //this just logs an empty
Run Code Online (Sandbox Code Playgroud)