【问题标题】:Codeception: Invoke method from other acceptance testCodeception:从其他验收测试中调用方法
【发布时间】:2016-11-02 20:55:40
【问题描述】:

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

}

【问题讨论】:

    标签: codeception


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,这正是我一直在寻找的,因为我基本上是想找到一种方法来按特定顺序执行它们
    猜你喜欢
    • 1970-01-01
    • 2014-02-01
    • 2018-10-21
    • 2017-03-25
    • 2016-11-03
    • 2014-08-17
    • 1970-01-01
    • 2013-06-10
    • 1970-01-01
    相关资源
    最近更新 更多