是否可以使用扩展父类的Cest文件并使用通用测试" login"其他测试依赖于使用@depends
所以我的Cest文件看起来与本文中的文件相似,它解释了如何在另一个测试中登录并重新使用cookie - https://stackoverflow.com/a/25547268/682754
我已经有了这个普通班级但是孩子班的考试没有运行和输出......这个考试取决于' commonCest :: login'通过。
<?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
}
?>
答案 0 :(得分:0)
在cest目录下根本没有commonCest。然后,将对在您的cest目录中扩展commonCest的类的每种情况下的每种情况运行登录,因为它们存在于所有目录中。但是,您不应为此使用@depends。相反,登录名应该在您的演员或助手中,并且应该在父类中从_before调用。
或者仅使用stepobjects https://codeception.com/docs/06-ReusingTestCode#stepobjects并从_before调用所需的函数