-
Notifications
You must be signed in to change notification settings - Fork 49
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
Detect javascript errors when visiting a new web page #185
base: master
Are you sure you want to change the base?
Conversation
@@ -125,7 +125,10 @@ public function visit($url) | |||
} | |||
}); | |||
JS; | |||
$this->server->evalJS($js); | |||
$out = $this->server->evalJS($js); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Are you sure, that JavaScript errors (if any) will be returned as method call result?
- Does same error catching technique apply to other js-enabled drivers, like Selenium?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aik099 visiting a URL in Selenium uses a native Selenium method. So we don't need to implement error handling (Selenium does).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aik099 see the JS code just above. On error, it outputs some stuff to the stream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The zombie "browser" object's method "visit" has a callback as its second argument that will be called if an error occurs. Currently this error information is just thrown away. I found it very helpful to have this error information in my project when making behat tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stof has been quiet on this. I guess it is ok as it is then?
src/ZombieDriver.php
Outdated
$this->server->evalJS($js); | ||
$out = $this->server->evalJS($js); | ||
if (!empty($out)) { | ||
throw new DriverException(sprintf('Error when loading page %s: %s', $url, $out)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The right fix would rather be to prefix the error output with ZombieServer::ERROR_PREFIX
and then evalJS
will throw the exception for us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then you will not get the same degree of specialized error message. You will get a more general error message, and you will not readily see the url that it tried to visit.
You can also see that the same coding pattern is applied to the click function at line 719, and also in triggerBrowserEvent at line 890
@aik099 Anything I can do to get this PR accepted? |
Here is an example of what happens when the php server is runnung at the not expected port.
Here is how it will look if we do it the way @stof suggested:
You see that the second error message has no information the url of that zombie tried to connect to when the error happened. |
This makes it possible to see what is going on if you visit a web page and it has javascript errors, or the page fails to load for other reasons (f.ex. the server might be down).
Without this fix, after you visit you just get http code 0 instead of 200, and you will not know what is going on.