|
| 1 | +# Licensed to the Software Freedom Conservancy (SFC) under one |
| 2 | +# or more contributor license agreements. See the NOTICE file |
| 3 | +# distributed with this work for additional information |
| 4 | +# regarding copyright ownership. The SFC licenses this file |
| 5 | +# to you under the Apache License, Version 2.0 (the |
| 6 | +# "License"); you may not use this file except in compliance |
| 7 | +# with the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, |
| 12 | +# software distributed under the License is distributed on an |
| 13 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +# KIND, either express or implied. See the License for the |
| 15 | +# specific language governing permissions and limitations |
| 16 | +# under the License. |
| 17 | +import os |
| 18 | +import tempfile |
| 19 | + |
| 20 | +from selenium.webdriver.common.by import By |
| 21 | +from selenium.webdriver.support.wait import WebDriverWait |
| 22 | + |
| 23 | + |
| 24 | +def test_get_downloadable_files(driver, pages): |
| 25 | + pages.load("downloads/download.html") |
| 26 | + driver.find_element(By.ID, "file-1").click() |
| 27 | + driver.find_element(By.ID, "file-2").click() |
| 28 | + WebDriverWait(driver, 3).until(lambda d: len(d.get_downloadable_files()) == 2) |
| 29 | + |
| 30 | + file_names = driver.get_downloadable_files() |
| 31 | + |
| 32 | + assert "file_1.txt" in file_names |
| 33 | + assert "file_2.jpg" in file_names |
| 34 | + |
| 35 | + |
| 36 | +def test_download_file(driver, pages): |
| 37 | + pages.load("downloads/download.html") |
| 38 | + driver.find_element(By.ID, "file-1").click() |
| 39 | + WebDriverWait(driver, 3).until(lambda d: d.get_downloadable_files()) |
| 40 | + |
| 41 | + file_name = driver.get_downloadable_files()[0] |
| 42 | + with tempfile.TemporaryDirectory() as target_directory: |
| 43 | + driver.download_file(file_name, target_directory) |
| 44 | + |
| 45 | + target_file = os.path.join(target_directory, file_name) |
| 46 | + with open(target_file, "r") as file: |
| 47 | + assert "Hello, World!" in file.read() |
| 48 | + |
| 49 | + |
| 50 | +def test_delete_downloadable_files(driver, pages): |
| 51 | + pages.load("downloads/download.html") |
| 52 | + driver.find_element(By.ID, "file-1").click() |
| 53 | + WebDriverWait(driver, 3).until(lambda d: d.get_downloadable_files()) |
| 54 | + |
| 55 | + driver.delete_downloadable_files() |
| 56 | + assert not driver.get_downloadable_files() |
0 commit comments