[FIX] core: use actual chrome/chromium executable on macOs.

This commit is contained in:
Christophe Simonis
2018-10-18 11:59:42 +02:00
parent ecaa04ec82
commit 42cfc72d5e
+32 -5
View File
@@ -12,6 +12,7 @@ import json
import logging
import operator
import os
import platform
import re
import requests
import shutil
@@ -30,6 +31,7 @@ from lxml import etree, html
from odoo.models import BaseModel
from odoo.osv.expression import normalize_domain
from odoo.tools import pycompat
from odoo.tools.misc import find_in_path
from odoo.tools.safe_eval import safe_eval
try:
@@ -344,10 +346,10 @@ class ChromeBrowser():
self.ws_url = '' # WebSocketUrl
self.ws = None # websocket
self.request_id = 0
self.user_data_dir = ''
self.user_data_dir = tempfile.mkdtemp(suffix='_chrome_odoo')
self.chrome_process = None
self.screencast_frames = []
self._chrome_start(['google-chrome'], self.user_data_dir)
self._chrome_start()
_logger.info('Websocket url found: %s' % self.ws_url)
self._open_websocket()
_logger.info('Enable chrome headless console log notification')
@@ -367,7 +369,32 @@ class ChromeBrowser():
_logger.info('Removing chrome user profile "%s"' % self.user_data_dir)
shutil.rmtree(self.user_data_dir)
def _chrome_start(self, cmd, user_data_dir):
@property
def executable(self):
system = platform.system()
if system == 'Linux':
for bin_ in ['google-chrome', 'chromium']:
try:
return find_in_path(bin_)
except IOError:
continue
elif system == 'Darwin':
bins = [
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
'/Applications/Chromium.app/Contents/MacOS/Chromium',
]
for bin_ in bins:
if os.path.exists(bin_):
return bin_
elif system == 'Windows':
# TODO: handle windows platform: https://stackoverflow.com/a/40674915
pass
raise unittest.SkipTest("Chrome executable not found")
def _chrome_start(self):
if self.chrome_process is not None:
return
switches = {
@@ -376,11 +403,12 @@ class ChromeBrowser():
'--no-default-browser-check': '',
'--no-first-run': '',
'--disable-extensions': '',
'--user-data-dir': user_data_dir,
'--user-data-dir': self.user_data_dir,
'--disable-translate': '',
'--window-size': '1366x768',
'--remote-debugging-port': str(self.devtools_port)
}
cmd = [self.executable]
cmd += ['%s=%s' % (k, v) if v else k for k, v in switches.items()]
url = 'about:blank'
cmd.append(url)
@@ -394,7 +422,6 @@ class ChromeBrowser():
_logger.info('Browser version: %s' % version['Browser'])
infos = self._json_command('')[0] # Infos about the first tab
self.ws_url = infos['webSocketDebuggerUrl']
self.user_data_dir = tempfile.mkdtemp(suffix='_chrome_odoo')
_logger.info('Chrome headless temporary user profile dir: %s' % self.user_data_dir)
def _json_command(self, command, timeout=3):