Best Python code snippet using SeleniumBase
upgrade_chromedriver.py
Source:upgrade_chromedriver.py
...34 )35 """36 )37 return testdir38 def print_versions_of_chromedriver_and_chrome(self, testdir):39 testdir.makepyfile(40 """41 from seleniumbase import BaseCase42 class MyTestCase(BaseCase):43 def test_print_versions(self):44 chrome_version = self.get_chrome_version()45 major_chrome_ver = chrome_version.split(".")[0]46 chromedriver_ver = self.get_chromedriver_version()47 major_chromedriver_ver = chromedriver_ver.split(".")[0]48 print(49 "\\n* Now using chromedriver %s with Chrome %s"50 % (chromedriver_ver, chrome_version)51 )52 if major_chromedriver_ver == major_chrome_ver:53 print(54 "* SUCCESS: "55 "The chromedriver version is compatible "56 "with Chrome!"57 )58 elif major_chromedriver_ver < major_chrome_ver:59 print("* !!! Version Mismatch !!!")60 print(61 "* The version of chromedriver is too low!\\n"62 "* Try upgrading to chromedriver %s manually:\\n"63 "* >>> sbase get chromedriver %s <<<"64 % (major_chrome_ver, major_chrome_ver)65 )66 else:67 print("* !!! Version Mismatch !!!")68 print(69 "* The version of chromedriver is too high!\\n"70 "* Try downgrading to chromedriver %s manually:\\n"71 "* >>> sbase get chromedriver %s <<<"72 % (major_chrome_ver, major_chrome_ver)73 )74 """75 )76 return testdir77 def test_upgrade_chromedriver(self, testdir):78 if "linux" not in sys.platform and "darwin" not in sys.platform:79 print("\n This script is for Linux/macOS systems only!")80 self.skip("This script is for Linux/macOS systems only!")81 # Find out if the installed chromedriver version works with Chrome82 testdir = self.basic_run(testdir)83 result = testdir.inline_run("--headless")84 try:85 assert result.matchreport("test_passing").passed86 except Exception:87 # Install the compatibility version of chromedriver88 subprocess.check_call(89 "seleniumbase get chromedriver 72.0.3626.69", shell=True90 )91 # Upgrade chromedriver to match the installed version of Chrome92 testdir = self.upgrade_chromedriver(testdir)93 result = testdir.inline_run("--headless", "-s")94 # Print the final installed versions of chromedriver and Chrome95 testdir = self.print_versions_of_chromedriver_and_chrome(testdir)...
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!!