Codeception - 依靠测试父类中

问题描述 投票:2回答:1

是否有可能有一个扩展父类CEST文件,并使用一个通用的测试“登录”,其他测试依赖对使用@depends

所以我CEST文件看起来类似于一个在这篇文章中介绍如何登录,并在另一个试验重复使用cookie中 - https://stackoverflow.com/a/25547268/682754

我有这个共同的类,但在子类测试不运行和输出...此测试取决于“commonCest ::登录”通过。

<?php

class commonCest {

    const COOKIE_NAME = 'PHPSESSID';

    protected $cookie;

    /**
     * Most tests will need to depend on this function as it logs the user in and stores the session cookie, use the
     * "@depends" phpdoc comment
     *
     * The cookie in then  re-used by calling the following in tests:
     *
     *     $I->setCookie(self::COOKIE_NAME, $this->cookie);
     *
     * @param \AcceptanceTester $I
     */
    public function login(AcceptanceTester $I) {
        $I->wantTo('Login');
        $I->amOnPage('/login');
        $I->fillField(array('name' => 'username'), 'aaaaaa');
        $I->fillField(array('name' => 'password'), 'abcdef');
        $I->click('.form-actions button');
        $I->seeElement('.username');
        $this->cookie = $I->grabCookie(self::COOKIE_NAME);
    }
}

<?php
use \AcceptanceTester;

class rolesCest extends commonCest 
{

    /**
     * @depends login (This doesn't work)
     * @depends commonCest:login (This doesn't work)
     * @depends commonCest::login (This doesn't work)
     */
    public function listUsers(AcceptanceTester $I)
    {
        // tests
    }

?>
php testing selenium-webdriver codeception acceptance-testing
1个回答
0
投票

根本就没有你的CEST目录下commonCest。登录,然后会在你的CEST目录扩展commonCest,因为它在所有的人都存在着一类的每一种情况下运行。但是,您不应该使用@depends这一点。登录而是应该在你的演员或帮手,而应该从你的父类_before调用。

或者只是使用stepobjects https://codeception.com/docs/06-ReusingTestCode#stepobjects和_before打电话给你所需要的功能

© www.soinside.com 2019 - 2024. All rights reserved.