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
#Which class gets loaded
importPage() loads the page from the namespace of your PrestaShop major
version: FrontOffice\Category becomes
PrestaFlow\Library\Pages\v9\FrontOffice\Category\Page on PrestaShop 9.
The page implementations live in Pages\v9. Pages\v7 and Pages\v8 hold
pages that delegate to them, so every page that existed before 1.8.0 still
resolves on every version. Pages added since then may exist for PrestaShop 9
only, as the table below says.
Pages\Common only keeps the two area base classes,
Common\FrontOffice\Page and Common\BackOffice\Page.
If you referenced a concrete page class directly, such as
PrestaFlow\Library\Pages\Common\FrontOffice\Home\Page, switch to its
Pages\v9 counterpart or go through importPage(), which needs no change.
#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}
Extend the area base of your version (Pages\v9\FrontOffice\Page,
Pages\v9\BackOffice\Page, and their v7 / v8 counterparts). Version
1.8.0 shipped without the two v9 bases, which also broke
importPage('FrontOffice') on PrestaShop 9: upgrade to 1.8.1, or extend
Pages\Common\FrontOffice\Page / Pages\Common\BackOffice\Page meanwhile.
#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 |
BackOffice\Theme |
$backOfficeThemePage |
Design › Theme & Logo (PrestaShop 9, since 1.8.0) |
BackOffice\CheckoutLayout |
$backOfficeCheckoutLayoutPage |
Design › Theme & Logo › Checkout (PrestaShop 9.2, since 1.8.0) |
BackOffice\OrderSettings |
$backOfficeOrderSettingsPage |
Shop Parameters › Order Settings (PrestaShop 9, since 1.8.0) |
BackOffice\Multistore |
$backOfficeMultistorePage |
Advanced Parameters › Multistore (PrestaShop 9, since 1.8.0) |
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;