def start_driver(self):
logging.info('Configuring Driver')
# Set up the options for the browser
chrome_options = webdriver.ChromeOptions()
prefs = {
"profile.default_content_setting_values.notifications": 2,
"download.default_directory": "/var/tmp/",
"download.prompt_for_download": False,
"download.directory_upgrade": True,
}
service = webdriver.ChromeService(
# log_output=subprocess.STDOUT,
log_output='/var/tmp/webservice.log',
service_args=['--log-level=INFO']
)
cloud_options = {}
cloud_options['goog:loggingPrefs'] = {'browser': 'ALL'}
chrome_options.add_experimental_option("prefs", prefs)
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--headless=new')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument("--remote-debugging-address=0.0.0.0")
chrome_options.add_argument("--remote-debugging-port=9222")
chrome_options.add_argument('--disable-notifications')
chrome_options.add_argument('--use-fake-ui-for-media-stream')
chrome_options.add_argument('--use-fake-device-for-media-stream')
# chrome_options.add_argument('--log-path=/var/tmp/chrome.log')
chrome_options.add_argument('--user-data-dir=/var/tmp/chrome')
chrome_options.add_argument('--log-format=json')
chrome_options.add_argument('--log-level=0')
chrome_options.add_argument('--enable-logging')
chrome_options.add_argument('--v=1')
chrome_options.set_capability('cloud:options', cloud_options)
# chrome_options.binary_location = '/usr/bin/google-chrome'
try:
self.driver = webdriver.Chrome(
options=chrome_options, service=service)
# options=chrome_options)
logging.info('Driver configured.')
except Exception as e:
logging.error('Driver Configuration Failed.')
logging.error(e)