Codeception:从其他验收测试中调用方法

Codeception: Invoke method from other acceptance test

我有多个验收测试,需要按特定顺序运行。因为他们互相依赖。现在我如何在 createstore class 中调用 tryToCreateACollection 以便我可以从那里 运行 它,以便我 运行 按我想要的顺序排列。

class CreateStoreCest
{

public function _before(AcceptanceTester $I)
{

  $I->amOnPage('http://127.0.0.1:8000/login');
  $I->submitForm('[name="login"]', [
      '_username' => 'test',
      '_password' => 'test12']);
  $I->dontSee('Invalid credentials.');
}

public function tryToCreateAStore(AcceptanceTester $I)
{
  $I->wantTo('I create a store');
    $I->click('//*[@id="dropdown-webshop"]/li[3]/a');
    $I->see('Account information');
    $I->submitForm('[name="user"]', [
            'user[first_name]' => 'TestUserFirstName',
            'user[last_name]' => 'TestUserLastName'
        ]);
      $I->see('Create store');
  $I->submitForm('[name ="webstore"]', [
      'webstore[name]' => 'TestWebstoreName',
      'webstore[description]' => 'TestWebstoreDescription',
      'webstore[phone]' => '06-12345678',
      'webstore[address][country]' => 'TestCountry',
      'webstore[address][region]' => 'TestRegion',
      'webstore[address][city]' => 'TestCity',
      'webstore[address][street]' => 'TestStreet',
      'webstore[address][number]' => 'TestNumber',
      'webstore[address][postal]' => 'TestPostal'
    ]);
  $I->click('//*[@id="dropdown-webshop"]/li[1]/a');
  $I->see('products');

}
}

public function tryToCreateACollection(AcceptanceTester $I)
{
  $I->wantTo('I want to create a collection');
  $I->click('//*[@id="mobile-demo"]/ul/a[8]');
  $I->see('collections');
  $I->click('//*[@id="content"]/div[2]/a');
  $I->submitForm('[name="category"]', [
      'category[name]' => 'TestCategory'
    ]);
  $I->click('//*[@id="mobile-demo"]/ul/li[3]/a[1]');
  $I->see('TestCategory');

  $I->amGoingTo('Edit the category');
  $I->click('//*[@id="content"]/div[1]/table/tbody/tr[2]/td[3]/a');
  $I->fillField('category[name]', 'This is edited');
  $I->attachFile('//*[@id="category_icon_picture_file"]', 'test.jpg');
  $I->click('//*[@id="category_save"]');
  $I->click('//*[@id="broukecrumbs"]/a[2]');
  $I->see('This is edited');
  $I->click('//*[@id="content"]/div[1]/table/tbody/tr[2]/td[4]/a');

}

依赖特定的测试执行顺序是一种测试味道。

在 Codeception 中重用测试代码的正确方法是步骤对象:http://codeception.com/docs/06-ReusingTestCode#StepObjects