2

我正在使用 Codeception 运行验收测试,我需要计算带有“.remove”类的按钮在一页中出现的次数。这样的按钮位于 html 表格内,计数取决于购物车中有多少物品。
以下是我尝试使用的代码:

    $I->amOnPage("/cart/");
    $table = $I->grabTextFrom(".//*[@id='cart']/table");
    $rows = explode("<tr>", $table);
    $rcount = count($rows);
    while ($rcount >= 0) {
        $I->click(".remove");
        $rcount--;
    }
    $I->see("Your shopping cart is empty.");
4

2 回答 2

5

我知道这有点晚了,但您应该尝试 $I->seeNumberOfElements,如下所述:

http://codeception.com/docs/modules/WebDriver#seeNumberOfElements

于 2014-10-20T17:40:08.970 回答
0
$arrayProducts = $I->grabMultiple(XPATH_PRODUCTS_BOX);
        $sumProducts = count($arrayProducts);
        $I->comment("In category $selectCategory is total product: $sumProducts");
        $I->seeNumberOfElements(XPATH_PRODUCTS_BOX, $sumProducts);
        return $sumProducts;
于 2016-09-16T18:38:44.950 回答