在Yii2中使用Codeception运行验收测试时遇到问题

时间:2018-11-16 12:27:08

标签: selenium yii2 codeception

我正在尝试使用代码接收进行一些测试,而当我尝试测试表单时,总是会失败,而且我也不知道为什么。与其余的,他们被通过。测试代码是这样的:

<?php namespace backend\tests\acceptance;

use \AcceptanceTester;

 class HomeDriverCest

{

   public function _before(AcceptanceTester $I){}

   // tests
   public function tryToTest(AcceptanceTester $I)
   {
     $I->amGoingTo("Check login on backend"); 
     $I->see("Login");
     $I->amOnPage('/site/login'); 
     $I->wait(5);
     $I->see("Email");
     $I->clearField('LoginForm[username]');
     $I->reloadPage();

     $I->submitForm('#login-form', array(
         'LoginForm[username]' => 'pepe@xxx.es',
         'LoginForm[password]' => '123456'
     ), 'submitButton');

    $I->see("Holidays");
 }
}

当我使用命令../vendor/bin/run -vvv --html --debug运行测试时,我有以下日志:

 ....
 12:52 (hace 10 minutos)
 para mí

 Home2Cest: Try to test
 Signature: backend\tests\acceptance\Home2Cest:tryToTest
 Test: tests/acceptance/Home2Cest.php:tryToTest
  Scenario --
   Destroying application
   Starting application
   [ConnectionWatcher] watching new connections
   [Fixtures] Loading fixtures
   [Fixtures] Done
   [TransactionForcer] watching new connections
   I am on page "/site/login"
   [GET] http://backend.smartholidays.test/site/login
   I see "Login"
   PASSED
   [TransactionForcer] no longer watching new connections
   Destroying application
   [ConnectionWatcher] no longer watching new connections
   [ConnectionWatcher] closing all (0) connections
   HomeDriverCest: Try to test
   Signature: backend\tests\acceptance\HomeDriverCest:tryToTest
   Test: tests/acceptance/HomeDriverCest.php:tryToTest
   Scenario --
   Destroying application
   Starting application
   [ConnectionWatcher] watching new connections
   [Fixtures] Loading fixtures
   [Fixtures] Done
   [TransactionForcer] watching new connections
   I am going to Check login on backend
   I see "Login"
   I am on page "/site/login"
   [GET] http://backend.smartholidays.test/site/login
   I wait 5
   I see "Email"
   I clear field "LoginForm[username]"
   I reload page
   I submit form "#login-form",{"LoginForm[username]":"pepe@xxxx.es","LoginForm[password]":"123456"},"submitButton"
   [Uri] http://backend.smartholidays.test/site/login
   [Method] post
   [Parameters]
    {"LoginForm[username]":"pepe@xxxx.es","LoginForm[password]":"123456"}
   [Page] /site/login
   I see "Holidays"
  [Selenium server Logs]
   11:35:23.268 INFO - Capabilities are: {
     "browserName": "chrome"
   }
   11:35:23.268 INFO - Matched factory org.openqa.selenium.grid.session.remote.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
   11:35:23.738 INFO - Detected dialect: OSS
   11:35:23.765 INFO - Started new session efab3c8277ad657b2dd22db4602e1b08 (org.openqa.selenium.chrome.ChromeDriverService)
   [Selenium browser Logs]
    11:35:25.449 WARNING - http://backend.smartholidays.test/site/login - This page includes a password or credit card input in a non-secure context. A warning has been added to the URL bar. For more information, see .....

    11:35:25.939 WARNING - http://backend.smartholidays.test/site/login - This page includes a password or credit card input in a non-secure context. A warning has been added to the URL bar. For more information, see .....

    11:35:31.598 WARNING - http://backend.smartholidays.test/site/login - This page includes a password or credit card input in a non-secure context. A warning has been added to the URL bar. For more information, see .....

    11:35:32.688 WARNING - http://backend.smartholidays.test/site/login - This page includes a password or credit card input in a non-secure context. A warning has been added to the URL bar. For more information, see ....

    [Selenium driver Logs]  EMPTY

      Screenshot and page source were saved into '/var/www/vhosts/smartholidays.test/backend/tests/_output/' dir

      FAIL

acceptance.suite.yml是这个:

       suite_namespace: backend\tests\acceptance

actor:AcceptanceTester

模块:

enabled:

    - WebDriver:

        url: http://backend.smartholidays.test
        browser: chrome
    - Yii2:
        part: init
        cleanup: true
    - \Helper\Acceptance

怎么了?我想要的是测试表格,然后看到下一页写的假期,为什么要通过一些测试而没有一个简单的表格?你有什么想法可以帮我吗?

1 个答案:

答案 0 :(得分:0)

它可以在代码中编写一些等待,例如,一旦调用了commitForm,就放置了等待,它就可以工作了