Expects
An expectation is an assertion that a test has passed. If the assertion fails, the step is reported as failed.
#Usage
Every expectation starts with Expect::that. There are two calling conventions:
Value assertions — pass the value under test to that(), then chain the assertion:
1Expect::that($page->getPageTitle())->contains('Cart');
Target assertions — for elements, the shop or the customer, call that() with no value and pass the target (a selector or a page object) to the assertion:
1Expect::that()->elementIsVisible('#header');2Expect::that()->shopIsVisible($frontOfficeHomePage);
Every assertion also accepts an optional last argument to override the message.
#Generic
Value assertions — they test the value passed to that().
| Expect | Description |
|---|---|
contains($needle) |
The value contains the substring $needle |
notContains($needle) |
The value does not contain $needle |
startsWith($needle) |
The value starts with $needle |
endsWith($needle) |
The value ends with $needle |
equals($other) |
Equal to $other (compared after trim()) |
notEquals($other) |
Not equal to $other (compared after trim()) |
isTheSameAs($expected) |
Strict equality (===): same type and value |
isNotTheSameAs($expected) |
Strict inequality (!==) |
samePriceAs($price) |
Compares two prices numerically (tolerates "15,90 €") |
isNull() |
The value is null |
isNotNull() |
The value is not null |
isEmpty() |
The value is empty |
isNotEmpty() |
The value is not empty |
isBetween($min, $max) |
The value is between $min and $max |
isGreaterThan($other) |
The value is strictly greater than $other |
isLessThan($other) |
The value is strictly lower than $other |
isGreaterThanOrEqualTo($other) |
The value is greater than or equal to $other |
isLessThanOrEqualTo($other) |
The value is lower than or equal to $other |
1Expect::that($backOfficeProductsPage->getPageTitle())->contains($backOfficeProductsPage->pageTitle());2Expect::that($score)->isGreaterThanOrEqualTo(90);
#Elements
Target assertions — pass a DOM selector. A $timeout in milliseconds (default 30000) can be given as the second argument.
| Expect | Description |
|---|---|
elementIsVisible($selector, $timeout = 30000) |
The element matched by $selector is visible |
elementIsNotVisible($selector, $timeout = 30000) |
The element is absent or hidden |
1Expect::that()->elementIsVisible('#header .cart');
#Shop
Target assertions — pass the page object to check the shop state.
| Expect | Description |
|---|---|
shopIsInMaintenance($page, $timeout = 1000) |
The shop displays the maintenance page |
shopIsNotInMaintenance($page, $timeout = 1000) |
The shop is not in maintenance |
shopIsVisible($page, $timeout = 1000) |
The shop front is reachable |
shopIsNotVisible($page, $timeout = 1000) |
The shop front is not reachable |
1Expect::that()->shopIsNotInMaintenance($frontOfficeHomePage);
#Customer
Target assertions — pass the selector that reveals the logged-in state.
| Expect | Description |
|---|---|
customerIsLogged($selector, $timeout = 30000) |
The customer is logged in |
customerIsNotLogged($selector, $timeout = 30000) |
The customer is logged out |
1Expect::that()->customerIsLogged('.user-info a.account');
#Example
1use PrestaFlow\Library\Expects\Expect; 2 3class ModuleCustom extends Scenario 4{ 5 public function steps($testSuite) 6 { 7 $this->importPage('Modules\Custom', domain: 'Shop\Tests'); 8 $this->importPage('FrontOffice\Category'); 9 10 extract($this->pages);11 12 $testSuite13 ->it('should go to page', function () use ($modulesCustomPage) {14 $modulesCustomPage->goToPage($modulesCustomPage);15 16 Expect::that($modulesCustomPage->getPageTitle())->contains($modulesCustomPage->pageTitle());17 })18 19 ;20 21 return $testSuite;22 }23}
#Using a custom expected message
1Expect::that($productPrice)->samePriceAs($productPriceExpected, "{value} need to be like {expected}");