当前位置: 首页 > 知识库问答 >
问题:

Yii2中使用Codeception运行验收测试时出现的问题

凤高澹
2023-03-14

我试图用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

接受。一套yml就是这个:

       suite_namespace: backend\tests\acceptance

演员:验收员

模块:

enabled:

    - WebDriver:

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

什么是错的?我想要的是测试表格,看看下一页写的假期,为什么一些测试通过了,一个简单的表格没有?。你能帮我个忙吗?

共有1个答案

姜志行
2023-03-14

它的工作原理是通过代码编写一些等待,例如,一旦你调用提交表单,你把等待和它的工作

 类似资料:
  • 我使用的是高级的Yii2模板,当我在构建后运行测试时,我遇到了以下问题。 我不知道名字空间是什么,所以请你向我解释一下它是什么。 错误 codeception.yml

  • 我正在写一个简单的测试用例。我使用作曲家安装了代码欺骗。我的测试用例位于测试用例文件夹内的根文件夹中 当我尝试运行以下代码时 当我尝试在浏览器中运行代码时,我得到以下错误 在我的项目中有一个名为yiisoft\yii2-codecsion\TestCase.php的文件 我做错了什么?有人能帮忙吗。?

  • 我正在使用phpStorm IDE以及composer和codeception在我的mac机器中编写selenium验收测试。但是我无法运行我的测试。 我开始我的硒独立罐和铬驱动器在我的mac机使用下面的命令。 java-Dwebdriver。铬。driver=“/Users/krishna/Downloads/chromedriverNewChrome”-jar selenium-server-

  • 尝试设置远程代码欺骗单元测试在PhpStorm中的Yii2项目。 使用SSH,我可以登录到服务器,转到我的Yii2项目的根目录并运行:

  • 我写这篇文章是因为yii2官方文档仍然不完整,codeception文档本身指的是yii2官方文档..:)。 我有一些问题: 在我的yii2应用程序根目录中有一个目录“tests/codeception”,这意味着我的项目中已经安装了codeception 在vendor/yiisoft中还有另一个codeception目录“yii2 codeception”,它是什么 文档中说要创建yii2_b

  • 当我运行codeception测试用例时,我的日志文件中出现了这个错误。如何解决这个问题? 代码: 命令: ./vendor/bin/codecept run tests/functional/AdminPhoneTestCest.php:testUpdatePhone 日志文件中的错误: [2015-06-06 05:34:02]本地的。错误:异常'照明\会话\令牌错配异常'在 /var/www