def testDefaults(self): options = browser_options.BrowserFinderOptions() parser = options.CreateParser() parser.add_option('-x', action='store', default=3) parser.parse_args(['--browser', 'any']) self.assertEquals(options.x, 3) # pylint: disable=E1101
def testAdbNoDevicesReturnsNone(self, warning_mock): finder_options = browser_options.BrowserFinderOptions() with mock.patch('os.path.isabs', return_value=False): self._healthy_device_mock.return_value = [] self.assertEquals(warning_mock.call_count, 0) self.assertIsNone(android_device.GetDevice(finder_options))
def __init__(self, logged_in=True, extension_paths=None, autotest_ext=False, num_tries=3, extra_browser_args=None, clear_enterprise_policy=True, expect_policy_fetch=False, dont_override_profile=False, disable_gaia_services=True, disable_default_apps=True, auto_login=True, gaia_login=False, username=None, password=None, gaia_id=None, arc_mode=None, arc_timeout=None, disable_arc_opt_in=True, disable_arc_opt_in_verification=True, disable_arc_cpu_restriction=True, disable_app_sync=False, disable_play_auto_install=False, disable_locale_sync=True, disable_play_store_auto_update=True, enable_assistant=False, enterprise_arc_test=False, init_network_controller=False, mute_audio=False, proxy_server=None, login_delay=0): """ Constructor of telemetry wrapper. @param logged_in: Regular user (True) or guest user (False). @param extension_paths: path of unpacked extension to install. @param autotest_ext: Load a component extension with privileges to invoke chrome.autotestPrivate. @param num_tries: Number of attempts to log in. @param extra_browser_args: Additional argument(s) to pass to the browser. It can be a string or a list. @param clear_enterprise_policy: Clear enterprise policy before logging in. @param expect_policy_fetch: Expect that chrome can reach the device management server and download policy. @param dont_override_profile: Don't delete cryptohome before login. Telemetry will output a warning with this option. @param disable_gaia_services: For enterprise autotests, this option may be used to enable policy fetch. @param disable_default_apps: For tests that exercise default apps. @param auto_login: Does not login automatically if this is False. Useful if you need to examine oobe. @param gaia_login: Logs in to real gaia. @param username: Log in using this username instead of the default. @param password: Log in using this password instead of the default. @param gaia_id: Log in using this gaia_id instead of the default. @param arc_mode: How ARC instance should be started. Default is to not start. @param arc_timeout: Timeout to wait for ARC to boot. @param disable_arc_opt_in: For opt in flow autotest. This option is used to disable the arc opt in flow. @param disable_arc_opt_in_verification: Adds --disable-arc-opt-in-verification to browser args. This should generally be enabled when disable_arc_opt_in is enabled. However, for data migration tests where user's home data is already set up with opted-in state before login, this option needs to be set to False with disable_arc_opt_in=True to make ARC container work. @param disable_arc_cpu_restriction: Adds --disable-arc-cpu-restriction to browser args. This is enabled by default and will make tests run faster and is generally desirable unless a test is actually trying to test performance where ARC is running in the background for some porition of the test. @param disable_app_sync: Adds --arc-disable-app-sync to browser args and this disables ARC app sync flow. By default it is enabled. @param disable_play_auto_install: Adds --arc-disable-play-auto-install to browser args and this disables ARC Play Auto Install flow. By default it is enabled. @param enable_assistant: For tests that require to enable Google Assistant service. Default is False. @param enterprise_arc_test: Skips opt_in causing enterprise tests to fail @param disable_locale_sync: Adds --arc-disable-locale-sync to browser args and this disables locale sync between Chrome and Android container. In case of disabling sync, Android container is started with language and preference language list as it was set on the moment of starting full instance. Used to prevent random app restarts caused by racy locale change, coming from profile sync. By default locale sync is disabled. @param disable_play_store_auto_update: Adds --arc-play-store-auto-update=off to browser args and this disables Play Store, GMS Core and third-party apps auto-update. By default auto-update is off to have stable autotest environment. @param mute_audio: Mute audio. @param proxy_server: To launch the chrome with --proxy-server Adds '--proxy-server="http://$HTTP_PROXY:PORT"' to browser args. By default proxy-server is disabled @param login_delay: Time for idle in login screen to simulate the time required for password typing. """ self._autotest_ext_path = None # Force autotest extension if we need enable Play Store. if (utils.is_arc_available() and (arc_util.should_start_arc(arc_mode) or not disable_arc_opt_in)): autotest_ext = True if extension_paths is None: extension_paths = [] finder_options = browser_options.BrowserFinderOptions() if proxy_server: finder_options.browser_options.AppendExtraBrowserArgs( ['--proxy-server="%s"' % proxy_server]) if utils.is_arc_available() and arc_util.should_start_arc(arc_mode): if disable_arc_opt_in and disable_arc_opt_in_verification: finder_options.browser_options.AppendExtraBrowserArgs( ['--disable-arc-opt-in-verification']) if disable_arc_cpu_restriction: finder_options.browser_options.AppendExtraBrowserArgs( ['--disable-arc-cpu-restriction']) if disable_app_sync: finder_options.browser_options.AppendExtraBrowserArgs( ['--arc-disable-app-sync']) if disable_play_auto_install: finder_options.browser_options.AppendExtraBrowserArgs( ['--arc-disable-play-auto-install']) if disable_locale_sync: finder_options.browser_options.AppendExtraBrowserArgs( ['--arc-disable-locale-sync']) if disable_play_store_auto_update: finder_options.browser_options.AppendExtraBrowserArgs( ['--arc-play-store-auto-update=off']) logged_in = True if autotest_ext: self._autotest_ext_path = os.path.join(os.path.dirname(__file__), 'autotest_private_ext') extension_paths.append(self._autotest_ext_path) finder_options.browser_options.AppendExtraBrowserArgs( ['--whitelisted-extension-id=%s' % self.AUTOTEST_EXT_ID]) self._browser_type = (self.BROWSER_TYPE_LOGIN if logged_in else self.BROWSER_TYPE_GUEST) finder_options.browser_type = self.browser_type if extra_browser_args: finder_options.browser_options.AppendExtraBrowserArgs( extra_browser_args) # finder options must be set before parse_args(), browser options must # be set before Create(). # TODO(crbug.com/360890) Below MUST be '2' so that it doesn't inhibit # autotest debug logs finder_options.verbosity = 2 finder_options.CreateParser().parse_args(args=[]) b_options = finder_options.browser_options b_options.disable_component_extensions_with_background_pages = False b_options.create_browser_with_oobe = True b_options.clear_enterprise_policy = clear_enterprise_policy b_options.dont_override_profile = dont_override_profile b_options.disable_gaia_services = disable_gaia_services b_options.disable_default_apps = disable_default_apps b_options.disable_component_extensions_with_background_pages = disable_default_apps b_options.disable_background_networking = False b_options.expect_policy_fetch = expect_policy_fetch b_options.auto_login = auto_login b_options.gaia_login = gaia_login b_options.mute_audio = mute_audio b_options.login_delay = login_delay if utils.is_arc_available() and not disable_arc_opt_in: arc_util.set_browser_options_for_opt_in(b_options) self.username = b_options.username if username is None else username self.password = b_options.password if password is None else password self.username = NormalizeEmail(self.username) b_options.username = self.username b_options.password = self.password self.gaia_id = b_options.gaia_id if gaia_id is None else gaia_id b_options.gaia_id = self.gaia_id self.arc_mode = arc_mode if logged_in: extensions_to_load = b_options.extensions_to_load for path in extension_paths: extension = extension_to_load.ExtensionToLoad( path, self.browser_type) extensions_to_load.append(extension) self._extensions_to_load = extensions_to_load # Turn on collection of Chrome coredumps via creation of a magic file. # (Without this, Chrome coredumps are trashed.) open(constants.CHROME_CORE_MAGIC_FILE, 'w').close() self._browser_to_create = browser_finder.FindBrowser(finder_options) self._browser_to_create.SetUpEnvironment(b_options) for i in range(num_tries): try: self._browser = self._browser_to_create.Create() self._browser_pid = \ cros_interface.CrOSInterface().GetChromePid() if utils.is_arc_available(): if disable_arc_opt_in: if arc_util.should_start_arc(arc_mode): arc_util.enable_play_store(self.autotest_ext, True) else: if not enterprise_arc_test: wait_for_provisioning = \ arc_mode != arc_common.ARC_MODE_ENABLED_ASYNC arc_util.opt_in( browser=self.browser, autotest_ext=self.autotest_ext, wait_for_provisioning=wait_for_provisioning) arc_util.post_processing_after_browser(self, arc_timeout) if enable_assistant: assistant_util.enable_assistant(self.autotest_ext) break except exceptions.LoginException as e: logging.error('Timed out logging in, tries=%d, error=%s', i, repr(e)) if i == num_tries - 1: raise if init_network_controller: self._browser.platform.network_controller.Open()
def CreateParser(cls): options = browser_options.BrowserFinderOptions() options.browser_type = 'any' parser = options.CreateParser('%%prog %s' % cls.usage) return parser
def testFindAllAvailableDevicesFailsNonFuchsiaBrowser(self): options = browser_options.BrowserFinderOptions('not_fuchsia_browser') self.assertEquals(fuchsia_device.FindAllAvailableDevices(options), [])
def testProfileDirDefault(self): options = browser_options.BrowserFinderOptions() parser = options.CreateParser() parser.parse_args(['--browser', 'any']) self.assertEquals(options.browser_options.profile_dir, None)
def testAdbNoDevicesReturnsNone(self): finder_options = browser_options.BrowserFinderOptions() with mock.patch('os.path.isabs', return_value=False): self._healthy_device_mock.return_value = [] self.assertEquals([], self._android_device_stub.logging.warnings) self.assertIsNone(android_device.GetDevice(finder_options))
def _CreateOptions(self): options = browser_options.BrowserFinderOptions() options.browser_options.wpr_mode = wpr_modes.WPR_RECORD options.browser_options.no_proxy_server = True return options
def _CreateOptions(self): options = browser_options.BrowserFinderOptions() options.browser_options.wpr_mode = wpr_modes.WPR_RECORD return options
def __init__(self, logged_in=True, extension_paths=[], autotest_ext=False, num_tries=3, extra_browser_args=None, clear_enterprise_policy=True, dont_override_profile=False, disable_gaia_services=True, disable_default_apps=True, auto_login=True, gaia_login=False, username=None, password=None, gaia_id=None, arc_mode=None, disable_arc_opt_in=True, init_network_controller=False): """ Constructor of telemetry wrapper. @param logged_in: Regular user (True) or guest user (False). @param extension_paths: path of unpacked extension to install. @param autotest_ext: Load a component extension with privileges to invoke chrome.autotestPrivate. @param num_tries: Number of attempts to log in. @param extra_browser_args: Additional argument(s) to pass to the browser. It can be a string or a list. @param clear_enterprise_policy: Clear enterprise policy before logging in. @param dont_override_profile: Don't delete cryptohome before login. Telemetry will output a warning with this option. @param disable_gaia_services: For enterprise autotests, this option may be used to enable policy fetch. @param disable_default_apps: For tests that exercise default apps. @param auto_login: Does not login automatically if this is False. Useful if you need to examine oobe. @param gaia_login: Logs in to real gaia. @param username: Log in using this username instead of the default. @param password: Log in using this password instead of the default. @param gaia_id: Log in using this gaia_id instead of the default. @param arc_mode: How ARC instance should be started. Default is to not start. @param disable_arc_opt_in: For opt in flow autotest. This option is used to disable the arc opt in flow. """ self._autotest_ext_path = None # Force autotest extension if we need enable Play Store. if (utils.is_arc_available() and (arc_util.should_start_arc(arc_mode) or not disable_arc_opt_in)): autotest_ext = True if autotest_ext: self._autotest_ext_path = os.path.join(os.path.dirname(__file__), 'autotest_private_ext') extension_paths.append(self._autotest_ext_path) finder_options = browser_options.BrowserFinderOptions() if utils.is_arc_available() and arc_util.should_start_arc(arc_mode): if disable_arc_opt_in: finder_options.browser_options.AppendExtraBrowserArgs( arc_util.get_extra_chrome_flags()) logged_in = True self._browser_type = (self.BROWSER_TYPE_LOGIN if logged_in else self.BROWSER_TYPE_GUEST) finder_options.browser_type = self.browser_type if extra_browser_args: finder_options.browser_options.AppendExtraBrowserArgs( extra_browser_args) # finder options must be set before parse_args(), browser options must # be set before Create(). # TODO(crbug.com/360890) Below MUST be '2' so that it doesn't inhibit # autotest debug logs finder_options.verbosity = 2 finder_options.CreateParser().parse_args(args=[]) b_options = finder_options.browser_options b_options.disable_component_extensions_with_background_pages = False b_options.create_browser_with_oobe = True b_options.clear_enterprise_policy = clear_enterprise_policy b_options.dont_override_profile = dont_override_profile b_options.disable_gaia_services = disable_gaia_services b_options.disable_default_apps = disable_default_apps b_options.disable_component_extensions_with_background_pages = disable_default_apps b_options.auto_login = auto_login b_options.gaia_login = gaia_login if utils.is_arc_available() and not disable_arc_opt_in: arc_util.set_browser_options_for_opt_in(b_options) self.username = b_options.username if username is None else username self.password = b_options.password if password is None else password self.username = NormalizeEmail(self.username) b_options.username = self.username b_options.password = self.password self.gaia_id = b_options.gaia_id if gaia_id is None else gaia_id b_options.gaia_id = self.gaia_id self.arc_mode = arc_mode if logged_in: extensions_to_load = b_options.extensions_to_load for path in extension_paths: extension = extension_to_load.ExtensionToLoad( path, self.browser_type) extensions_to_load.append(extension) self._extensions_to_load = extensions_to_load # Turn on collection of Chrome coredumps via creation of a magic file. # (Without this, Chrome coredumps are trashed.) open(constants.CHROME_CORE_MAGIC_FILE, 'w').close() for i in range(num_tries): try: browser_to_create = browser_finder.FindBrowser(finder_options) self._browser = browser_to_create.Create(finder_options) if utils.is_arc_available(): if disable_arc_opt_in: if arc_util.should_start_arc(arc_mode): arc_util.enable_play_store(self.autotest_ext) else: arc_util.opt_in(self.browser, self.autotest_ext) arc_util.post_processing_after_browser(self) break except exceptions.LoginException as e: logging.error('Timed out logging in, tries=%d, error=%s', i, repr(e)) if i == num_tries - 1: raise if init_network_controller: self._browser.platform.network_controller.InitializeIfNeeded()
def main(): """Does a bisect based on the command-line arguments passed in. The user will be prompted to classify each revision as good or bad. """ usage = ('%prog [options]\n' 'Used to run the bisection script with a manual test.') options = browser_options.BrowserFinderOptions('release') parser = options.CreateParser(usage) parser.add_option('-b', '--bad_revision', type='str', help='A bad revision to start bisection. ' + 'Must be later than good revision. May be either a git' + ' or svn revision.') parser.add_option('-g', '--good_revision', type='str', help='A revision to start bisection where performance' + ' test is known to pass. Must be earlier than the ' + 'bad revision. May be either a git or svn revision.') parser.add_option('-w', '--working_directory', type='str', default='..', help='A working directory to supply to the bisection ' 'script, which will use it as the location to checkout ' 'a copy of the chromium depot.') parser.add_option( '--extra_src', type='str', help='Path to extra source file. If this is supplied, ' 'bisect script will use this to override default behavior.') parser.add_option('--target_build_type', type='choice', choices=['Release', 'Debug'], help='The target build type. Choices are "Release" ' 'or "Debug".') parser.add_option( '--goma_threads', default=64, type='int', help='Number of goma threads to use. 0 will disable goma.') parser.add_option( '--builder_type', default='', choices=['perf', 'full', 'android-chrome-perf', ''], help='Type of builder to get build from. This allows ' 'script to use cached builds. By default (empty), binaries ' 'are built locally.') options, _ = parser.parse_args() error_msg = '' if not options.good_revision: error_msg += 'Error: missing required parameter: --good_revision\n' if not options.bad_revision: error_msg += 'Error: missing required parameter: --bad_revision\n' if error_msg: print error_msg parser.print_help() return 1 if 'android' not in options.browser_type and sys.platform.startswith( 'linux'): if not os.environ.get('CHROME_DEVEL_SANDBOX'): print 'SUID sandbox has not been setup.'\ ' See https://chromium.googlesource.com/chromium/src/'\ '+/master/docs/linux_suid_sandbox_development.md.' return 1 return _RunBisectionScript(options)
def _CreateOptions(self): options = browser_options.BrowserFinderOptions() options.browser_options.wpr_mode = wpr_modes.WPR_RECORD options.intermediate_dir = self._output_dir return options
def setUp(self): self._finder_options = browser_options.BrowserFinderOptions() self._finder_options.chrome_root = tempfile.mkdtemp()
def __init__(self, logged_in=True, extension_paths=[], autotest_ext=False, is_component=True, num_tries=3, extra_browser_args=None, clear_enterprise_policy=True, dont_override_profile=False, disable_gaia_services=True, disable_default_apps = True, auto_login=True, gaia_login=False, username=None, password=None, gaia_id=None): """ Constructor of telemetry wrapper. @param logged_in: Regular user (True) or guest user (False). @param extension_paths: path of unpacked extension to install. @param autotest_ext: Load a component extension with privileges to invoke chrome.autotestPrivate. @param is_component: Whether extensions should be loaded as component extensions. @param num_tries: Number of attempts to log in. @param extra_browser_args: Additional argument(s) to pass to the browser. It can be a string or a list. @param clear_enterprise_policy: Clear enterprise policy before logging in. @param dont_override_profile: Don't delete cryptohome before login. Telemetry will output a warning with this option. @param disable_gaia_services: For enterprise autotests, this option may be used to enable policy fetch. @param disable_default_apps: For tests that exercise default apps. @param auto_login: Does not login automatically if this is False. Useful if you need to examine oobe. @param gaia_login: Logs in to real gaia. @param username: Log in using this username instead of the default. @param password: Log in using this password instead of the default. @param gaia_id: Log in using this gaia_id instead of the default. """ self._autotest_ext_path = None if autotest_ext: self._autotest_ext_path = os.path.join(os.path.dirname(__file__), 'autotest_private_ext') extension_paths.append(self._autotest_ext_path) finder_options = browser_options.BrowserFinderOptions() self._browser_type = (self.BROWSER_TYPE_LOGIN if logged_in else self.BROWSER_TYPE_GUEST) finder_options.browser_type = self.browser_type if extra_browser_args: finder_options.browser_options.AppendExtraBrowserArgs( extra_browser_args) if logged_in: extensions_to_load = finder_options.extensions_to_load for path in extension_paths: extension = extension_to_load.ExtensionToLoad( path, self.browser_type, is_component=is_component) extensions_to_load.append(extension) self._extensions_to_load = extensions_to_load # finder options must be set before parse_args(), browser options must # be set before Create(). # TODO(crbug.com/360890) Below MUST be '2' so that it doesn't inhibit # autotest debug logs finder_options.verbosity = 2 finder_options.CreateParser().parse_args(args=[]) b_options = finder_options.browser_options b_options.disable_component_extensions_with_background_pages = False b_options.create_browser_with_oobe = True b_options.clear_enterprise_policy = clear_enterprise_policy b_options.dont_override_profile = dont_override_profile b_options.disable_gaia_services = disable_gaia_services b_options.disable_default_apps = disable_default_apps b_options.disable_component_extensions_with_background_pages = disable_default_apps b_options.auto_login = auto_login b_options.gaia_login = gaia_login self.username = b_options.username if username is None else username self.password = b_options.password if password is None else password b_options.username = self.username b_options.password = self.password # gaia_id will be added to telemetry code in chromium repository later try: self.gaia_id = b_options.gaia_id if gaia_id is None else gaia_id b_options.gaia_id = self.gaia_id except AttributeError: pass # Turn on collection of Chrome coredumps via creation of a magic file. # (Without this, Chrome coredumps are trashed.) open(constants.CHROME_CORE_MAGIC_FILE, 'w').close() for i in range(num_tries): try: browser_to_create = browser_finder.FindBrowser(finder_options) self._browser = browser_to_create.Create(finder_options) break except (exceptions.LoginException) as e: logging.error('Timed out logging in, tries=%d, error=%s', i, repr(e)) if i == num_tries-1: raise
def testDefaultsPlusOverride(self): options = browser_options.BrowserFinderOptions() parser = options.CreateParser() parser.add_option('-x', action='store', default=3) parser.parse_args(['--browser', 'any', '-x', 10]) self.assertEquals(options.x, 10) # pylint: disable=no-member
# # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License import telemetry.core from telemetry.internal.browser import browser_options from telemetry.internal.browser import browser_finder from json import dumps options = browser_options.BrowserFinderOptions() parser = options.CreateParser() (_, args) = parser.parse_args() browserFactory = browser_finder.FindBrowser(options) with browserFactory.Create(options) as browser: tab = browser.tabs.New() tab.Activate() for i in browser.tabs: if i == tab: continue i.Close() tab.Navigate(args[0]) tab.WaitForDocumentReadyStateToBeComplete() json = tab.EvaluateJavaScript("""(function() {
def testCount2(self): options = browser_options.BrowserFinderOptions() parser = options.CreateParser() parser.add_option('-x', action='count', dest='v') parser.parse_args(['--browser', 'any', '-xx']) self.assertEquals(options.v, 2) # pylint: disable=no-member
def testGetServByNameNotCalledWithPortSpecified(self, serv_mock): options = browser_options.BrowserFinderOptions() parser = options.CreateParser() parser.parse_args( ['--browser=cros-chrome', '--remote=localhost', '--remote-ssh-port=22']) serv_mock.assert_not_called()
def testEnableSystrace(self): options = browser_options.BrowserFinderOptions() parser = options.CreateParser() parser.parse_args(['--enable-systrace']) self.assertTrue(options.enable_systrace)
def testSshNotAvailableHardFailsCrosRemoteTest(self, serv_mock): serv_mock.side_effect = OSError('No SSH here') options = browser_options.BrowserFinderOptions() parser = options.CreateParser() with self.assertRaises(RuntimeError): parser.parse_args(['--browser=cros-chrome', '--remote=localhost'])
def CreateParser(cls): options = browser_options.BrowserFinderOptions() parser = options.CreateParser('%prog run benchmark_name [<options>]') return parser
def testNoConfig(self): options = browser_options.BrowserFinderOptions() parser = options.CreateParser() parser.parse_args([])
def PrintTelemetryHelp(): options = browser_options.BrowserFinderOptions() options.browser_type = 'any' parser = options.CreateParser() print('\n\nCommand line arguments handled by Telemetry:') parser.print_help()
def testExistingEnvironment(self): options = browser_options.BrowserFinderOptions() parser = options.CreateParser() browser_options.BrowserFinderOptions.emulator_environment = True parser.parse_args(['--avd-config=foo'])
def testFindAllAvailableDevicesFailsNonLinuxHost(self): options = browser_options.BrowserFinderOptions( fuchsia_interface.FUCHSIA_BROWSERS[0]) with mock.patch('platform.system', return_value='not_Linux'): self.assertEquals(fuchsia_device.FindAllAvailableDevices(options), [])
def testNoBuildAndroidDir(self, exists_mock): exists_mock.return_value = False options = browser_options.BrowserFinderOptions() parser = options.CreateParser() with self.assertRaises(RuntimeError): parser.parse_args(['--avd-config=foo'])
def CreateBrowserFinderOptions(browser_type=None): """Creates fake browser finder options for discovering a browser.""" return browser_options.BrowserFinderOptions(browser_type=browser_type)
def testAllPrerequisites(self, exists_mock): exists_mock.return_value = True options = browser_options.BrowserFinderOptions() parser = options.CreateParser() with self.assertRaises(ParseAndroidEmulatorOptionsTest.EarlyExitException): parser.parse_args(['--avd-config=foo'])
def CreateParser(cls): options = browser_options.BrowserFinderOptions() parser = options.CreateParser('%%prog %s %s' % (cls.Name(), cls.usage)) return parser
def __init__(self, path, browser, host_os, target_os, android_device=None, debug=False): self._logger = Util.get_logger() self.path = path self.target_os = target_os # path if target_os.is_cros(): self.path = '/usr/local/chromedriver/chromedriver' executable_suffix = Util.get_executable_suffix(host_os) if not self.path and browser.is_chrome() and host_os == target_os: if host_os.is_mac(): browser_dir = browser.path.replace( '/Chromium.app/Contents/MacOS/Chromium', '') else: browser_dir = os.path.dirname(os.path.realpath(browser.path)) tmp_path = Util.use_slash(browser_dir + '/chromedriver') tmp_path += executable_suffix if os.path.exists(tmp_path): self.path = tmp_path if not self.path: tmp_path = 'webdriver/%s/' % host_os.name if browser.is_chrome(): tmp_path += self.CHROME_WEBDRIVER_NAME elif browser.is_edge(): tmp_path += self.EDGE_WEBDRIVER_NAME elif browser.is_firefox(): tmp_path += self.FIREFOX_WEBDRIVER_NAME tmp_path += executable_suffix if os.path.exists(tmp_path): self.path = tmp_path # webdriver if target_os.is_android() or target_os.is_cros(): # This needs to be done before server process is created if target_os.is_cros(): from telemetry.internal.browser import browser_finder, browser_options finder_options = browser_options.BrowserFinderOptions() finder_options.browser_type = ('system') if browser.options: finder_options.browser_options.AppendExtraBrowserArgs( browser.options) finder_options.verbosity = 0 finder_options.CreateParser().parse_args(args=[]) b_options = finder_options.browser_options b_options.disable_component_extensions_with_background_pages = False b_options.create_browser_with_oobe = True b_options.clear_enterprise_policy = True b_options.dont_override_profile = False b_options.disable_gaia_services = True b_options.disable_default_apps = True b_options.disable_component_extensions_with_background_pages = True b_options.auto_login = True b_options.gaia_login = False b_options.gaia_id = b_options.gaia_id open('/mnt/stateful_partition/etc/collect_chrome_crashes', 'w').close() browser_to_create = browser_finder.FindBrowser(finder_options) self._browser = browser_to_create.Create(finder_options) self._browser.tabs[0].Close() webdriver_args = [self.path] port = self._get_unused_port() webdriver_args.append('--port=%d' % port) self.server_process = subprocess.Popen(webdriver_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, env=None) capabilities = {} capabilities['chromeOptions'] = {} self.server_url = 'http://localhost:%d' % port if target_os.is_android(): capabilities['chromeOptions'][ 'androidDeviceSerial'] = android_device.id capabilities['chromeOptions'][ 'androidPackage'] = self.ANDROID_CHROME_NAME_PKG[ browser.name] capabilities['chromeOptions']['args'] = browser.options elif target_os.is_cros(): remote_port = self._get_chrome_remote_debugging_port() urllib2.urlopen('http://localhost:%i/json/new' % remote_port) capabilities['chromeOptions']['debuggerAddress'] = ( 'localhost:%d' % remote_port) self.driver = webdriver.Remote(command_executor=self.server_url, desired_capabilities=capabilities) # other OS else: chrome_options = selenium.webdriver.ChromeOptions() for option in browser.options: chrome_options.add_argument(option) chrome_options.binary_location = browser.path if debug: service_args = ['--verbose', '--log-path=log/chromedriver.log'] else: service_args = [] self.driver = selenium.webdriver.Chrome( executable_path=self.path, chrome_options=chrome_options, service_args=service_args) # check if not browser.path: Util.error('Could not find browser at %s' % browser.path) if not self.path: Util.error('Could not find webdriver at %s' % self.path) if not self.driver: Util.error('Could not get webdriver') atexit.register(self._quit)