@@ -104,13 +104,22 @@ public function getFilters()
104104 /**
105105 * Get all available filters.
106106 *
107+ * @param string $attributeLabel
107108 * @return array
108109 */
109- public function getFilterContents ()
110+ public function getFilterContents ($ attributeLabel )
110111 {
111- $ this ->waitForElementVisible ($ this ->loadedNarrowByList );
112- $ optionContents = $ this ->_rootElement ->find ($ this ->optionContent , Locator::SELECTOR_XPATH );
113- $ data =[];
112+ $ data = [];
113+
114+ if (trim ($ attributeLabel ) === '' ) {
115+ return $ data ;
116+ }
117+
118+ $ link = sprintf ($ this ->filterLink , $ attributeLabel );
119+ $ this ->openFilterContainer ($ attributeLabel , $ link );
120+
121+ $ optionContents = $ this ->_rootElement ->getElements ($ link , Locator::SELECTOR_XPATH );
122+
114123 foreach ($ optionContents as $ optionContent ) {
115124 $ data [] = trim (strtoupper ($ optionContent ->getText ()));
116125 }
@@ -128,13 +137,8 @@ public function getFilterContents()
128137 */
129138 public function applyFilter ($ filter , $ linkPattern )
130139 {
131- $ expandFilterButton = sprintf ($ this ->optionTitle , $ filter );
132140 $ links = sprintf ($ this ->filterLink , $ filter );
133-
134- $ this ->waitForElementVisible ($ this ->loadedNarrowByList );
135- if (!$ this ->_rootElement ->find ($ links , Locator::SELECTOR_XPATH )->isVisible ()) {
136- $ this ->_rootElement ->find ($ expandFilterButton , Locator::SELECTOR_XPATH )->click ();
137- }
141+ $ this ->openFilterContainer ($ filter , $ links );
138142
139143 $ links = $ this ->_rootElement ->getElements ($ links , Locator::SELECTOR_XPATH );
140144 foreach ($ links as $ link ) {
@@ -160,4 +164,19 @@ public function isCategoryVisible(Category $category, $qty)
160164 Locator::SELECTOR_XPATH
161165 )->isVisible ();
162166 }
167+
168+ /**
169+ * @param string $filter
170+ * @param string $link
171+ * @return void
172+ */
173+ private function openFilterContainer ($ filter , $ link )
174+ {
175+ $ expandFilterButton = sprintf ($ this ->optionTitle , $ filter );
176+
177+ $ this ->waitForElementVisible ($ this ->loadedNarrowByList );
178+ if (!$ this ->_rootElement ->find ($ link , Locator::SELECTOR_XPATH )->isVisible ()) {
179+ $ this ->_rootElement ->find ($ expandFilterButton , Locator::SELECTOR_XPATH )->click ();
180+ }
181+ }
163182}
0 commit comments