Scenario
A scenario is a set of steps.
Creating scenarios allow you to use them in one line instead of duplicate each steps that it contains.
#Creating scenario
You need to extends the Scenario class and add the steps() method.
Copied!
1use PrestaFlow\Library\Scenarios\Scenario;2 3class AddProductToCart extends Scenario4{5 public function steps($testSuite)6 {7 return $testSuite;8 }9}
You can now write your steps as you will do inside a test suite.
Copied!
1public function steps($testSuite) 2{ 3 $testSuite->importPage('FrontOffice\Category'); 4 $testSuite->importPage('FrontOffice\Product'); 5 6 extract($testSuite->pages); 7 8 $testSuite 9 ->it('go to category page', function () use ($frontOfficeCategoryPage) {10 $frontOfficeCategoryPage->goToPage('category', (int) $this->getParam('categoryId'));11 12 Expect::that($frontOfficeCategoryPage->getListingTitle())->contains($this->getParam('categoryTitle'));13 })14 ->it('go to product page', function () use ($frontOfficeCategoryPage, $frontOfficeProductPage) {15 $frontOfficeCategoryPage->goToProduct((int) $this->getParam('productIndex'));16 17 Expect::that($frontOfficeProductPage->getTitle())->contains($this->getParam('productTitle'));18 })19 ->it('add to cart', function () use ($frontOfficeProductPage) {20 $textResult = $frontOfficeProductPage->addToCart((int) $this->getParam('cartQuantity'));21 22 Expect::that($textResult)->contains($frontOfficeProductPage->message('addedToCart'));23 });24 25 return $testSuite;26}
#Use
Copied!
1->scenario(ModuleCustom::class)
#Parameters
A scenario is a make to re-use steps.
As each steps could be taking one or more parameters distinctly, you can add a array of parameters.
#Declare parameters
Copied!
1public $params = [2 'categoryId' => 3,3 'categoryTitle' => 'Vêtements',4 'productIndex' => 1,5 'productTitle' => 'T-shirt imprimé colibri',6 'cartQuantity' => 1,7];
You will define the key as a parameter and you can attach it a default value.
#Pass parameters in test suite
Copied!
1->scenario(ModuleCustom::class, [2 'locale' => 'en',3 'useIsoCode' => true,4])