How to use latest_release_url method in webdriver_manager

Best Python code snippet using webdriver_manager

driver.py

Source:driver.py Github

copy

Full Screen

...91 if super().get_os_type().startswith("mac"):92 return "macos"93 return super().get_os_type()94 @property95 def latest_release_url(self):96 return self._latest_release_url97 def tagged_release_url(self, version):98 return self._mozila_release_tag.format(version)99class IEDriver(Driver):100 def __init__(self, name, version,101 os_type,102 url,103 latest_release_url):104 if os_type == "win64":105 os_type = "x64"106 else:107 os_type = "Win32"108 super(IEDriver, self).__init__(version=version,109 os_type=os_type,110 url=url,111 latest_release_url=latest_release_url,112 name=name)113 self.browser_version = ""114 def sortchildrenby(self, container):115 data = []116 for elem in container.iter("Contents"):117 key = elem118 data.append((key, elem))119 data.sort()120 def get_latest_release_version(self):121 resp = requests.get(self._url)122 root = ElementTree.fromstring(resp.text)123 values = {}124 xmlns = '{http://doc.s3.amazonaws.com/2006-03-01}'125 for child in root.findall(xmlns + 'Contents'):126 key = child.find(xmlns + 'Key').text127 if self.get_name() in key and self._os_type in key:128 last_modified = child.find(xmlns + 'LastModified').text129 values[last_modified] = key130 latest_key = values[max(values)]131 # 2.39/IEDriverServer_Win32_2.39.0.zip132 m = re.match(r".*_{os}_(.*)\.zip".format(os=self.get_os_type()),133 latest_key)134 if m:135 return m.group(1)136 else:137 raise ValueError("Can't parse latest version {key} | {os}".format(138 key=latest_key, os=self.get_os_type()))139 def get_url(self):140 major, minor, patch = self.__get_divided_version(self.get_version())141 return ("{url}/{major}.{minor}/"142 "{name}_{os}_{major}.{minor}.{patch}.zip").format(143 url=self._url, name=self.get_name(), os=self.get_os_type(),144 major=major, minor=minor, patch=patch)145 def __get_divided_version(self, version):146 divided_version = version.split('.')147 if len(divided_version) == 2:148 return divided_version[0], divided_version[1], '0'149 elif len(divided_version) == 3:150 return divided_version151 else:152 raise ValueError(153 "Version must consist of major, minor and/or patch, "154 "but given was: {version}".format(version=self.get_version()))155class OperaDriver(Driver):156 def __init__(self, name,157 version,158 os_type,159 url,160 latest_release_url,161 opera_release_tag):162 super(OperaDriver, self).__init__(name, version, os_type, url,163 latest_release_url)164 self.opera_release_tag = opera_release_tag165 self._os_token = os.getenv("GH_TOKEN", None)166 self.auth_header = None167 self.browser_version = ""168 if self._os_token:169 log("GH_TOKEN will be used to perform requests")170 self.auth_header = {'Authorization': f'token {self._os_token}'}171 def get_latest_release_version(self):172 # type: () -> str173 resp = requests.get(self.latest_release_url, headers=self.auth_header)174 validate_response(resp)175 return resp.json()["tag_name"]176 def get_url(self):177 # type: () -> str178 # https://github.com/operasoftware/operachromiumdriver/releases/download/v.2.45/operadriver_linux64.zip179 version = self.get_version()180 log(f"Getting latest opera release info for {version}")181 resp = requests.get(url=self.tagged_release_url(version),182 headers=self.auth_header)183 validate_response(resp)184 assets = resp.json()["assets"]185 name = "{0}_{1}".format(self.get_name(), self.get_os_type())186 output_dict = [asset for asset in assets if187 asset['name'].startswith(name)]188 return output_dict[0]['browser_download_url']189 @property190 def latest_release_url(self):191 return self._latest_release_url192 def tagged_release_url(self, version):193 return self.opera_release_tag.format(version)194class EdgeChromiumDriver(Driver):195 def __init__(self, name, version, os_type, url, latest_release_url):196 super(EdgeChromiumDriver, self).__init__(name, version, os_type, url,197 latest_release_url)198 self.browser_version = ""199 def get_latest_release_version(self):200 # type: () -> str201 if os_name() == OSType.LINUX:202 latest_release_url = "https://msedgedriver.azureedge.net/LATEST_STABLE"203 else:204 major_edge_version = chrome_version(ChromeType.MSEDGE).split(".")[0]...

Full Screen

Full Screen

manager.py

Source:manager.py Github

copy

Full Screen

