-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
There should be a direct programatic way to check whether any javascript error has occurred due to running some test(s). #25
Comments
@HaseebLUMS I don't see such feature in php-webdriver library and W3C WebDriver protocol (Please double check). I think that the most realistic option is to use executeJS method to setup |
This can be achieved. Step: 1Codeception Config: File: acceptancejs.suite.yml (this can be different in your case) actor: AcceptanceJsTester
modules:
enabled:
- Asserts
# use WebDriver instead of PhpBrowser to enable javascript testing
- WebDriver:
url: 'http://localhost:8116/'
#url: https://web/
#host: chrome
debug_log_entries: 10 # <------ this is the most important one; it must be > 0
log_js_errors: true # <------ this won't work if `debug_log_entries` is 0 (the default value)
browser: chrome
window_size: 1900x950
capabilities:
javascriptEnabled: true Till now if you test fails for any reason, the client side JavaScript (browser devtool console) error will be displayed as comment in CLI. But if you tests passes, it won't be shown. But we want to see errors and want to fail tests if there are any such errors. Below steps are for that. Step: 2In your test/cest file: use Codeception\Module\WebDriver;
class ProfileControllerCest
{
public $wd;
protected function _inject(WebDriver $wd)
{
$this->wd = $wd;
}
public function testSomething(AcceptanceJsTester $I)
{
// your actual tests that may yield client side JS errors
}
public function _after(AcceptanceJsTester $I)
{
$this->failIfBrowserConsoleJavaScriptErrorsExists($I, $this->wd);
parent::_after($I);
}
protected function failIfBrowserConsoleJavaScriptErrorsExists(AcceptanceJsTester $I)
{
// $I->wait(3); // depending on your tests, you may "wait" for JS operations to finish
$clientSideErrors = $this->getClientSideErrors();
if ($clientSideErrors) {
// $I->fail('JavsScript (JS) error found in browser devtools console!');
$I->assertNull($clientSideErrors);
}
}
protected function getClientSideErrors()
{
$logs = $this->wd->webDriver->manage()->getAvailableLogTypes();
$logType = 'browser';
if (in_array($logType, $logs)) {
return $this->wd->webDriver->manage()->getLog($logType);
}
return [];
} Also if you navigate from one page to another in test and if first one have errors and second does not then you have to handle this in your own way Things to do in Codeception:
|
What are you trying to achieve?
What do you get instead?
# paste output here
// paste test
Details
composer show
)# paste suite config here
The text was updated successfully, but these errors were encountered: