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

时间:2016-06-30 16:20:25

标签: codeception

我有多个验收测试,需要按特定顺序运行。因为他们互相依赖。现在我如何调用createstore类中的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');

}

1 个答案:

答案 0 :(得分:0)

依靠特定的测试顺序执行是一种测试气味。

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