0

赛普拉斯与桌子配合得好吗?我有一个表格,其中我新添加的元素位于表格的第二页。如果元素不在第一页上,我想搜索表格,以便赛普拉斯点击第 2 页。我可以这样做还是必须使用 Javascript 或其他东西?

4

3 回答 3

1

这被称为Conditional Testing,通常对于 e2e 测试来说是个坏主意。

这是关于条件测试的赛普拉斯文档指南

于 2018-06-17T02:20:01.810 回答
0

如果我想在表格中搜索,这就是我实际要做的(在这种情况下,我单击每个可用按钮):

 cy.get('.name_of_class_or_id_if_apply').then((table) => {
        //Obtain the quantity of rows
        var count_rows = table[0].childElementCount
            //Obatining the name of rows
            var aux_name_rows = table[0].classList.toString()
            for (var i = 0; i < count_rows; ++i) {
                //Obtaining the quantity of columns
                var count_columns = table[0].childNodes[i].childElementCount
                    //Obtaining the name of columns
                    var aux_name_columns = table[0].childNodes[i].classList.toString()
                    for (var j = 1; j < count_columns; ++j) {
                        //In my case i obtain the name of the buttons
                        var aux_name_columns_button = table[0].childNodes[i].childNodes[j].classList.toString()
                            //Checking if the button is clickeable
                            if (aux_name_columns_button == "your_class_button") {
                                //Obtaining the position click
                                var row_position_click = i + 1
                                    var column_position_click = j + 1
                                    cy.get(':nth-child(' + row_position_click + ') > :nth-child(' + column_position_click + ') > .class_of_object_clickeable').click()
    
                            }
                    }
            }
    })

于 2021-03-10T17:44:19.777 回答
0

这将有助于

cy.xpath(columnInTable).each(
      ($e, index, $list) => {
        const text = $e.text()
        if (text.includes('yourDesiredColumnText')) {
//Do logic here
          }

        if (index === -1) {
          //goto 2nd page
        }
      }
    )
  }
于 2021-03-11T12:10:48.663 回答