Yii2 Codeception测试点击下拉菜单

时间:2016-06-10 18:49:21

标签: yii2 codeception

我有提交表单的下拉列表,现在问题是当我运行测试时,它会出错:

1) Failed to ensure that clients create works in tests\codeception\frontend\acceptance\ClientCrudCest::testClientCreate (.\acceptance\ClientCrudCest.php)
 Step  I click "schedule_pending"
 Fail  Link or Button by name or CSS or XPath element with 'schedule_pending' was not found.
Scenario Steps:
 13. $I->click("schedule_pending") at _pages\ClientCrudPage.php:26
 12. // I am going to submit client form with no data
 11. $I->see("Client Profile") at acceptance\ClientCrudCest.php:63
 10. $I->see("Add Client","h3") at acceptance\ClientCrudCest.php:62
 9. $I->amOnPage("/frontend/web/index-test.php/clients/create") at tion\BasePage.php:77
 8. $I->dontSeeLink("Sign In") at acceptance\ClientCrudCest.php:56

FAILURES!
Tests: 1, Assertions: 4, Failures: 1.

这是下拉按钮:

<ul class="dropdown-menu" role="menu">
      <li><a href="#" id="schedule_pending" class="enroll-client-btn">SAVE & PENDING</a></li>
      <li><a href="#" id="schedule_enrollment" class="enroll-client-btn">SAVE & ENROLLMENT</a></li>
      <li><a href="#" id="schedule_appointment" class="enroll-client-btn">SAVE & APPOINTMENT</a></li>
      <li><a href="#" id="schedule_eval" class="enroll-client-btn">SAVE & EVALUATION</a></li>
</ul>

Class ClientCrudPage:

class ClientCrudPage extends BasePage
{
    public $route = 'clients/create';

    public function submit(array $signupData)
    {
        foreach ($signupData as $field => $value) {
            $inputType = $field === 'body' ? 'textarea' : 'input';
            $this->actor->fillField($inputType . '[name="Clients[' . $field . ']"]', $value);
        }       
        $this->actor->click('schedule_pending');
    }
}

如何点击下拉链接?

1 个答案:

答案 0 :(得分:0)

Yii2模块不支持javascript,因此点击<a href="#">毫无意义。

但如果您坚持,可以点击$I->click("#schedule_pending")$I->click('SAVE & PENDING')