How to use get_path_of_downloaded_file method in SeleniumBase

Best Python code snippet using SeleniumBase

test_download_files.py

Source:test_download_files.py Github

copy

Full Screen

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

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 SeleniumBase 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