Selectors


#Add your own selectors

You can add these in a JSON format file present in the Tests/Selectors folder and its name must be as follows: <locale>.json (e.g.: fr.json)

Copied!
1{
2 "FrontOffice": {
3 "Product": {
4 "pageTitle": "h1.product-page-title"
5 }
6 }
7}

The structured datas will follow the namespace as this : FrontOffice\Product\Page.

#Theme selectors

PrestaShop 9 ships two front-office themes, and they do not share a markup. .add-to-cart on Classic is .product__add-to-cart-button on Hummingbird; the price that Classic renders as bare text comes wrapped in a visually-hidden label on Hummingbird. A page object written against one theme silently matches nothing on the other — click() returns false on a missing selector instead of raising, so a suite can report a passing step while the browser did nothing.

A theme is a JSON file named after the theme, holding only the selectors that differ from the built-in ones, in the same shape as the locale files above:

Copied!
1{
2 "FrontOffice": {
3 "Product": {
4 "addToCartButton": ".product__add-to-cart-button"
5 }
6 }
7}

The structure follows the page namespace, so the block above overrides addToCartButton for FrontOffice\Product\Page and leaves every other selector of that page untouched.

#Choosing the theme

There is no automatic detection. A shop can run a different theme per shop in a multistore, and guessing would be one more thing that fails quietly, so the theme is always something you state. Three ways, from the most global to the most local:

Copied!
1# .env or .env.local
2PRESTAFLOW_THEME=hummingbird
Copied!
1# one run, without touching any file
2PRESTAFLOW_THEME=hummingbird php bin/prestaflow run Scenarios
Copied!
1// one page, inside a suite
2$this->importPage('FrontOffice\Product', ['theme' => 'hummingbird']);

When nothing says otherwise, Classic is used. It is the structural baseline the built-in selectors were written against, so the default behaves exactly as it did before theme support existed.

Naming a theme that has no JSON file is not silently ignored: the run keeps going on the Classic baseline and writes one warning line to STDERR, once per page. A typo in a theme name would otherwise look like a theme with no overrides at all.

#Where it sits in the merge order

Selectors are merged from the most general source to the most specific, each tier overriding the one before it:

  1. the page's own defineSelectors()
  2. the theme files, the library's then yours (see below)
  3. the locale file, Tests/Selectors/<locale>.json
  4. the customs['selectors'] passed at import time

So a locale file still wins over a theme file, and an explicit override at import time always wins.

#Where theme files live

Two directories are searched, least specific first:

Directory Holds
the library's own Themes/ the maps PrestaFlow ships, currently hummingbird.json
your project's Tests/Themes/ your own themes, and your corrections to the shipped ones

Your file wins, key by key. A single selector that the shipped Hummingbird map gets wrong on your shop can be fixed with a Tests/Themes/hummingbird.json holding only that one key — the rest of the shipped map still applies. It is the same root as the Tests/Selectors/ folder above, so nothing new to set up.

#Writing a third-party theme

Nothing here is specific to the two themes PrestaShop ships. Dropping a Tests/Themes/panda.json into your project makes PRESTAFLOW_THEME=panda work, with no PHP to write and no page to subclass — which is the point of keeping the overrides in data rather than in code.