使用cypress搜索表

时间:2018-03-30 13:16:10

标签: cypress

柏树能很好地使用桌子吗?我有一个表,我新添加的元素在表的第二页上。我想搜索表格,如果它不在第一页上,那么柏树将点击第2页。我可以这样做或者我是否必须使用Javascript或其他东西?

3 个答案:

答案 0 :(得分:0)

这称为 Conditional Testing ,对于e2e测试通常是糟糕的主意

Here's the guide on the Cypress Docs about Conditional Testing

答案 1 :(得分: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()
    
                            }
                    }
            }
    })

答案 2 :(得分: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
        }
      }
    )
  }