-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[py] implement file downloads (#13023)
* [py] download file do not return a string * [py] require enabling downloads
- Loading branch information
1 parent
96f13f8
commit 605fccd
Showing
6 changed files
with
139 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
py/test/selenium/webdriver/remote/remote_downloads_tests.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Licensed to the Software Freedom Conservancy (SFC) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The SFC licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
import os | ||
import tempfile | ||
|
||
from selenium.webdriver.common.by import By | ||
from selenium.webdriver.support.wait import WebDriverWait | ||
|
||
|
||
def test_get_downloadable_files(driver, pages): | ||
_browser_downloads(driver, pages) | ||
|
||
file_names = driver.get_downloadable_files() | ||
|
||
assert "file_1.txt" in file_names | ||
assert "file_2.jpg" in file_names | ||
|
||
|
||
def test_download_file(driver, pages): | ||
_browser_downloads(driver, pages) | ||
|
||
file_name = driver.get_downloadable_files()[0] | ||
with tempfile.TemporaryDirectory() as target_directory: | ||
driver.download_file(file_name, target_directory) | ||
|
||
target_file = os.path.join(target_directory, file_name) | ||
with open(target_file, "r") as file: | ||
assert "Hello, World!" in file.read() | ||
|
||
|
||
def test_delete_downloadable_files(driver, pages): | ||
_browser_downloads(driver, pages) | ||
|
||
driver.delete_downloadable_files() | ||
assert not driver.get_downloadable_files() | ||
|
||
|
||
def _browser_downloads(driver, pages): | ||
pages.load("downloads/download.html") | ||
driver.find_element(By.ID, "file-1").click() | ||
driver.find_element(By.ID, "file-2").click() | ||
WebDriverWait(driver, 3).until(lambda d: "file_2.jpg" in d.get_downloadable_files()) |