@@ -104,13 +104,22 @@ public function getFilters()
104
104
/**
105
105
* Get all available filters.
106
106
*
107
+ * @param string $attributeLabel
107
108
* @return array
108
109
*/
109
- public function getFilterContents ()
110
+ public function getFilterContents ($ attributeLabel )
110
111
{
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
+
114
123
foreach ($ optionContents as $ optionContent ) {
115
124
$ data [] = trim (strtoupper ($ optionContent ->getText ()));
116
125
}
@@ -128,13 +137,8 @@ public function getFilterContents()
128
137
*/
129
138
public function applyFilter ($ filter , $ linkPattern )
130
139
{
131
- $ expandFilterButton = sprintf ($ this ->optionTitle , $ filter );
132
140
$ 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 );
138
142
139
143
$ links = $ this ->_rootElement ->getElements ($ links , Locator::SELECTOR_XPATH );
140
144
foreach ($ links as $ link ) {
@@ -160,4 +164,19 @@ public function isCategoryVisible(Category $category, $qty)
160
164
Locator::SELECTOR_XPATH
161
165
)->isVisible ();
162
166
}
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
+ }
163
182
}
0 commit comments