Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/java/src/org/openqa/selenium/HasDownloads.java
1865 views
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
18
package org.openqa.selenium;
19
20
import java.io.IOException;
21
import java.nio.file.Path;
22
import java.util.List;
23
24
/** Indicates that a driver supports downloading remote files. */
25
public interface HasDownloads {
26
27
/**
28
* Requires downloads to be enabled.
29
*
30
* <p>TODO: Create an example in the documentation and provide a link to it.
31
*
32
* @param capabilities the capabilities object
33
* @throws WebDriverException if capability to enable downloads is not set
34
*/
35
default void requireDownloadsEnabled(Capabilities capabilities) {
36
if (!isDownloadsEnabled(capabilities)) {
37
throw new WebDriverException(
38
"You must enable downloads in order to work with downloadable files.");
39
}
40
}
41
42
/**
43
* Checks if downloads are enabled
44
*
45
* @return true if this webdriver has capability "se:downloadsEnabled" = true
46
*/
47
boolean isDownloadsEnabled();
48
49
static boolean isDownloadsEnabled(Capabilities capabilities) {
50
return capabilities.is("se:downloadsEnabled");
51
}
52
53
/**
54
* Gets the downloadable files.
55
*
56
* @return a list of downloadable files for each key
57
*/
58
List<String> getDownloadableFiles();
59
60
/**
61
* Downloads a file to a given location.
62
*
63
* @param fileName the name of the file to be downloaded
64
* @param targetLocation the location where the file will be downloaded to
65
* @throws IOException if an I/O error occurs while downloading the file
66
*/
67
void downloadFile(String fileName, Path targetLocation) throws IOException;
68
69
/** Deletes the downloadable files. */
70
void deleteDownloadableFiles();
71
}
72
73