Home | History | Annotate | Download | only in install_test
      1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 """Chrome-specific options for configuring a ChromeDriver instance."""
      6 
      7 import base64
      8 
      9 
     10 class ChromeOptions(object):
     11   """Chrome-specific options for configuring a ChromeDriver instance."""
     12 
     13   def __init__(self):
     14     """Initialize ChromeOptions object."""
     15     self._capabilities = {'chrome.switches': [], 'chrome.extensions': []}
     16 
     17   def AddSwitch(self, switch):
     18     """Add a switch to be passed to Chrome.
     19 
     20     Args:
     21       switch: String switch to be passed to Chrome.
     22     """
     23     self._capabilities['chrome.switches'].append(switch)
     24 
     25   def AddExtension(self, extension):
     26     """Add an extension to be loaded onto Chrome.
     27 
     28     Args:
     29       extension: String path to the extension to be loaded onto Chrome.
     30     """
     31     with open(extension, 'rb') as ext_file:
     32       self._capabilities['chrome.extensions'].append(
     33           base64.b64encode(ext_file.read()))
     34 
     35   def SetUserDataDir(self, user_data_dir):
     36     """Set the Chrome user data dir.
     37 
     38     Args:
     39       user_data_dir: String path to the profile directory.
     40     """
     41     self.AddSwitch('user-data-dir=%s' % user_data_dir)
     42 
     43   def GetCapabilities(self):
     44     """Returns a capabilities object suitable for using with ChromeDriver."""
     45     return self._capabilities
     46