How to use get_latest_release_version method in webdriver_manager

Best Python code snippet using webdriver_manager

driver.py

Source:driver.py Github

copy

Full Screen

...31 return f"{self._url}/{self.get_version()}/{self.get_name()}_{self.get_os_type()}.zip"32 def get_version(self):33 driver_version = self._version34 if driver_version == "latest":35 return self.get_latest_release_version()36 return self._version37 def get_latest_release_version(self):38 # type: () -> str39 raise NotImplementedError("Please implement this method")40class ChromeDriver(Driver):41 def __init__(self, name, version, os_type, url, latest_release_url,42 chrome_type=ChromeType.GOOGLE):43 super(ChromeDriver, self).__init__(name, version, os_type, url,44 latest_release_url)45 self.chrome_type = chrome_type46 self.browser_version = chrome_version(chrome_type)47 def get_os_type(self):48 if "win" in super().get_os_type():49 return "win32"50 return super().get_os_type()51 def get_latest_release_version(self):52 log(f"Get LATEST driver version for {self.browser_version}")53 resp = requests.get(f"{self._latest_release_url}_{self.browser_version}")54 validate_response(resp)55 return resp.text.rstrip()56class GeckoDriver(Driver):57 def __init__(self, name,58 version,59 os_type,60 url,61 latest_release_url,62 mozila_release_tag):63 super(GeckoDriver, self).__init__(name, version, os_type, url,64 latest_release_url)65 self._mozila_release_tag = mozila_release_tag66 self._os_token = os.getenv("GH_TOKEN", None)67 self.auth_header = None68 self.browser_version = firefox_version()69 if self._os_token:70 log("GH_TOKEN will be used to perform requests", first_line=True)71 self.auth_header = {'Authorization': f'token {self._os_token}'}72 def get_latest_release_version(self):73 # type: () -> str74 log(f"Get LATEST driver version for {self.browser_version}")75 resp = requests.get(url=self.latest_release_url,76 headers=self.auth_header)77 validate_response(resp)78 return resp.json()["tag_name"]79 def get_url(self):80 # https://github.com/mozilla/geckodriver/releases/download/v0.11.1/geckodriver-v0.11.1-linux64.tar.gz81 log(f"Getting latest mozilla release info for {self.get_version()}")82 resp = requests.get(url=self.tagged_release_url(self.get_version()),83 headers=self.auth_header)84 validate_response(resp)85 assets = resp.json()["assets"]86 name = f"{self.get_name()}-{self.get_version()}-{self.get_os_type()}{'-aarch64' if (self.get_os_type() == 'macos' and not platform.processor() == 'i386') else ''}" + "."87 output_dict = [asset for asset in assets if88 asset['name'].startswith(name)]89 return output_dict[0]['browser_download_url']90 def get_os_type(self):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]205 latest_release_url = self._latest_release_url + '_' + major_edge_version206 resp = requests.get(latest_release_url)207 validate_response(resp)...

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