[FIX] tests: properly stop chrome when no tab found

In some situations, Chrome remote debugging is sending an empty list of
opened tabs. In that case, an orphan Chrome process stays alive.

With this commit, Chrome is stopped properly in those situations.
This commit is contained in:
Christophe Monniez
2018-10-18 11:59:43 +02:00
committed by Christophe Simonis
parent 0daf4536a6
commit 5a523b06cd
+9 -1
View File
@@ -351,6 +351,7 @@ class ChromeBrowser():
self.chrome_process = None
self.screencast_frames = []
self._chrome_start()
self._find_websocket()
self._logger.info('Websocket url found: %s', self.ws_url)
self._open_websocket()
self._logger.info('Enable chrome headless console log notification')
@@ -419,9 +420,16 @@ class ChromeBrowser():
except OSError:
raise unittest.SkipTest("%s not found" % cmd[0])
self._logger.info('Chrome pid: %s', self.chrome_process.pid)
def _find_websocket(self):
version = self._json_command('version')
self._logger.info('Browser version: %s', version['Browser'])
infos = self._json_command('')[0] # Infos about the first tab
try:
infos = self._json_command('')[0] # Infos about the first tab
except IndexError:
self._logger.warning('No tab found in Chrome')
self.stop()
raise unittest.SkipTest('No tab found in Chrome')
self.ws_url = infos['webSocketDebuggerUrl']
self._logger.info('Chrome headless temporary user profile dir: %s', self.user_data_dir)