Best Python code snippet using webdriver_manager
driver.py
Source:driver.py
...104 def get_url(self):105 """Like https://github.com/mozilla/geckodriver/releases/download/v0.11.1/geckodriver-v0.11.1-linux64.tar.gz"""106 log(f"Getting latest mozilla release info for {self.get_version()}")107 resp = requests.get(108 url=self.tagged_release_url(self.get_version()),109 headers=self.auth_header,110 verify=self.ssl_verify,111 )112 validate_response(resp)113 assets = resp.json()["assets"]114 name = f"{self.get_name()}-{self.get_version()}-{self.get_os_type()}."115 output_dict = [116 asset for asset in assets if asset['name'].startswith(name)117 ]118 return output_dict[0]['browser_download_url']119 def get_os_type(self):120 mac = f'macos{"-aarch64" if platform.processor() != "i386" else ""}'121 return mac if 'mac' in super().get_os_type() else super().get_os_type()122 @property123 def latest_release_url(self):124 return self._latest_release_url125 def tagged_release_url(self, version):126 return self._mozila_release_tag.format(version)127class IEDriver(Driver):128 def __init__(129 self,130 name,131 version,132 os_type,133 url,134 latest_release_url,135 ie_release_tag,136 ):137 super(IEDriver, self).__init__(138 name,139 version,140 os_type,141 url,142 latest_release_url,143 )144 self.os_type = "x64" if os_type == "win64" else "Win32"145 self._ie_release_tag = ie_release_tag146 # todo: for 'browser_version' implement installed IE version detection147 # like chrome or firefox148 self.browser_version = ""149 self._os_token = os.getenv("GH_TOKEN", None)150 self.auth_header = (151 {'Authorization': f'token {self._os_token}'}152 if self._os_token153 else None154 )155 if self._os_token:156 log("GH_TOKEN will be used to perform requests", first_line=True)157 def get_latest_release_version(self) -> str:158 log(f"Get LATEST driver version for {self.browser_version}")159 resp = requests.get(160 url=self.latest_release_url,161 headers=self.auth_header,162 verify=self.ssl_verify,163 )164 validate_response(resp)165 releases = resp.json()166 release = next(167 release168 for release in releases169 for asset in release['assets']170 if asset['name'].startswith(self.get_name())171 )172 self._version = release['tag_name'].replace('selenium-', '')173 return self._version174 def get_url(self):175 """Like https://github.com/seleniumhq/selenium/releases/download/3.141.59/IEDriverServer_Win32_3.141.59.zip"""176 log(f"Getting latest ie release info for {self.get_version()}")177 resp = requests.get(178 url=self.tagged_release_url(self.get_version()),179 headers=self.auth_header,180 verify=self.ssl_verify,181 )182 validate_response(resp)183 assets = resp.json()["assets"]184 name = f"{self.get_name()}_{self.os_type}_{self.get_version()}" + "."185 output_dict = [186 asset for asset in assets if asset['name'].startswith(name)187 ]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 version = self.__get_divided_version(version)194 return self._ie_release_tag.format(version)195 def __get_divided_version(self, version):196 divided_version = version.split('.')197 if len(divided_version) == 2:198 return f'{version}.0'199 elif len(divided_version) == 3:200 return version201 else:202 raise ValueError(203 "Version must consist of major, minor and/or patch, "204 "but given was: '{version}'".format(version=version)205 )206class OperaDriver(Driver):207 def __init__(self, name,208 version,209 os_type,210 url,211 latest_release_url,212 opera_release_tag):213 super(OperaDriver, self).__init__(name, version, os_type, url,214 latest_release_url)215 self.opera_release_tag = opera_release_tag216 self._os_token = os.getenv("GH_TOKEN", None)217 self.auth_header = None218 self.browser_version = ""219 if self._os_token:220 log("GH_TOKEN will be used to perform requests")221 self.auth_header = {'Authorization': f'token {self._os_token}'}222 def get_latest_release_version(self) -> str:223 resp = requests.get(224 url=self.latest_release_url,225 headers=self.auth_header,226 verify=self.ssl_verify,227 )228 validate_response(resp)229 self._version = resp.json()["tag_name"]230 return self._version231 def get_url(self) -> str:232 # https://github.com/operasoftware/operachromiumdriver/releases/download/v.2.45/operadriver_linux64.zip233 version = self.get_version()234 log(f"Getting latest opera release info for {version}")235 resp = requests.get(236 url=self.tagged_release_url(version),237 headers=self.auth_header,238 verify=self.ssl_verify,239 )240 validate_response(resp)241 assets = resp.json()["assets"]242 name = "{0}_{1}".format(self.get_name(), self.get_os_type())243 output_dict = [asset for asset in assets if244 asset['name'].startswith(name)]245 return output_dict[0]['browser_download_url']246 @property247 def latest_release_url(self):248 return self._latest_release_url249 def tagged_release_url(self, version):250 return self.opera_release_tag.format(version)251class EdgeChromiumDriver(Driver):252 def __init__(253 self,254 name,255 version,256 os_type,257 url,258 latest_release_url,259 ):260 super(EdgeChromiumDriver, self).__init__(261 name,262 version,263 os_type,...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!