[FIX] tests: avoid confusing traceback at browser start

During an HttpCase, when the Chrome browser starts, it may happens that
the websocket is unreachable. In such a case, the stop method is called
and tries to stop the browser gracefully by sending a `Browser.close`
through the websocket ... which is not reachable.

The result is a confusing traceback. With this commit, nothing is sent
is the websocket is not available.

Moreover, the `sigxcpu_handler` attribute is used in the stop method but
not yet declared. Fixed by moving it before calling the _chrome_start
method.

X-original-commit: 0d156fd3bc114b40680ca5aa0456e0f21a5b8cff
This commit is contained in:
Christophe Monniez
2020-02-20 16:53:33 +00:00
parent 54e1a69b09
commit 426fc163ba
+3 -1
View File
@@ -644,6 +644,7 @@ class ChromeBrowser():
os.makedirs(self.screenshots_dir, exist_ok=True)
self.window_size = window_size
self.sigxcpu_handler = None
self._chrome_start()
self._find_websocket()
self._logger.info('Websocket url found: %s', self.ws_url)
@@ -652,7 +653,6 @@ class ChromeBrowser():
self._websocket_send('Runtime.enable')
self._logger.info('Chrome headless enable page notifications')
self._websocket_send('Page.enable')
self.sigxcpu_handler = None
if os.name == 'posix':
self.sigxcpu_handler = signal.getsignal(signal.SIGXCPU)
signal.signal(signal.SIGXCPU, self.signal_handler)
@@ -811,6 +811,8 @@ class ChromeBrowser():
"""
send chrome devtools protocol commands through websocket
"""
if self.ws is None:
return
sent_id = self.request_id
payload = {
'method': method,