Path: blob/trunk/py/test/selenium/webdriver/remote/remote_downloads_tests.py
1865 views
# Licensed to the Software Freedom Conservancy (SFC) under one1# or more contributor license agreements. See the NOTICE file2# distributed with this work for additional information3# regarding copyright ownership. The SFC licenses this file4# to you under the Apache License, Version 2.0 (the5# "License"); you may not use this file except in compliance6# with the License. You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing,11# software distributed under the License is distributed on an12# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13# KIND, either express or implied. See the License for the14# specific language governing permissions and limitations15# under the License.1617import os18import tempfile1920from selenium.webdriver.common.by import By21from selenium.webdriver.support.wait import WebDriverWait222324def test_get_downloadable_files(driver, pages):25_browser_downloads(driver, pages)2627file_names = driver.get_downloadable_files()2829assert "file_1.txt" in file_names30assert "file_2.jpg" in file_names31assert type(file_names) is list323334def test_download_file(driver, pages):35_browser_downloads(driver, pages)3637# Get a list of downloadable files and find the txt file38downloadable_files = driver.get_downloadable_files()39text_file_name = next((file for file in downloadable_files if file.endswith(".txt")), None)40assert text_file_name is not None, "Could not find a .txt file in downloadable files"4142with tempfile.TemporaryDirectory() as target_directory:43driver.download_file(text_file_name, target_directory)4445target_file = os.path.join(target_directory, text_file_name)46with open(target_file) as file:47assert "Hello, World!" in file.read()484950def test_delete_downloadable_files(driver, pages):51_browser_downloads(driver, pages)5253driver.delete_downloadable_files()54assert not driver.get_downloadable_files()555657def _browser_downloads(driver, pages):58pages.load("downloads/download.html")59driver.find_element(By.ID, "file-1").click()60driver.find_element(By.ID, "file-2").click()61WebDriverWait(driver, 3).until(lambda d: "file_2.jpg" in d.get_downloadable_files())626364