2016-06-10 257 views
1

我有一个下拉的提交表单上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> 

类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'); 
    } 
} 

如何执行点击下拉链接?

回答

0

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

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

+0

请单击它看到这个http://www.yiiframework.com/forum/index.php/topic/71289-how-i-can- use-i-in-clientcrudpage-extend-basepage/ –

+0

查看http://codeception.com/docs/06-ReusingTestCode#PageObjects中的登录方法 – Naktibalda