Page
On this page
#Native pages
PrestaFlow includes a series of so-called native pages.
These are the pages found in your PrestaShop store, such as product pages, categories, CMS, contact, etc.
#Import page
1$this->importPage('FrontOffice\Category');
In order to use the imported pages, it is necessary to extract them!
1extract($this->pages);
Once imported, you will be able to use a page in your steps via a use within the step closure.
The variable name is defined as follows:
- FrontOffice\Category => $frontOfficeCategoryPage
- FrontOffice\Product => $frontOfficeProductPage
#Custom page
#Create
1namespace Shop\Tests\Pages\v9\Modules\Custom; 2 3use PrestaFlow\Library\Pages\v9\FrontOffice\Page as BasePage; 4 5class Page extends BasePage 6{ 7 public string $url = 'guest-tracking'; 8 public string $pageTitle = 'Guest Order Tracking'; 9 10 public function defineMessages()11 {12 return [13 'addedToCart' => $this->translate('Product successfully added to your shopping cart'),14 ];15 }16 17 public function getPrice()18 {19 return $this->getTextContent($this->getSelector('currentProductPrice'));20 }21 22 public function addToCart(int $quantity = 1)23 {24 $this->setValue($this->getSelector('quantityWantedInput'), $quantity);25 26 $this->click($this->getSelector('addToCartButton'));27 28 return ltrim($this->getTextContent($this->getSelector('modalTitle')));29 }30}
#Import page
To import a custom page, you use the same call as to import a regular page, adding the domain it applies to.
1$this->importPage('Modules\Custom', domain: 'Shop\Tests');
After the extraction of the page, you can use it as this :
1$testSuite2->it('should go to page', function () use ($modulesCustomPage) {3 $modulesCustomPage->goToPage($modulesCustomPage);4 5 Expect::that($modulesCustomPage->getPageTitle())->contains($modulesCustomPage->pageTitle());6})7 8;
#Back Office pages
In addition to Front Office pages, PrestaFlow ships native Back Office pages, automatically resolved for your PrestaShop major version (1.7 / 8 / 9):
| Page | Imported variable | Admin menu |
|---|---|---|
BackOffice\Login |
$backOfficeLoginPage |
Login screen |
BackOffice\Dashboard |
$backOfficeDashboardPage |
Dashboard |
BackOffice\Products |
$backOfficeProductsPage |
Catalog › Products |
BackOffice\Orders |
$backOfficeOrdersPage |
Orders › Orders |
BackOffice\Categories |
$backOfficeCategoriesPage |
Catalog › Categories |
BackOffice\Customers |
$backOfficeCustomersPage |
Customers › Customers |
BackOffice\Modules |
$backOfficeModulesPage |
Modules › Module Manager |
BackOffice\Carriers |
$backOfficeCarriersPage |
Shipping › Carriers |
Every page above exposes menu navigation through goTo(). The Products page additionally provides list & CRUD helpers (see below); the other pages currently focus on navigation, ready to be extended with your own helpers in a custom page.
#Import
They are imported exactly like Front Office pages:
1$this->importPage('BackOffice\Products');2 3extract($this->pages);
The variable name follows the same rule:
- BackOffice\Products => $backOfficeProductsPage
- BackOffice\Orders => $backOfficeOrdersPage
#Menu navigation
Each Back Office page knows its own admin menu entry. Call goTo() to open it through the main menu — the parent menu is expanded automatically when needed:
1$testSuite2->it('should open the Products page', function () use ($backOfficeProductsPage) {3 $backOfficeProductsPage->goTo();4 5 Expect::that($backOfficeProductsPage->getPageTitle())->contains($backOfficeProductsPage->pageTitle());6})7 8;
You can still navigate directly through the URL with goToPage(), like any other page.
#Products: list & CRUD
The Products page exposes helpers to filter the grid and create or delete products:
| Method | Description |
|---|---|
goTo() |
Open the Products page through the Catalog menu |
filterByName(string $name) |
Filter the grid by product name |
resetFilter() |
Reset the grid filters |
getListCount(): int |
Number of products in the current listing |
getProductNameInList(int $row = 1): string |
Name of the product on the given row |
goToNewProduct() |
Open the "new product" form |
createProduct(string $name, float $price = 0, int $quantity = 0) |
Create a product and save it |
deleteProduct(int $row = 1) |
Delete the product on the given row |
getSuccessMessage(): string |
Text of the success alert after an action |
1$testSuite 2->it('should create a product', function () use ($backOfficeProductsPage) { 3 $backOfficeProductsPage->goTo(); 4 $backOfficeProductsPage->createProduct('My test product', 19.90, 100); 5 6 Expect::that($backOfficeProductsPage->getSuccessMessage())->isNotEmpty(); 7}) 8 9->it('should find it in the list', function () use ($backOfficeProductsPage) {10 $backOfficeProductsPage->goTo();11 $backOfficeProductsPage->filterByName('My test product');12 13 Expect::that($backOfficeProductsPage->getListCount())->isGreaterThan(0);14})15 16;