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.
5 """Chrome-specific options for configuring a ChromeDriver instance."""
10 class ChromeOptions(object):
11 """Chrome-specific options for configuring a ChromeDriver instance."""
14 """Initialize ChromeOptions object."""
15 self
._capabilities
= {'chrome.switches': [], 'chrome.extensions': []}
17 def AddSwitch(self
, switch
):
18 """Add a switch to be passed to Chrome.
21 switch: String switch to be passed to Chrome.
23 self
._capabilities
['chrome.switches'].append(switch
)
25 def AddExtension(self
, extension
):
26 """Add an extension to be loaded onto Chrome.
29 extension: String path to the extension to be loaded onto Chrome.
31 with
open(extension
, 'rb') as ext_file
:
32 self
._capabilities
['chrome.extensions'].append(
33 base64
.b64encode(ext_file
.read()))
35 def SetUserDataDir(self
, user_data_dir
):
36 """Set the Chrome user data dir.
39 user_data_dir: String path to the profile directory.
41 self
.AddSwitch('user-data-dir=%s' % user_data_dir
)
43 def GetCapabilities(self
):
44 """Returns a capabilities object suitable for using with ChromeDriver."""
45 return self
._capabilities