【问题标题】:How can I get the value stored in that array 'my_array' Cypress?如何获取存储在该数组“my_array”赛普拉斯中的值?
【发布时间】:2021-04-11 07:01:03
【问题描述】:
cy.get(tableBody)
    .each(($el, $index) => {
        let myArray = []
        let mydata = $el.text()
        if($index!==1) {
            myArray.push(mydata.trim())
        }
    }).then((my_list) => {
        cy.log(my_list)

这里,my_list 打印与 cy.get(tableBody) 返回的值相同的值。就像 cy.get(tableBody).then((my_list) => { cy.log(my_list) }。我想要那个数组并在以后使用它。我知道我可以像这样得到回报

TableDataBeforeSorting() {
    let myArray = []
    cy.get(tableBody).each(($el, $index) => {
        let mydata = $el.text()
        if($index!==1) {
            myArray.push(mydata.trim())
        }    
    })
    return myArray

但我希望它使用 then 以便我以后可以使用它。任何建议或反馈都将受到高度赞赏。

【问题讨论】:

    标签: javascript arrays sorting each cypress


    【解决方案1】:

    我发现,当赛普拉斯在将数据保存到变量以供以后使用方面没有做我想做的事情时,我可以将数据保存到磁盘:

    // save it
    cy.XYZcommand().then((results) => {
      cy.writeFile('temp.txt', results)
    })
    
    ...
    
    cy.readFile('temp.txt')
      .then((results) => {
      // do something with it
    })
    
    ...
    // clean it up
    cy.exec('rm temp.txt')
    

    【讨论】:

      猜你喜欢
      • 2021-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-12
      • 2018-06-29
      相关资源
      最近更新 更多