Best Python code snippet using webdriver_manager
shim.py
Source: shim.py
...21 except subprocess.CalledProcessError as e:22 if silent:23 return None24 raise e25def get_browser_type(string):26 for t in BROWSER_TYPES:27 if t in string:28 return t29 raise ValueError("couldn't get browser type from {}".format(string))30def get_browser_name(string):31 if ('/' in string) or ('\\' in string): # its a path32 return os.path.basename(string)33 else: # its a browser type34 for bn in BROWSER_NAMES:35 if string in bn and unix_which(bn, silent=True):36 return os.path.basename(unix_which(bn))37 raise ValueError('Could not get browser name from {}'.format(string))38def build_crx():39 '''Builds the .crx file for Chrome and returns the path to it'''40 cmd = [os.path.join(get_git_root(), 'make.sh'), '--remove-update-channels']41 run_shell_command(cmd)42 # Since this is an unpacked extension we're loading, the extension ID is43 # determined by the below `crx_dir` path alone. Don't alter it without44 # changing the corresponding ID at the top of this file.45 crx_dir = os.path.join(os.sep, 'tmp','https-everywhere-test')46 shutil.rmtree(crx_dir, True)47 shutil.copytree(os.path.join(get_git_root(), 'pkg', 'crx-cws'), crx_dir)48 return crx_dir49def build_xpi():50 cmd = [os.path.join(get_git_root(), 'make.sh'), '--remove-update-channels']51 return os.path.join(get_git_root(), run_shell_command(cmd).split()[-5])52def install_ext_on_ff(driver, extension_path):53 '''54 Use Selenium's internal API's to manually send a message to geckodriver55 to install the extension. We should remove this once the functionality is56 included in Selenium. See https://github.com/SeleniumHQ/selenium/issues/421557 '''58 command = 'addonInstall'59 driver.install_addon(extension_path, temporary = True)60 time.sleep(2)61class Shim:62 _browser_msg = '''BROWSER should be one of:63* /path/to/a/browser64* a browser executable name so we can find the browser with "which $BROWSER"65* something from BROWSER_TYPES66'''67 __doc__ = 'Chooses the correct driver and extension_url based on the BROWSER environment\nvariable. ' + _browser_msg68 def __init__(self, chrome_info, firefox_info):69 print('Configuring the test run')70 self.chrome_info, self.firefox_info = chrome_info, firefox_info71 self._specifics = None72 browser = os.environ.get('BROWSER')73 # get browser_path and broser_type first74 if browser is None:75 raise ValueError("The BROWSER environment variable is not set. " + self._browser_msg)76 elif ("/" in browser) or ("\\" in browser): # path to a browser binary77 self.browser_path = browser78 self.browser_type = get_browser_type(self.browser_path)79 elif unix_which(browser, silent=True): # executable browser name like 'google-chrome-stable'80 self.browser_path = unix_which(browser)81 self.browser_type = get_browser_type(browser)82 elif get_browser_type(browser): # browser type like 'firefox' or 'chrome'83 bname = get_browser_name(browser)84 self.browser_path = unix_which(bname)85 self.browser_type = browser86 else:87 raise ValueError("could not infer BROWSER from {}".format(browser))88 self.extension_path = self.get_ext_path()89 self._set_specifics()90 print('\nUsing browser path: {} \nwith browser type: {} \nand extension path: {}'.format(self.browser_path, self.browser_type, self.extension_path))91 self._set_urls(self.base_url)92 def _set_specifics(self):93 self._specifics = self._specifics or {94 'chrome': Specifics(self.chrome_manager,95 'chrome-extension://{}/'.format(self.chrome_info['extension_id']),96 self.chrome_info),...
page_object_driver.py
Source: page_object_driver.py
...16 cls.base_url = driverOptions.url17 driver_path = Path(__file__).parent.parent + "\drivers"18 19 browser_type = driverOptions.browser20 web_driver = cls.get_browser_type(browser_type, driver_path)21 return web_driver22 23 @classmethod24 def get_browser_type(cls, browser_type, driver_path):25 switcher={26 'Chrome': webdriver.Chrome(driver_path),27 'Edge':webdriver.Edge(driver_path),28 'Firefox':webdriver.Firefox(driver_path),29 }30 return switcher.get(browser_type,webdriver.Chrome(driver_path))
...
browser_factory.py
Source: browser_factory.py
...10 options.add_experimental_option("prefs", {11 "safebrowsing.enabled": True,12 "intl.accept_languages": f"{Config().get_language()}"13 })14 if Config().get_browser_type() == 'Chrome':15 return webdriver.Chrome(executable_path=ChromeDriverManager().install(), chrome_options=options)16 elif Config().get_browser_type() == 'Firefox':17 return webdriver.Firefox(executable_path=GeckoDriverManager().install())18 else:...
Check out the latest blogs from LambdaTest on this topic:
The automation backend architecture of Appium has undergone significant development along with the release of numerous new capabilities. With the advent of Appium, test engineers can cover mobile apps, desktop apps, Flutter apps, and more.
People love to watch, read and interact with quality content — especially video content. Whether it is sports, news, TV shows, or videos captured on smartphones, people crave digital content. The emergence of OTT platforms has already shaped the way people consume content. Viewers can now enjoy their favorite shows whenever they want rather than at pre-set times. Thus, the OTT platform’s concept of viewing anything, anytime, anywhere has hit the right chord.
Have you ever visited a website that only has plain text and images? Most probably, no. It’s because such websites do not exist now. But there was a time when websites only had plain text and images with almost no styling. For the longest time, websites did not focus on user experience. For instance, this is how eBay’s homepage looked in 1999.
Hey Folks! Welcome back to the latest edition of LambdaTest’s product updates. Since programmer’s day is just around the corner, our incredible team of developers came up with several new features and enhancements to add some zing to your workflow. We at LambdaTest are continuously upgrading the features on our platform to make lives easy for the QA community. We are releasing new functionality almost every week.
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!!