class OperaDriverObject(object): def __init__(self): self.ut = Utility() self.ot = OS_type() self.log = Logger() # Set opera odriver path # Pass the option 'headless' if it is needed to run gecko in headless # configuration def set_operadriver_object(self): try: os_type = self.ot.os_name() driver = None if os_type == "macos": driver_path = self.ut.get_driver_path('/dependencies/dir_operadriver/operadriver_mac64/operadriver') self.ut.set_executable_permission(driver_path) self.log.log_info("Setting path of operadriver") driver = webdriver.Opera(executable_path=driver_path) self.log.log_info("Path for opera binary is set") if os_type == "linux": driver_path = self.ut.get_driver_path('/dependencies/dir_operadriver/operadriver_linux64/operadriver') self.ut.set_executable_permission(driver_path) self.log.log_info("Setting path of operadriver") driver = webdriver.Opera(executable_path=driver_path) self.log.log_info("Path for opera binary is set") return driver except WebDriverException as e: self.log.log_error("There is an exception in the Web Driver configuration") self.log.log_error(e)
class ChromeDriverObject(object): def __init__(self): self.ut = Utility() self.log = Logger() # Set chromedriver path # Pass the option 'headless' if it is needed to run chrome in headless # configuration def set_chromedriver_object(self, chromeArgs): try: chromeArgs = chromeArgs chromeOptions = webdriver.ChromeOptions() driver_path = self.ut.get_driver_path('/dependencies/dir_chromedriver/chromedriver') self.ut.set_executable_permission(driver_path) self.log.log_info("Setting executable permission to the chrome binary") self.log.log_info("Setting path of chromedriver") if not chromeArgs: driver = webdriver.Chrome(executable_path=driver_path) else: while '' in chromeArgs: chromeArgs.remove('') for val in chromeArgs: chromeOptions.add_argument(val) driver = webdriver.Chrome(executable_path=driver_path, options=chromeOptions) self.log.log_info("Path for chrome binary is set") return driver except WebDriverException as e: self.log.log_error("There is an exception in the Web Driver configuration") self.log.log_error(e)
class GeckoDriverObject(object): def __init__(self): self.ut = Utility() self.log = Logger() # Set geckodriver path # Pass the option 'headless' if it is needed to run gecko in headless # configuration def set_geckodriver_object(self, geckoArgs=None): try: geckoArgs = geckoArgs firefoxOptions = Options() driver_path = self.ut.get_driver_path( '/dependencies/dir_geckodriver/geckodriver') self.log.log_info("Setting path of geckodriver") if not geckoArgs: driver = webdriver.Firefox(executable_path=driver_path) else: while '' in geckoArgs: geckoArgs.remove() for val in geckoArgs: firefoxOptions.add_argument(val) driver = webdriver.Firefox(executable_path=driver_path, firefox_options=firefoxOptions) return driver except WebDriverException as e: self.log.log_error( "There is an exception in the Web Driver configuration") self.log.log_error(e)
class PhantomDriverObject(object): def __init__(self): self.ut = Utility() self.log = Logger() # Set chromedriver path # Pass the option 'headless' if it is needed to run chrome in headless # configuration def set_phantomdriver_object(self): try: driver_path = self.ut.get_driver_path('/dependencies/dir_phantomjsdriver/phantomjsdriver/bin/phantomjs') self.ut.set_executable_permission(driver_path) self.log.log_info("Setting executable permission to the phantom binary") driver = webdriver.PhantomJS(executable_path=driver_path) self.log.log_info("Path for phantom binary is set") return driver except WebDriverException as e: self.log.log_error("There is an exception in the Web Driver configuration")
class Geckodriver(object): def __init__(self): self.ut = Utility() self.ot = OS_type() self.log = Logger() # Get the required chromedriver informations from the downloader_config.ini # Use the config_reader function from the Utility class to read the required configuration def geckodriver_object(self): config_parser = self.ut.config_reader() api_url = config_parser.get('GeckoDriver', 'latest_browser_driver') return api_url # build the required download url based on the information gathered using the # geckodriver_objects function def parse_geckodriver_api(self): api_url = self.geckodriver_object() browser_api_url = self.ut.get_api_data(api_url) return browser_api_url # Download the required geckodriver binary based on the operating system type def evaluate_on_environment(self, os_name, arch_type): dir_path = self.ut.get_driver_path('/dependencies/dir_geckodriver') if os_name == 'macos' and arch_type == '64': self.log.log_info("Environment: " + os_name) self.log.log_info("Architecture Type: " + arch_type) url_builder_mac = self.parse_geckodriver_api() self.log.log_info("Downloading the required binary for geckodriver") self.ut.driver_downloader(url_builder_mac['mac'], dir_path) self.log.log_info("Download completed") self.ut.untar_file('dir_geckodriver/') self.log.log_info("Unarchiving contents completed") if os_name == 'linux' and arch_type == '64': self.log.log_info("Environment: " + os_name) self.log.log_info("Architecture Type: " + arch_type) url_builder_linux = self.parse_geckodriver_api() self.log.log_info("Downloading the required binary for geckodriver") self.ut.driver_downloader(url_builder_linux['linux'], dir_path) self.log.log_info("Download completed") self.ut.untar_file('dir_geckodriver/') self.log.log_info("Unarchiving contents completed") if os_name == 'linux' and arch_type == '32': self.log.log_info("Environment: " + os_name) self.log.log_info("Architecture Type: " + arch_type) url_builder_linux = self.parse_geckodriver_api() self.log.log_info("Downloading the required binary for geckodriver") self.ut.driver_downloader(url_builder_linux['linux'], dir_path) self.log.log_info("Download completed") self.ut.untar_file('dir_geckodriver/') self.log.log_info("Unarchiving contents completed") # Create a required directory separately for gecko and called the evaluate_on_environment # function to download the required binary def download_driver(self): dir_path = self.ut.get_driver_path('/dependencies/dir_geckodriver') if os.path.exists(dir_path): self.log.log_info( "gecko driver is already present. To update gecko driver please run `flexibox update " "--driver=geckodriver`" ) else: os.makedirs(dir_path) os_name = self.ot.os_name() arch_type = str(self.ot.os_architecture()) self.evaluate_on_environment(os_name, arch_type) # Update the required geckodriver based on the operating system type def update_driver(self): self.log.log_info("Deleting directory contents") self.ut.check_directory_content("/dependencies/dir_geckodriver/geckodriver") self.ut.delete_dir_contents('dir_geckodriver/') os_name = self.ot.os_name() arch_type = str(self.ot.os_architecture()) self.evaluate_on_environment(os_name, arch_type) self.log.log_info("geckodriver updated")
class Phantomjs_driver(): def __init__(self): self.ut = Utility() self.ot = OS_type() self.log = Logger() # Get the required phsntomjs driver informations from the downloader_config.ini # Use the config_reader function from the Utility class to read the required configuration def phantomjsdriver_object(self): config_parser = self.ut.config_reader() api_url = config_parser.get('PhantomJSDriver', 'latest_browser_driver') return api_url # Get the required API data from the function phantomjsdriver_object def parse_phantomjsdriver_api(self): api_url = self.phantomjsdriver_object() api_data = self.ut.api_parser(api_url) return api_data # Get the required download url based on the information gathered using the # geckodriver_objects function def parse_apidata(self): api_url = {} raw_json = self.parse_phantomjsdriver_api() api_url = { "zip_ball": raw_json['zipball_url'], "tar_ball": raw_json['tarball_url'] } return api_url # Download the required phantomjsdriver binary based on the operating system type def evaluate_on_environment(self, os_name): download_url = self.parse_apidata() dir_path = self.ut.get_driver_path('/dependencies/dir_phantomjsdriver') if os_name == 'macos': self.log.log_info("Environment: " + os_name) self.log.log_info( "Downloading the required binary for phantomjsdriver") self.ut.driver_downloader(download_url['zip_ball'], dir_path) self.log.log_info("Download completed") self.ut.unzip_file('dir_phantomjsdriver/') self.log.log_info("Unarchiving contents completed") self.ut.rename_dir('dir_phantomjsdriver/') if os_name == 'linux': self.log.log_info("Environment: " + os_name) self.log.log_info( "Downloading the required binary for phantomjsdriver") self.ut.driver_downloader(download_url['tar_ball'], dir_path) self.log.log_info("Download completed") self.ut.untar_file('dir_phantomjsdriver/') self.log.log_message("Unarchiving contents completed") self.ut.rename_dir('dir_phantomjsdriver/') # Create a required directory separately for phantomjs and called the evaluate_on_environment # function to download the required binary def download_driver(self): dir_path = self.ut.get_driver_path('/dependencies/dir_phantomjsdriver') if os.path.exists(dir_path): self.log.log_info( "phantomjs driver is already present. To update phantomjsdriver please run `flexibox update --driver=phantomjsdriver`" ) else: os.makedirs(dir_path) os_name = self.ot.os_name() self.evaluate_on_environment(os_name) # Update the required phantomjsdriver based on the operating system type def update_driver(self): self.log.log_info("Deleting directory contents") self.ut.check_directory_content('/dependencies/dir_phantomjsdriver') self.ut.delete_dir_contents('dir_phantomjsdriver/') os_name = self.ot.os_name() self.evaluate_on_environment(os_name) self.log.log_info("phantomjs driver updated")
class Chromedriver(object): def __init__(self): self.ut = Utility() self.ot = OS_type() self.log = Logger() # Get the required chromedriver informations from the downloader_config.ini # Use the config_reader function from the Utility class to read the required configuration def chromedriver_objects(self): config_dict = {} config_parser = self.ut.config_reader() driver_type = config_parser.get('ChromeDriver', 'name') api_url = config_parser.get('ChromeDriver', 'url') latest_release = config_parser.get('ChromeDriver', 'latest_browser_driver') arch = config_parser.get('ChromeDriver', 'arch_type') config_dict = { 'driver_type': driver_type, 'api_url': api_url, 'latest_release': latest_release, 'arch': arch } return config_dict # build the required download url based on the information gathered using the # chromedriver_objects function def url_builder(self, os_extension): data = self.chromedriver_objects() LATEST_RELEASE = requests.get(data['latest_release']) url_builder = data['api_url'] + LATEST_RELEASE.text + '/' + data[ 'driver_type'] + os_extension + data['arch'] + '.zip' return url_builder # Download the required chromedriver binary based on the operating system type def evaluate_on_environment(self, os_name, arch_type): dir_path = self.ut.get_driver_path("/dependencies/dir_chromedriver") if os_name == 'macos' and arch_type == '64': self.ut.log_message("INFO", "Environment: " + os_name) self.ut.log_message("INFO", "Architecture Type: " + arch_type) url_builder_mac = self.url_builder('_mac') self.ut.log_message( "INFO", "Downloading the required binary for chromedriver") self.ut.driver_downloader(url_builder_mac, dir_path) self.ut.log_message("INFO", "Download completed") self.ut.unzip_file('dir_chromedriver/') self.ut.log_message("INFO", "Unarchiving contents completed") if os_name == 'linux' and arch_type == '64': self.ut.log_message("INFO", "Environment: " + os_name) self.ut.log_message("INFO", "Architecture Type: " + arch_type) url_builder_linux = self.url_builder('_linux') self.ut.log_message( "INFO", "Downloading the required binary for chromedriver") self.ut.driver_downloader(url_builder_linux, dir_path) self.ut.log_message("INFO", "Download completed") self.ut.unzip_file('dir_chromedriver/') self.ut.log_message("INFO", "Unarchiving contents completed") # Create a required directory separately for Chrome and called the evaluate_on_environment # function to download the required binary def download_driver(self): dir_path = self.ut.get_driver_path("/dependencies/dir_chromedriver") if os.path.exists(dir_path): self.ut.log_message( "INFO", "chrome driver is already present. To update chromedriver please run `flexibox update --driver=chromedriver`" ) else: os.makedirs(dir_path) os_name = self.ot.os_name() arch_type = str(self.ot.os_architecture()) self.evaluate_on_environment(os_name, arch_type) # Update the required chromedriver based on the operating system type def update_driver(self): self.ut.check_directory_content( "/dependencies/dir_chromedriver/chromedriver") self.ut.log_message("INFO", "Deleting directory contents") self.ut.delete_dir_contents('dir_chromedriver/') os_name = self.ot.os_name() arch_type = str(self.ot.os_architecture()) self.evaluate_on_environment(os_name, arch_type) self.ut.log_message("INFO", "chromedriver updated")