@@ -24,31 +24,31 @@ public function getRouteName(): string
2424
2525 public function countProductsItems (): int
2626 {
27- $ productsList = $ this ->getDocument ()-> find ( ' css ' , ' # products ' );
27+ $ productsList = $ this ->getElement ( ' products ' );
2828
29- $ products = $ productsList ->findAll ('css ' , '.card ' );
29+ $ products = $ productsList ->findAll ('css ' , '[data-test-product] ' );
3030
3131 return count ($ products );
3232 }
3333
3434 public function getFirstProductNameFromList (): string
3535 {
36- $ productsList = $ this ->getDocument ()-> find ( ' css ' , ' # products ' );
36+ $ productsList = $ this ->getElement ( ' products ' );
3737
38- return $ productsList ->find ('css ' , '.card :first-child . content > a ' )->getText ();
38+ return $ productsList ->find ('css ' , '[data-test-product] :first-child [data-test-product- content] > a ' )->getText ();
3939 }
4040
4141 public function getLastProductNameFromList (): string
4242 {
43- $ productsList = $ this ->getDocument ()-> find ( ' css ' , ' # products ' );
43+ $ productsList = $ this ->getElement ( ' products ' );
4444
45- return $ productsList ->find ('css ' , '.card :last-child . content > a ' )->getText ();
45+ return $ productsList ->find ('css ' , '[data-test-product] :last-child [data-test-product- content] > a ' )->getText ();
4646 }
4747
4848 public function search (string $ name ): void
4949 {
5050 $ this ->getDocument ()->fillField ('criteria_search_value ' , $ name );
51- $ this ->getDocument ()->pressButton ( ' Search ' );
51+ $ this ->getDocument ()->find ( ' css ' , ' [data-test-search] ' )-> submit ( );
5252 }
5353
5454 public function sort (string $ orderNumber ): void
@@ -58,35 +58,37 @@ public function sort(string $orderNumber): void
5858
5959 public function clearFilter (): void
6060 {
61- $ this ->getDocument ( )->clickLink ( ' Clear ' );
61+ $ this ->getElement ( ' clear ' )->click ( );
6262 }
6363
6464 public function isProductOnList (string $ productName ): bool
6565 {
66- return null !== $ this ->getDocument ()->find ('css ' , sprintf ('.sylius-product-name:contains("%s") ' , $ productName ));
66+ $ element = $ this ->getDocument ()->find ('css ' , sprintf ('[data-test-product-name="%s"] ' , $ productName ));
67+
68+ return ($ element !== null ) ? true : false ;
6769 }
6870
6971 public function isEmpty (): bool
7072 {
71- return false !== strpos ($ this ->getDocument ()->find ('css ' , '. message ' )->getText (), 'There are no results to display ' );
73+ return false !== strpos ($ this ->getDocument ()->find ('css ' , '[data-test-flash- message] ' )->getText (), 'There are no results to display ' );
7274 }
7375
7476 public function getProductPrice (string $ productName ): string
7577 {
76- $ container = $ this ->getDocument ()->find ('css ' , sprintf ('.sylius- product-name:contains( "%s") ' , $ productName ))-> getParent ( );
78+ $ element = $ this ->getDocument ()->find ('css ' , sprintf ('[data-test- product-name= "%s"] ' , $ productName ));
7779
78- return $ container -> find ('css ' , '.sylius- product-price ' )->getText ();
80+ return $ element -> getParent ()-> find ('css ' , '[data-test- product-price] ' )->getText ();
7981 }
8082
8183 public function isProductOnPageWithName (string $ name ): bool
8284 {
83- return null !== $ this ->getDocument ()->find ('css ' , sprintf ('.content > a:contains( "%s") ' , $ name ));
85+ return null !== $ this ->getDocument ()->find ('css ' , sprintf ('[data-test-product-name= "%s"] ' , $ name ));
8486 }
8587
8688 public function hasProductsInOrder (array $ productNames ): bool
8789 {
88- $ productsList = $ this ->getDocument ()-> find ( ' css ' , ' # products ' );
89- $ products = $ productsList ->findAll ('css ' , '.card . content > .sylius- product-name ' );
90+ $ productsList = $ this ->getElement ( ' products ' );
91+ $ products = $ productsList ->findAll ('css ' , '[data-test-product- content] > [data-test- product-name] ' );
9092
9193 foreach ($ productNames as $ key => $ value ) {
9294 if ($ products [$ key ]->getText () !== $ value ) {
@@ -96,4 +98,12 @@ public function hasProductsInOrder(array $productNames): bool
9698
9799 return true ;
98100 }
101+
102+ protected function getDefinedElements (): array
103+ {
104+ return array_merge (parent ::getDefinedElements (), [
105+ 'clear ' => '[data-test-clear] ' ,
106+ 'products ' => '[data-test-products] ' ,
107+ ]);
108+ }
99109}
0 commit comments