对Cest测试中的条件行为以编程方式访问“ --skip-group”设置

时间:2019-02-13 08:00:33

标签: codeception

我想根据“ --skip-group”设置在不同的环境/阶段以不同的断言运行Codeception CEST测试,因为基于此设置,还有一些完整的测试会被跳过:

  • 在非生产环境/阶段(在没有任何“ --skip-group”设置的情况下执行测试),我想使用seeInDatabase进行防御性很强/严格的断言
  • 由于生产环境中的安全性原因,不允许这种数据库访问(使用“ --skip-group”设置执行测试)

我尝试过:

这些是我现在重复的测试,我只想替换为带有条件调用seeFormSubmissionInDatabase的测试(请参阅“ //!HERE”)

  /**
   * @param Front\Forms\ContactForm\PageObject $contactFormPage
   * @group nonProductionTest
   */
  public function submitContactFormSuccessful(Front\Forms\ContactForm\PageObject $contactFormPage) {
    $firstName = 'User' . uniqid();
    $contactFormPage->openPage();
    $contactFormPage->fillFormWithValidData($firstName);
    $contactFormPage->fillFormWithPrivacyAcceptance();
    $contactFormPage->submitForm();
    $contactFormPage->seeValidFormSubmission();
    // TODO: instead of "@group nonProductionTest" for test and duplication submitContactFormSuccessfulWithoutDb()
    // if not group skip nonProductionTest then also check
    $contactFormPage->seeFormSubmissionInDatabase($firstName); // ! HERE
  }

  /**
   * TODO: Duplication of submitContactFormSuccessful() test above
   * @param Front\Forms\ContactForm\PageObject $contactFormPage
   */
  public function submitContactFormSuccessfulWithoutDb(Front\Forms\ContactForm\PageObject $contactFormPage) {
    $firstName = 'User' . uniqid();
    $contactFormPage->openPage();
    $contactFormPage->fillFormWithValidData($firstName);
    $contactFormPage->fillFormWithPrivacyAcceptance();
    $contactFormPage->submitForm();
    $contactFormPage->seeValidFormSubmission();
  }

0 个答案:

没有答案
相关问题