Best Python code snippet using SeleniumBase
test_download_files.py
Source: test_download_files.py
...9 "/101.0.4951.41/%s" % notes_file10 )11 self.download_file(notes_link)12 self.assert_downloaded_file(notes_file)13 notes_path = self.get_path_of_downloaded_file(notes_file)14 with open(notes_path, "r") as f:15 notes_data = f.read()16 self.assert_true(len(notes_data) > 100) # Verify file not empty17 text = "Switching to nested frame fails with chrome/chromedriver 100"18 self.assert_true(text in notes_data) # Verify file has expected data19 def test_download_files_from_pypi_with_edge(self):20 if self.browser != "edge":21 self.open("data:,")22 print("\n This test is only for Microsoft Edge (Chromium)!")23 print(' (Run this test using "--edge" or "--browser=edge")')24 self.skip('Use "--edge" or "--browser=edge"')25 self.open("https://pypi.org/project/seleniumbase/#files")26 pkg_header = self.get_text("h1.package-header__name").strip()27 pkg_name = pkg_header.replace(" ", "-")28 whl_file = pkg_name + "-py2.py3-none-any.whl"29 tar_gz_file = pkg_name + ".tar.gz"30 # Click the links to download the files into: "./downloaded_files/"31 # (If using Safari, IE, or Chromium Guest Mode: download directly.)32 # (The default Downloads Folder can't be changed when using those.)33 # (The same problem occurs when using an out-of-date chromedriver.)34 # (Use self.get_browser_downloads_folder() to get the folder used.)35 whl_selector = 'div#files a[href$="%s"]' % whl_file36 tar_selector = 'div#files a[href$="%s"]' % tar_gz_file37 if (38 self.browser == "safari"39 or self.browser == "ie"40 or (self.is_chromium() and self.guest_mode and not self.headless)41 or (42 self.browser == "chrome"43 and self.is_chromedriver_too_old()44 and self.headless45 )46 ):47 whl_href = self.get_attribute(whl_selector, "href")48 tar_href = self.get_attribute(tar_selector, "href")49 self.download_file(whl_href)50 self.download_file(tar_href)51 else:52 self.click(whl_selector)53 self.click(tar_selector)54 # Verify that the downloaded files appear in the [Downloads Folder]55 # (This only guarantees that the exact file name is in the folder.)56 # (This does not guarantee that the downloaded files are complete.)57 # (Later, we'll check that the files were downloaded successfully.)58 self.assert_downloaded_file(whl_file)59 self.assert_downloaded_file(tar_gz_file)60 self.sleep(1) # Add more time to make sure downloads have completed61 # Get the actual size of the downloaded files (in bytes)62 whl_path = self.get_path_of_downloaded_file(whl_file)63 with open(whl_path, "rb") as f:64 whl_file_bytes = len(f.read())65 print("\n%s | Download = %s bytes." % (whl_file, whl_file_bytes))66 tar_gz_path = self.get_path_of_downloaded_file(tar_gz_file)67 with open(tar_gz_path, "rb") as f:68 tar_gz_file_bytes = len(f.read())69 print("%s | Download = %s bytes." % (tar_gz_file, tar_gz_file_bytes))70 # Check to make sure the downloaded files are not empty or too small71 self.assert_true(whl_file_bytes > 5000)72 self.assert_true(tar_gz_file_bytes > 5000)73 # Get file sizes in kB to compare actual values with displayed values74 whl_file_kb = whl_file_bytes / 1000.075 whl_line_fi = self.get_text('a[href$=".whl"]').strip()76 whl_line = self.get_text('div.file:contains("%s")' % whl_line_fi)77 whl_display_kb = float(whl_line.split("(")[1].split(" ")[0])78 tar_gz_file_kb = tar_gz_file_bytes / 1000.079 tar_gz_line_fi = self.get_text('a[href$=".tar.gz"]').strip()80 tar_gz_line = self.get_text('div.file:contains("%s")' % tar_gz_line_fi)...
Check out the latest blogs from LambdaTest on this topic:
The QA testing profession requires both educational and long-term or experience-based learning. One can learn the basics from certification courses and exams, boot camp courses, and college-level courses where available. However, developing instinctive and practical skills works best when built with work experience.
Ever since the Internet was invented, web developers have searched for the most efficient ways to display content on web browsers.
In general, software testers have a challenging job. Software testing is frequently the final significant activity undertaken prior to actually delivering a product. Since the terms “software” and “late” are nearly synonymous, it is the testers that frequently catch the ire of the whole business as they try to test the software at the end. It is the testers who are under pressure to finish faster and deem the product “release candidate” before they have had enough opportunity to be comfortable. To make matters worse, if bugs are discovered in the product after it has been released, everyone looks to the testers and says, “Why didn’t you spot those bugs?” The testers did not cause the bugs, but they must bear some of the guilt for the bugs that were disclosed.
Xamarin is an open-source framework that offers cross-platform application development using the C# programming language. It helps to simplify your overall development and management of cross-platform software applications.
When software developers took years to create and introduce new products to the market is long gone. Users (or consumers) today are more eager to use their favorite applications with the latest bells and whistles. However, users today don’t have the patience to work around bugs, errors, and design flaws. People have less self-control, and if your product or application doesn’t make life easier for users, they’ll leave for a better solution.
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!!