-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[grid] Support file downloads on the node #11277
[grid] Support file downloads on the node #11277
Conversation
fb02c4d
to
b2b6be9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @krmahadevan! I left some comments.
e2cc1b3
to
b7f975c
Compare
@diemol - I have fixed all the review comments, rebased off of |
b7f975c
to
42b1a22
Compare
80855c2
to
c3418ff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked out this PR to run a complete test but it did not work. Probably because the get method for downloadsPath
configuration is not being used.
The client code I used to perform a test was:
package org.example;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.io.Zip;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.http.HttpMethod;
import org.openqa.selenium.remote.http.HttpRequest;
import org.openqa.selenium.remote.http.HttpResponse;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import static org.openqa.selenium.remote.http.Contents.string;
public class Main {
public static void main(String[] args) throws InterruptedException, IOException {
FirefoxOptions options = new FirefoxOptions();
options.addPreference("browser.download.manager.showWhenStarting", false);
options.addPreference("browser.helperApps.neverAsk.saveToDisk", "images/jpeg, application/pdf, application/octet-stream");
options.addPreference("pdfjs.disabled", true);
URL gridUrl = new URL("http://localhost:4444");
RemoteWebDriver driver = new RemoteWebDriver(gridUrl, options);
driver.get("http://the-internet.herokuapp.com/download");
WebElement element = driver.findElement(By.cssSelector(".example a"));
element.click();
Thread.sleep(10 * 1000);
HttpRequest request = new HttpRequest(
HttpMethod.GET,
String.format("/session/%s/se/file", driver.getSessionId()));
request.addQueryParameter("filename", "my_appointments-1.pdf");
try (HttpClient client = HttpClient.Factory.createDefault().createClient(gridUrl)) {
HttpResponse response = client.execute(request);
Map<String, Object> map = new Json().toType(string(response), Json.MAP_TYPE);
String encodedContents = map.get("contents").toString();
Zip.unzip(encodedContents, new File("/Users/diegomolina/Downloads"));
}
driver.quit();
}
}
java/test/org/openqa/selenium/grid/distributor/AddingNodesTest.java
Outdated
Show resolved
Hide resolved
1919501
to
3fad03f
Compare
@diemol - Thanks for catching that bug! Fixed the review comments, rebased off of trunk and force pushed changes back to this branch. Please check |
Fixes: SeleniumHQ#9218 On the node, set the directory to where the browser will download files to via: a. The CLI argument `--downloads-dir` (or) b. via the Toml syntax of ``` [node] downloads-dir = "/path/to/dir/goes/here" ``` The GET end-points that will support file download would be: * `/session/:sessionId:/file?filename=` * `/session/:sessionId:/se/file?filename=`
* Renamed the CLI arg to downloads-path * Download is available only via GET /session/{sessionId}/se/file * Files downloaded would be available ONLY as a zip file.
3fad03f
to
6c0204a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @krmahadevan!
@krmahadevan would be great if you can help us with the docs for this new feature 💪 |
SonarCloud Quality Gate failed. |
@diemol - I have raised a PR for this PR: SeleniumHQ/seleniumhq.github.io#1262 Doc links:
|
Downloaded 4.8.0 and verified this feature. Working well👍🏼. Will the API also include an endpoint to clean up the downloaded files? |
imo it shouldn't have its own endpoint, it should be part of the cleanup process of ending the session. Once the session is finished, the files can't be accessed again. |
Thank you @titusfortner and agree re session clean up. Have tried verifying this behaviour with a local Grid
|
I see, thank you for the extra info. Will keep a watch in this further development. |
That's about right. We'll see what trouble we run into (if any) in the implementation. |
@krmahadevan Can I use the preference settings for this download path inside the code (download.default_directory) instead of passing the download path while setting-up node? Because we are using docker container provisioned by aws ECS? Thanks |
@vijaysp77 This feature is going through a revamp. The functionality will change once my PR #11702 gets merged. So I would suggest that you follow the above PR and wait for this functionality to get streamlined. |
@krmahadevan I saw your PR 1702 has been merged. |
@patilsha it was merged yesterday, it will be part of the next release. |
I'm assuming this is not yet available in Selenium docker images (4.8.1)? Chrome node
Firefox node
I also tried running this using PHP driver: $file = $driver->executeCustomCommand('/session/:sessionId/se/file?filename=100MB.bin'); Result:
I'm in dark. This feature is documented, yet cannot be used. Am I doing something wrong? I defined Version: Selenium 4.8.1 (revision 8ebccac) |
@xZero707 - For this to be available in the docker selenium project, I think this should be released first. The feature has gone through some revamp. So please create an issue on the docker-selenium project that tracks this requirement and you can also cross link this issue there. |
@krmahadevan Thank you for clarification. It makes sense. I will do as you suggested. |
@diemol Can you pls help me here, I'm trying to test File Downloads on Jenkins Node but |
@naveenmadd - If you wanted to build/experiment something on top of this changes, I would suggest that you do it from |
Even I verified selenium-trunk repository, I see the same implementation [ package org.openqa.selenium.grid.node > class NodeTest > @test @DisplayName("DownloadsTestCase") Map<String, Object> map = new Json().toType(string(response), Json.MAP_TYPE);] Thanks @krmahadevan @diemol |
Fixes: #9218
On the node, set the directory to where the browser will download files to via:
a. The CLI argument
--downloads-path
(or)b. via the Toml syntax of
The GET end-points that will support file
download would be (The file will ALWAYS BE DOWNLOADED AS A ZIP FILE):
/session/:sessionId:/se/file?filename=
Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.
Description
Motivation and Context
Types of changes
Checklist