|
@@ 137-174 (lines=38) @@
|
| 134 |
|
* |
| 135 |
|
* @BeforeStep |
| 136 |
|
*/ |
| 137 |
|
public function handleAjaxBeforeStep(StepEvent $event) { |
| 138 |
|
try{ |
| 139 |
|
$ajaxEnabledSteps = $this->getMainContext()->getAjaxSteps(); |
| 140 |
|
$ajaxEnabledSteps = implode('|', array_filter($ajaxEnabledSteps)); |
| 141 |
|
|
| 142 |
|
if (empty($ajaxEnabledSteps) || !preg_match('/(' . $ajaxEnabledSteps . ')/i', $event->getStep()->getText())) { |
| 143 |
|
return; |
| 144 |
|
} |
| 145 |
|
|
| 146 |
|
$javascript = <<<JS |
| 147 |
|
if ('undefined' !== typeof window.jQuery && 'undefined' !== typeof window.jQuery.fn.on) { |
| 148 |
|
window.jQuery(document).on('ajaxStart.ss.test.behaviour', function(){ |
| 149 |
|
window.__ajaxStatus = function() { |
| 150 |
|
return 'waiting'; |
| 151 |
|
}; |
| 152 |
|
}); |
| 153 |
|
window.jQuery(document).on('ajaxComplete.ss.test.behaviour', function(e, jqXHR){ |
| 154 |
|
if (null === jqXHR.getResponseHeader('X-ControllerURL')) { |
| 155 |
|
window.__ajaxStatus = function() { |
| 156 |
|
return 'no ajax'; |
| 157 |
|
}; |
| 158 |
|
} |
| 159 |
|
}); |
| 160 |
|
window.jQuery(document).on('ajaxSuccess.ss.test.behaviour', function(e, jqXHR){ |
| 161 |
|
if (null === jqXHR.getResponseHeader('X-ControllerURL')) { |
| 162 |
|
window.__ajaxStatus = function() { |
| 163 |
|
return 'success'; |
| 164 |
|
}; |
| 165 |
|
} |
| 166 |
|
}); |
| 167 |
|
} |
| 168 |
|
JS; |
| 169 |
|
$this->getSession()->wait(500); // give browser a chance to process and render response |
| 170 |
|
$this->getSession()->executeScript($javascript); |
| 171 |
|
}catch(\WebDriver\Exception $e){ |
| 172 |
|
$this->logException($e); |
| 173 |
|
} |
| 174 |
|
} |
| 175 |
|
|
| 176 |
|
/** |
| 177 |
|
* Wait for the __ajaxStatus()to return anything but 'waiting'. |
|
@@ 184-206 (lines=23) @@
|
| 181 |
|
* |
| 182 |
|
* @AfterStep ~@modal |
| 183 |
|
*/ |
| 184 |
|
public function handleAjaxAfterStep(StepEvent $event) { |
| 185 |
|
try{ |
| 186 |
|
$ajaxEnabledSteps = $this->getMainContext()->getAjaxSteps(); |
| 187 |
|
$ajaxEnabledSteps = implode('|', array_filter($ajaxEnabledSteps)); |
| 188 |
|
|
| 189 |
|
if (empty($ajaxEnabledSteps) || !preg_match('/(' . $ajaxEnabledSteps . ')/i', $event->getStep()->getText())) { |
| 190 |
|
return; |
| 191 |
|
} |
| 192 |
|
|
| 193 |
|
$this->handleAjaxTimeout(); |
| 194 |
|
|
| 195 |
|
$javascript = <<<JS |
| 196 |
|
if ('undefined' !== typeof window.jQuery && 'undefined' !== typeof window.jQuery.fn.off) { |
| 197 |
|
window.jQuery(document).off('ajaxStart.ss.test.behaviour'); |
| 198 |
|
window.jQuery(document).off('ajaxComplete.ss.test.behaviour'); |
| 199 |
|
window.jQuery(document).off('ajaxSuccess.ss.test.behaviour'); |
| 200 |
|
} |
| 201 |
|
JS; |
| 202 |
|
$this->getSession()->executeScript($javascript); |
| 203 |
|
}catch(\WebDriver\Exception $e){ |
| 204 |
|
$this->logException($e); |
| 205 |
|
} |
| 206 |
|
} |
| 207 |
|
|
| 208 |
|
public function handleAjaxTimeout() { |
| 209 |
|
$timeoutMs = $this->getMainContext()->getAjaxTimeout(); |