Search code examples
javascriptselenium-webdrivercodeceptionacceptance-testing

Prevent clear cookies codeception webdriver


I have to test single page JavaScript application. After complete test action look like WebDriver clear cookies. Is possible prevent it? I need run tests without isolation from each other.

My test file:

<?php


class ClientGroenCest
{
    protected $selectors = [
        'clientTableElements' => '.b-content__clients > div:first-child > div:first-child .b-table-v2.b-table__clients tbody .nano tr',
        'clientTableFirstElement' => '.b-content__clients > div:first-child > div:first-child .b-table-v2.b-table__clients tbody .nano tr:first-child',
    ];

    public function _before(AcceptanceTester $I)
    {
    }

    public function _after(AcceptanceTester $I)
    {
    }

        // tests
public function login(AcceptanceTester $I)
{
    $I->amOnPage('/');
    $I->fillField('#loginform-email', '[email protected]');
    $I->fillField('#loginform-password', 'qweewq');
    $I->wait(1);
    $I->click('button[type="submit"]');
    $I->dontSeeCurrentUrlEquals('/login');
    $I->dontSeeCurrentUrlEquals('/site/login');
    $I->dontSeeCurrentUrlEquals('/');
}

public function checkNumberOfClients(AcceptanceTester $I)
{
    $I->click($this->selectors['clientTableFirstElement']);
    $I->wait(5);
}

acceptance.suite.yml:

class_name: AcceptanceTester
modules:
    enabled:
        - WebDriver:
            url: https://crm.loc
            browser: chrome
            delay: 5000
            window_size: maximize
            capabilities:
                acceptSslCerts: true
                trustAllSSLCertificates: true
        - \Helper\Acceptance
        - Yii2:
            configFile: 'config/test.php'
            part: ORM # allow to use AR methods
            cleanup: false # don't wrap test in transaction
            entryScript: index-test.php

Solution

  • Need use clear_cookies to save state of actions.

    http://codeception.com/docs/modules/WebDriver#Configuration