小编rea*_*dom的帖子

无法在 cypress 命令 cy.get() 内设置变量的值以在命令外使用

我正在设置一个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)

javascript cypress

5
推荐指数
1
解决办法
5133
查看次数

标签 统计

cypress ×1

javascript ×1