Best Python code snippet using SeleniumBase
base_case.py
Source:base_case.py
...1684 browser_name = self.driver.capabilities["browserName"]1685 if browser_name.lower() in ("chrome", "edge", "msedge", "opera"):1686 chromium = True1687 return chromium1688 def __fail_if_not_using_chrome(self, method):1689 chrome = False1690 browser_name = self.driver.capabilities["browserName"]1691 if browser_name.lower() == "chrome":1692 chrome = True1693 if not chrome:1694 from seleniumbase.common.exceptions import NotUsingChromeException1695 message = (1696 'Error: "%s" should only be called '1697 'by tests running with self.browser == "chrome"! '1698 'You should add an "if" statement to your code before calling '1699 "this method if using browsers that are Not Chrome! "1700 'The browser detected was: "%s".' % (method, browser_name)1701 )1702 raise NotUsingChromeException(message)1703 def get_chrome_version(self):1704 self.__check_scope()1705 self.__fail_if_not_using_chrome("get_chrome_version()")1706 driver_capabilities = self.driver.capabilities1707 if "version" in driver_capabilities:1708 chrome_version = driver_capabilities["version"]1709 else:1710 chrome_version = driver_capabilities["browserVersion"]1711 return chrome_version1712 def get_chromedriver_version(self):1713 self.__check_scope()1714 self.__fail_if_not_using_chrome("get_chromedriver_version()")1715 chrome_dict = self.driver.capabilities["chrome"]1716 chromedriver_version = chrome_dict["chromedriverVersion"]1717 chromedriver_version = chromedriver_version.split(" ")[0]1718 return chromedriver_version1719 def is_chromedriver_too_old(self):1720 """There are known issues with chromedriver versions below 73.1721 This can impact tests that need to hover over an element, or ones1722 that require a custom downloads folder ("./downloaded_files").1723 Due to the situation that newer versions of chromedriver require1724 an exact match to the version of Chrome, an "old" version of1725 chromedriver is installed by default. It is then up to the user1726 to upgrade to the correct version of chromedriver from there.1727 This method can be used to change test behavior when trying1728 to perform an action that is impacted by having an old version1729 of chromedriver installed."""1730 self.__check_scope()1731 self.__fail_if_not_using_chrome("is_chromedriver_too_old()")1732 if int(self.get_chromedriver_version().split(".")[0]) < 73:1733 return True # chromedriver is too old! Please upgrade!1734 return False1735 def get_google_auth_password(self, totp_key=None):1736 """Returns a time-based one-time password based on the1737 Google Authenticator password algorithm. Works with Authy.1738 If "totp_key" is not specified, defaults to using the one1739 provided in seleniumbase/config/settings.py1740 Google Auth passwords expire and change at 30-second intervals.1741 If the fetched password expires in the next 1.5 seconds, waits1742 for a new one before returning it (may take up to 1.5 seconds).1743 See https://pyotp.readthedocs.io/en/latest/ for details."""1744 import pyotp1745 if not totp_key:...
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!!