N
N
Nikolai Konyukhov2016-09-06 17:06:16
PHP
Nikolai Konyukhov, 2016-09-06 17:06:16

Codeception acceptance - annotations before, after, depends do not work, what could be the problem?

I am using Codeception version 2.2.4.
I don’t want to rely on chance when executing a test and I’m trying to indicate the dependencies of the tests among themselves and the order of execution using annotations:

class TsdPricetagCest extends ValidateFormCest
{
    public function _before(AcceptanceTester $I)
    {
        $I->login();
    }

    public function _after(AcceptanceTester $I)
    {
    }

    /**
     * в конце теста сохраняет валидные значения
     * @example {"importFilesDestinationFolder":{"type":"path", "value":"C:\\tmp\\tsd\\import"}, "archiveExpirationDate":{"type":"day", "min":1, "max":365, "value":1}, "archiveDestinationFolder":{"type":"path", "value":"C:\\tmp\\tsd\\archive"}, "logsDestinationFolder":{"type":"path", "value":"C:\\tmp\\tsd\\logs"}}
     * @param AcceptanceTester     $I
     * @param \Codeception\Example $example
     */
    public function testSettingsValidation(AcceptanceTester $I, \Codeception\Example $example)
    {
        $I->wantTo('test settings validation');
        $I->amOnPage('index.php?r=tsd/settings/index');
        $I->waitForElement(\Codeception\Util\Locator::contains('h1', 'Настройки'));

        $this->testFormValidation($I, 'TsdPricetagForm', $example);

        $I->wantTo('test template alias validation');
        $I->click(Locator::contains('#content_templatesCollapseable a', 'Добавить шаблоны'));
        $I->waitForElementVisible('#templatesDialog', $I::TIMEOUT);
        $I->click(Locator::elementAt('#templatesGrid .items tbody tr', 1));
        $I->seeCheckboxIsChecked('#checkboxTemplatesColumn_0');

        $I->click('#templateDialogSelect');
        $I->waitForElementNotVisible('#templatesDialog');

        $I->waitForElement('#templatesCollapseable div.ym-grid');

        $fieldSelector = '#templatesCollapseable div.ym-grid input[type="text"]';
        $templateFieldValidator = $this->validationHelper->createValidator($fieldSelector, array('type' => 'length', 'min' => 1, 'max' => 1, 'value' => 1));
        $templateFieldValidator->isSelectorXPath = true;
        $templateFieldValidator->validateWithSubmit = true;
        $templateFieldValidator->submitButton = '#save';
        $templateFieldValidator->validate($I);

        $I->wait($I::WAIT_A_SEC);
    }

    /**
     * @param AcceptanceTester $I
     */
    public function testSettingsSaveCorrectly(AcceptanceTester $I)
    {
        $I->wantTo('test settings validation');
        $I->amOnPage('index.php?r=tsd/settings/index');

        $I->seeInField('#TsdPricetagForm_importFilesDestinationFolder', 'C:\tmp\tsd\import');
        $I->seeInField('#TsdPricetagForm_archiveExpirationDate', '1');
        $I->seeInField('#TsdPricetagForm_archiveDestinationFolder', 'C:\tmp\tsd\archive');
        $I->seeInField('#TsdPricetagForm_logsDestinationFolder', 'C:\tmp\tsd\logs');
        $I->seeInField('#templatesCollapseable .ym-grid input[type="text"]', '1');
    }
}

The settings validation test must run after and depends on testSettingsValidation.
pointing
/**
     * @depends testSettingsValidation
     * @param AcceptanceTester $I
     */
    public function testSettingsSaveCorrectly(AcceptanceTester $I)

The test is marked as skipped and not executed, the console output is:
SKIPPED: Dependent test for OperationalActivity\TsdPricetagCest:testSettingsValidation not found
indicating
/**
     * @depends  OperationalActivity\TsdPricetagCest::testSettingsValidation
     * @param AcceptanceTester $I
     */
    public function testSettingsSaveCorrectly(AcceptanceTester $I)

I see: SKIPPED: This test depends on OperationalActivity\ TsdPricetagCest
::testSettingsValidation to pass although
the test was executed before . made a mistake
@after@before

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolai Konyukhov, 2016-09-08
@heahoh

As it turned out, using the before, after annotations together with the example injection does not work - the annotations work fine without them.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question