Scenarios & pages
On this page
A scenario is a sequence of steps that several suites can reuse, for example "add a product to the cart and check out". A page (a page object) groups the URL, the selectors and the methods of one page of your shop. Find both in the sidebar, under Scenarios and Pages.
#Scenarios
#Create a scenario
Click the "+" (New scenario) next to Scenarios in the sidebar. Enter a Scenario name, for example "Order with a promo code".
Under Start from, pick a starting point:
- Empty scenario: you add the steps in the editor.
- Copy a project scenario: reuses a scenario of the project under a new name. The copy keeps all of the code; only the namespace and the class name change.
- Copy a library scenario: reuses a scenario provided by PrestaFlow, which you then adapt.
Advanced options shows the PHP class name (FQCN). It is built from the scenario name,
with a number added if it is already taken. If you type it yourself, it must be free and
include a namespace, for example Tests\Scenarios\OrderWithAPromoCode.
Then click Create scenario.
#Edit a scenario
The scenario editor has these parts:
- Metadata.
- Referenced pages: use "Use a page…" to pick the pages the scenario relies on.
- Parameters: named values for the scenario. Each one has a Key, a Value and a Type: Text, Number, Boolean, Null or Array (JSON). A Description is optional.
- Used elements: the
useimports, as in a suite. - Steps: each step is a title and a PHP body.
The PHP of every step is checked when you save. A mistake shows a message such as "Invalid PHP syntax at line …", with the line number.
When you only want to read a scenario, the view page shows its "PHP source" and a "Copy FQCN" button.
#Delete a scenario
Remove the scenario from your suites before you delete it, or those suites will fail when they run.
#Pages
A page object describes one page of the shop. Its class name follows the page it
represents, for example Tests\Pages\v7\FrontOffice\Cart\Page. In the library's page
objects, the v7, v8 or v9 segment matches the PrestaShop major version.
#Create a page
Click the "+" (New page) next to Pages in the sidebar. Enter a Display name and an FQCN (a fully qualified class name, like the one above), then pick Blank or Clone a page, and click Create page.
#Edit a page
The page editor has these parts:
- Static properties: the URL of the page and its page title.
- Selectors: a list of keys, each with a CSS selector.
- Methods: see below.
- Used elements: the
useimports.
Methods
A method has:
- a name, starting with a lowercase letter and made of letters and digits;
- a visibility: public, protected or private;
- a static option;
- Parameters;
- a Returns type.
The body of a method is built from actions. Add them with + Call, + Expect, + Assign and + Return. You can also add a free-code block when an action does not fit.