1import os2import winreg3import logging4import requests5from functools import lru_cache6from win32api import GetFileVersionInfo, LOWORD, HIWORD7from webdriver_manager import utils8from webdriver_manager.driver import Driver9from webdriver_manager.logger import log10from webdriver_manager.manager import DriverManager11from webdriver_manager.utils import ChromeType, validate_response, OSType, os_name, download_file12@lru_cache(1)13def get_installed_browsers() -> dict:14 browsers = dict()15 with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\Clients\StartMenuInternet", 0, winreg.KEY_READ) as key:16 for i in range(winreg.QueryInfoKey(key)[0]):17 browser = winreg.EnumKey(key, i)18 with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,19 fr"SOFTWARE\WOW6432Node\Clients\StartMenuInternet\{browser}\shell\open", 0,20 winreg.KEY_READ) as key1:21 browsers[browser] = winreg.QueryValue(key1, "command")22 for name in browsers:23 browsers[name] = browsers[name].replace('"', "")24 return browsers25def get_version(path: str) -> str:26 try:27 info = GetFileVersionInfo(path, "\\")28 ms: str = info['FileVersionMS']29 ls: str = info['FileVersionLS']30 return f"{HIWORD(ms)}.{LOWORD(ms)}.{HIWORD(ls)}.{LOWORD(ls)}"31 except Exception as ex:32 print(ex)33 return "Unknown version"34def browser_exists(browser: str) -> bool:35 return True if browser in get_installed_browsers() else False36def browser_version(browser: str):37 return get_version(get_installed_browsers()[browser])38class ChromeDriver(Driver):39 def __init__(self, name, version, os_type, url, latest_release_url,40 chrome_type=ChromeType.GOOGLE):41 super(ChromeDriver, self).__init__(name, version, os_type, url,42 latest_release_url)43 self.chrome_type = chrome_type44 self.browser_version = ".".join(browser_version("Google Chrome").split(".")[:-1])45 def get_os_type(self):46 if "win" in super().get_os_type():47 return "win32"48 return super().get_os_type()49 def get_latest_release_version(self):50 log(f"Get LATEST driver version for {self.browser_version}")51 resp = requests.get(f"{self._latest_release_url}_{self.browser_version}")52 validate_response(resp)53 return resp.text.rstrip()54class ChromeDriverManager(DriverManager):55 def __init__(self, version="latest",56 os_type=utils.os_type(),57 path=None,58 name="chromedriver",59 url="https://chromedriver.storage.googleapis.com",60 latest_release_url="https://chromedriver.storage.googleapis.com/LATEST_RELEASE",61 chrome_type=ChromeType.GOOGLE,62 log_level=logging.INFO,63 print_first_line=True,64 cache_valid_range=1):65 super().__init__(path, log_level=log_level, print_first_line=print_first_line,66 cache_valid_range=cache_valid_range)67 self.driver = ChromeDriver(name=name,68 version=version,69 os_type=os_type,70 url=url,71 latest_release_url=latest_release_url,72 chrome_type=chrome_type)73 def install(self):74 log(f"Current {self.driver.chrome_type} version is {self.driver.browser_version}", first_line=True)75 driver_path = self._get_driver_path(self.driver)76 os.chmod(driver_path, 0o755)77 return driver_path78class EdgeChromiumDriver(Driver):79 def __init__(self, name, version, os_type, url, latest_release_url):80 super(EdgeChromiumDriver, self).__init__(name, version, os_type, url,81 latest_release_url)82 self.browser_version = ""83 def get_latest_release_version(self):84 # type: () -> str85 if os_name() == OSType.LINUX:86 latest_release_url = "https://msedgedriver.azureedge.net/LATEST_STABLE"87 else:88 major_edge_version = browser_version("Microsoft Edge").split(".")[0]89 latest_release_url = self._latest_release_url + '_' + major_edge_version90 resp = requests.get(latest_release_url)91 validate_response(resp)92 return resp.text.rstrip()93class EdgeChromiumDriverManager(DriverManager):94 def __init__(self, version="latest",95 os_type=utils.os_type(),96 path=None,97 name="edgedriver",98 url="https://msedgedriver.azureedge.net",99 latest_release_url="https://msedgedriver.azureedge.net/"100 "LATEST_RELEASE",101 log_level=None,102 print_first_line=None,103 cache_valid_range=1):104 super().__init__(path, log_level, print_first_line, cache_valid_range)105 self.driver = EdgeChromiumDriver(version=version,106 os_type=os_type,107 name=name,108 url=url,109 latest_release_url=latest_release_url)110 def install(self):111 return self._get_driver_path(self.driver)112if __name__ == '__main__':113 print(get_installed_browsers())114 print("Google Chrome", browser_exists("Google Chrome"), browser_version("Google Chrome"))...

Full Screen

Full Screen

microsoft.py

Source:microsoft.py Github

copy

Full Screen

1from webdriver_manager import utils2from webdriver_manager.driver import EdgeChromiumDriver3from webdriver_manager.driver import IEDriver4from webdriver_manager.manager import DriverManager5class IEDriverManager(DriverManager):6 def __init__(self, version="latest",7 os_type=utils.os_type(),8 path=None,9 name="IEDriverServer",10 url="http://selenium-release.storage.googleapis.com",11 latest_release_url=None,12 log_level=None,13 print_first_line=True,14 cache_valid_range=1):15 super().__init__(path, log_level, print_first_line, cache_valid_range)16 self.driver = IEDriver(version=version,17 os_type=os_type,18 name=name,19 url=url,20 latest_release_url=latest_release_url)21 def install(self):22 return self._get_driver_path(self.driver)23class EdgeChromiumDriverManager(DriverManager):24 def __init__(self, version="latest",25 os_type=utils.os_type(),26 path=None,27 name="edgedriver",28 url="https://msedgedriver.azureedge.net",29 latest_release_url="https://msedgedriver.azureedge.net/"30 "LATEST_RELEASE",31 log_level=None,32 print_first_line=None,33 cache_valid_range=1):34 super().__init__(path, log_level, print_first_line, cache_valid_range)35 self.driver = EdgeChromiumDriver(version=version,36 os_type=os_type,37 name=name,38 url=url,39 latest_release_url=latest_release_url)40 def install(self):...

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 webdriver_manager 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