Merge pull request #1164 from mailpoet/acceptance_js_errors
Add JS error checking to acceptance tests [MAILPOET-1179]
This commit is contained in:
@ -5,5 +5,50 @@ namespace Helper;
|
|||||||
|
|
||||||
class Acceptance extends \Codeception\Module
|
class Acceptance extends \Codeception\Module
|
||||||
{
|
{
|
||||||
|
protected $js_errors = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note: Selenium JS error log buffer is cleared after logs retrieval:
|
||||||
|
* https://github.com/SeleniumHQ/selenium/wiki/Logging#retrieval-of-logs
|
||||||
|
*/
|
||||||
|
function seeNoJSErrors() {
|
||||||
|
$wd = $this->getModule('WPWebDriver');
|
||||||
|
|
||||||
|
try {
|
||||||
|
$logEntries = array_slice(
|
||||||
|
$wd->webDriver->manage()->getLog('browser'),
|
||||||
|
-15 // Number of log entries to tail
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach($logEntries as $logEntry) {
|
||||||
|
if($this->isJSError($logEntry)) {
|
||||||
|
// Collect JS errors into an array
|
||||||
|
$this->js_errors[] = $logEntry['message'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!empty($this->js_errors)) {
|
||||||
|
$this->debug('JS errors : ' . print_r($this->js_errors, true));
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->debug('Unable to retrieve Selenium logs : ' . $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// String comparison is used to show full error messages in test fail diffs
|
||||||
|
$this->assertEquals('', join(PHP_EOL, $this->js_errors), 'JS errors are present');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function isJSError($logEntry) {
|
||||||
|
return isset($logEntry['level'])
|
||||||
|
&& isset($logEntry['message'])
|
||||||
|
&& isset($logEntry['source'])
|
||||||
|
&& $logEntry['level'] === 'SEVERE'
|
||||||
|
&& ($logEntry['source'] === 'javascript' // Native JS errors
|
||||||
|
|| ($logEntry['source'] === 'network' && preg_match('/\.(js|css)/i', $logEntry['message'])) // JS/CSS files failed to load
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function _after() {
|
||||||
|
$this->js_errors = array();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ class SubscriptionFormCest
|
|||||||
$I->fillField('input[title="Email"]', 'test-email@example.com');
|
$I->fillField('input[title="Email"]', 'test-email@example.com');
|
||||||
$I->click('.mailpoet_submit');
|
$I->click('.mailpoet_submit');
|
||||||
$I->waitForText('Check your inbox or spam folder to confirm your subscription.', 3, '.mailpoet_validate_success');
|
$I->waitForText('Check your inbox or spam folder to confirm your subscription.', 3, '.mailpoet_validate_success');
|
||||||
|
$I->seeNoJSErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
function _after(\AcceptanceTester $I) {
|
function _after(\AcceptanceTester $I) {
|
||||||
|
Reference in New Issue
Block a user