blob: c353ed0db81a3d23f5eb7fb3a6f944b4ecbb5b4b [file] [log] [blame]
Dennis Jeffreydffc0bd2013-05-03 13:24:31 -07001# Copyright (c) 2013 The Chromium OS 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"""Telemetry-based Chrome automation functions."""
6
7from telemetry.core import browser_finder, browser_options
8
9
10# The following constant is the name of the logged-in user that is specified
11# by the Telemetry chromeOS login extension
12# (chromium/src/tools/telemetry/telemetry/core/chrome/chromeos_login_ext).
13# The value here must match what is specified in that login extension.
14LOGIN_USER = 'test@test.test'
Achuith Bhandarkar86c46812013-07-15 17:13:39 -070015_BROWSER_TYPE_LOGIN = 'system'
16_BROWSER_TYPE_GUEST = 'system-guest'
Dennis Jeffreydffc0bd2013-05-03 13:24:31 -070017
18
Achuith Bhandarkar86c46812013-07-15 17:13:39 -070019def _get_browser(browser_type):
20 options = browser_options.BrowserOptions()
21 options.browser_type = browser_type
22 browser_to_create = browser_finder.FindBrowser(options)
23 return browser_to_create.Create()
24
25
26def logged_in_browser():
27 """Returns a logged in browser.
Dennis Jeffreydffc0bd2013-05-03 13:24:31 -070028
29 Wrapping this within a Python with/as construct will take care of
30 automatically logging into Chrome at the start and logging out of Chrome
31 at the end, e.g.:
32
Achuith Bhandarkar86c46812013-07-15 17:13:39 -070033 with chrome.logged_in_browser() as browser:
Dennis Jeffreydffc0bd2013-05-03 13:24:31 -070034 do_test() # Will be logged in for this.
35 # Logged out at this point.
36
37 @return A Telemetry Browser object supporting context management.
38 """
Achuith Bhandarkar86c46812013-07-15 17:13:39 -070039 return _get_browser(_BROWSER_TYPE_LOGIN)
40
41
42def incognito_browser():
43 """Returns an incognito browser."""
44 return _get_browser(_BROWSER_TYPE_GUEST)