How to use _install_build method in lisa

Best Python code snippet using lisa_python

install_test.py

Source:install_test.py Github

copy

Full Screen

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 be3# found in the LICENSE file.4"""Test fixture for tests involving installing/updating Chrome.5Provides an interface to install or update chrome from within a testcase, and6allows users to run tests using installed version of Chrome. User and system7level installations are supported, and either one can be used for running the8tests. Currently the only platform it supports is Windows.9"""10import os11import sys12import unittest13import urllib14import chrome_installer_win15_DIRECTORY = os.path.dirname(os.path.abspath(__file__))16sys.path.append(os.path.join(_DIRECTORY, os.path.pardir, os.path.pardir,17 os.path.pardir, 'third_party', 'webdriver',18 'pylib'))19sys.path.append(os.path.join(_DIRECTORY, os.path.pardir, 'pylib'))20# This import should go after sys.path is set appropriately.21from chrome import Chrome22from selenium import webdriver23import selenium.webdriver.chrome.service as service24from selenium.webdriver.chrome.service import WebDriverException25from common import util26class InstallTest(unittest.TestCase):27 """Base updater test class.28 All dependencies, like Chrome installers and ChromeDriver, are downloaded at29 the beginning of the test. Dependencies are downloaded in the temp directory.30 This download occurs only once, before the first test is executed. Each test31 case starts an instance of ChromeDriver and terminates it upon completion.32 All updater tests should derive from this class.33 Example:34 class SampleUpdater(InstallTest):35 def testCanOpenGoogle(self):36 self.Install(self.GetUpdateBuilds()[0])37 self.StartChrome()38 self._driver.get('http://www.google.com/')39 self.Install(self.GetUpdateBuilds()[1])40 self.StartChrome()41 self._driver.get('http://www.google.org/')42 Include the following in your updater test script to make it run standalone.43 from install_test import Main44 if __name__ == '__main__':45 Main()46 To fire off an updater test, use the command below.47 python test_script.py --url=<URL> --update-builds=24.0.1299.0,24.0.1300.048 """49 _installer_paths = {}50 _chrome_driver = ''51 _installer_options = []52 _install_type = chrome_installer_win.InstallationType.USER53 def __init__(self, methodName='runTest'):54 unittest.TestCase.__init__(self, methodName)55 self._driver = None56 current_version = chrome_installer_win.ChromeInstallation.GetCurrent()57 if current_version:58 current_version.Uninstall()59 def setUp(self):60 """Called before each unittest to prepare the test fixture."""61 self._StartService()62 def tearDown(self):63 """Called at the end of each unittest to do any test related cleanup."""64 # Confirm ChromeDriver was instantiated, before attempting to quit.65 if self._driver is not None:66 try:67 self._driver.quit()68 except WebDriverException:69 pass70 self._service.stop()71 self._installation.Uninstall()72 def _StartService(self):73 """Starts ChromeDriver service."""74 self._service = service.Service(InstallTest._chrome_driver)75 self._service.start()76 def StartChrome(self, caps={}, options=None):77 """Creates a ChromeDriver instance.78 If both caps and options have the same settings, the settings from options79 will be used.80 Args:81 caps: Capabilities that will be passed to ChromeDriver.82 options: ChromeOptions object that will be passed to ChromeDriver.83 """84 self._driver = Chrome(self._service.service_url, caps, options)85 def Install(self, build, master_pref=None):86 """Helper method that installs the specified Chrome build.87 Args:88 build: Chrome version number that will be used for installation.89 master_pref: Location of the master preferences file.90 """91 if self._driver:92 try:93 self._driver.quit()94 except WebDriverException:95 pass96 options = []97 options.extend(self._installer_options)98 if self._install_type == chrome_installer_win.InstallationType.SYSTEM:99 options.append('--system-level')100 if master_pref:101 options.append('--installerdata=%s' % master_pref)102 self._installation = chrome_installer_win.Install(103 self._installer_paths[build],104 self._install_type,105 build,106 options)107 def GetInstallBuild(self):108 """Returns Chorme build to be used for install test scenarios."""109 return self._install_build110 def GetUpdateBuilds(self):111 """Returns Chrome builds to be used for update test scenarios."""112 return self._update_builds113 @staticmethod114 def _Download(url, path):115 """Downloads a file from the specified URL.116 Args:117 url: URL where the file is located.118 path: Location where file will be downloaded.119 Raises:120 RuntimeError: URL or file name is invalid.121 """122 if not util.DoesUrlExist(url):123 raise RuntimeError('Either the URL or the file name is invalid.')124 urllib.urlretrieve(url, path)125 @staticmethod126 def SetInstallType(install_type):127 """Sets Chrome installation type.128 Args:129 install_type: Type of installation(i.e., user or system).130 """131 InstallTest._install_type = install_type132 @staticmethod133 def InitTestFixture(install_build, update_builds, base_url, options):134 """Static method for passing command options to InstallTest.135 We do not instantiate InstallTest. Therefore, command arguments cannot be136 passed to its constructor. Since InstallTest needs to use these options,137 and using globals is not an option, this method can be used by the Main138 class to pass the arguments it parses onto InstallTest.139 Args:140 install_build: A string representing the Chrome build to be used for141 install testing. Pass this argument only if testing142 fresh install scenarios.143 update_builds: A list that contains the Chrome builds to be used for144 testing update scenarios. Pass this argument only if145 testing upgrade scenarios.146 base_url: Base url of the 'official chrome builds' page.147 options: A list that contains options to be passed to Chrome installer.148 """149 system = util.GetPlatformName()150 InstallTest._install_build = install_build151 InstallTest._update_builds = update_builds152 InstallTest._installer_options = options153 tempdir = util.MakeTempDir()154 builds = []155 if InstallTest._install_build:156 builds.append(InstallTest._install_build)157 if InstallTest._update_builds:158 builds.extend(InstallTest._update_builds)159 # Remove any duplicate build numbers.160 builds = list(frozenset(builds))161 for build in builds:162 url = '%s%s/%s/mini_installer.exe' % (base_url, build, system)163 installer_path = os.path.join(tempdir, 'mini_installer_%s.exe' % build)164 InstallTest._installer_paths[build] = installer_path165 InstallTest._Download(url, installer_path)166 InstallTest._chrome_driver = os.path.join(tempdir, 'chromedriver.exe')167 url = '%s%s/%s/%s/chromedriver.exe' % (base_url, build, system,168 'chrome-win32.test')...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful