How to use get_browser_type method in webdriver_manager

Best Python code snippet using webdriver_manager

shim.py

Source:shim.py Github

copy

Full Screen

...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),...

Full Screen

Full Screen

page_object_driver.py

Source:page_object_driver.py Github

copy

Full Screen

...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)) ...

Full Screen

Full Screen

browser_factory.py

Source:browser_factory.py Github

copy

Full Screen

...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:...

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