Skip to content

Commit 6b9f76b

Browse files
committed
Tweaking new docs for file downloads
[deploy site]
1 parent fd8a67f commit 6b9f76b

File tree

8 files changed

+147
-76
lines changed

8 files changed

+147
-76
lines changed

website_and_docs/content/documentation/grid/configuration/cli_options.en.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,8 @@ Set the custom capability to `false` in order to match the Node B.
353353

354354
#### Specifying path from where downloaded files can be retrieved
355355

356-
At times a test may need to access files that were downloaded by it on the Node. To retrieve such files, following can be done.
356+
At times a test may need to access files that were downloaded by it on the Node. To retrieve
357+
such files, following can be done.
357358

358359
##### Start the Hub
359360
```
@@ -364,9 +365,26 @@ java -jar selenium-server-<version>.jar hub
364365
```
365366
java -jar selenium-server-<version>.jar node --downloads-path /usr/downloads
366367
```
368+
##### Important information when dowloading a file:
369+
370+
* The endpoint to `GET` from is `/session/<sessionId>/se/file?filename=`
371+
* The session needs to be active in order for the command to work.
372+
* The response blob contains two keys,
373+
* `filename` - Same as what was specified in the request.
374+
* `contents` - Base64 encoded zipped contents of the file.
375+
* The file contents are Base64 encoded and they need to be unzipped.
367376

368377
##### Sample that retrieves the downloaded file
369378

379+
Assuming the downloaded file is named `my_file.pdf`, and using `curl`, the
380+
file could be downloaded with the following command:
381+
382+
```bash
383+
curl -X GET "http://localhost:4444/session/<sessionId>/se/file?filename=my_file.pdf"
384+
```
385+
386+
Below is an example in Java that shows how to download a file named `my_file.pdf`.
387+
370388
```java
371389
import static org.openqa.selenium.remote.http.Contents.string;
372390

@@ -389,26 +407,31 @@ import org.openqa.selenium.remote.http.HttpResponse;
389407
public class DownloadsSample {
390408

391409
public static void main(String[] args) throws InterruptedException, IOException {
392-
File dirToCopyTo = new File("/usr/downloads");
410+
// Make sure the following directory exists on your machine
411+
File dirToCopyTo = new File("/usr/downloads/file");
412+
// Assuming the Grid is running locally.
393413
URL gridUrl = new URL("http://localhost:4444");
394414
RemoteWebDriver driver = new RemoteWebDriver(gridUrl, firefoxOptions());
415+
// This public website resets the available files for dowload on a daily basis,
416+
// check the name of the file that will be downloaded and replace it below.
395417
driver.get("http://the-internet.herokuapp.com/download");
396418
WebElement element = driver.findElement(By.cssSelector(".example a"));
397419
element.click();
398420

421+
// The download happens in a remote Node, which makes difficult to know when the file
422+
// has been completely downloaded. For demonstration purposes, this example uses a
423+
// 10 second sleep which should be enough time for a file to be downloaded.
424+
// We strongly recommend to avoid hardcoded sleeps, and ideally, to modify your
425+
// application under test so it offers a way to know when the file has been completely
426+
// downloaded.
399427
TimeUnit.SECONDS.sleep(10);
400428

401-
// The file can be downloaded by accessing
402-
// curl -X GET "http://localhost:4444/session/<sessionId>/se/file?filename=my_file.pdf"
403-
404-
HttpRequest request = new HttpRequest(
405-
HttpMethod.GET,
406-
String.format("/session/%s/se/file", driver.getSessionId()));
407-
request.addQueryParameter("filename", "my_appointments-1.pdf");
429+
HttpRequest request = new HttpRequest(HttpMethod.GET, String.format("/session/%s/se/file", driver.getSessionId()));
430+
request.addQueryParameter("filename", "my_file.pdf");
408431
try (HttpClient client = HttpClient.Factory.createDefault().createClient(gridUrl)) {
409432
HttpResponse response = client.execute(request);
410433
Map<String, Object> map = new Json().toType(string(response), Json.MAP_TYPE);
411-
// The returned map would contain 2 keys viz.,
434+
// The returned map would contain 2 keys,
412435
// filename - This represents the name of the file (same as what was provided by the test)
413436
// contents - Base64 encoded String which contains the zipped file.
414437
String encodedContents = map.get("contents").toString();
@@ -422,6 +445,8 @@ public class DownloadsSample {
422445

423446
private static FirefoxOptions firefoxOptions() {
424447
FirefoxOptions options = new FirefoxOptions();
448+
// Options specific for Firefox to avoid prompting a dialog for downloads. They might
449+
// change in the future, so please refer to the Firefox documentation for up to date details.
425450
options.addPreference("browser.download.manager.showWhenStarting", false);
426451
options.addPreference("browser.helperApps.neverAsk.saveToDisk",
427452
"images/jpeg, application/pdf, application/octet-stream");
@@ -431,11 +456,3 @@ public class DownloadsSample {
431456
}
432457
```
433458

434-
##### Points to remember:
435-
436-
* The endpoint to `GET` from is `/session/<sessionId>/se/file?filename=`
437-
* The response contains two keys viz.,
438-
* `filename` - Same as what was specified in the request.
439-
* `contents` - Base64 encoded zipped contents of the file.
440-
* The file contents are Base64 encoded.
441-
* The contents need to be unzipped.

website_and_docs/content/documentation/grid/configuration/cli_options.ja.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ driver.quit();
354354

355355
#### Specifying path from where downloaded files can be retrieved
356356

357-
At times a test may need to access files that were downloaded by it on the Node. To retrieve such files, following can be done.
357+
At times a test may need to access files that were downloaded by it on the Node. To retrieve
358+
such files, following can be done.
358359

359360
##### Start the Hub
360361
```
@@ -365,9 +366,26 @@ java -jar selenium-server-<version>.jar hub
365366
```
366367
java -jar selenium-server-<version>.jar node --downloads-path /usr/downloads
367368
```
369+
##### Important information when dowloading a file:
370+
371+
* The endpoint to `GET` from is `/session/<sessionId>/se/file?filename=`
372+
* The session needs to be active in order for the command to work.
373+
* The response blob contains two keys,
374+
* `filename` - Same as what was specified in the request.
375+
* `contents` - Base64 encoded zipped contents of the file.
376+
* The file contents are Base64 encoded and they need to be unzipped.
368377

369378
##### Sample that retrieves the downloaded file
370379

380+
Assuming the downloaded file is named `my_file.pdf`, and using `curl`, the
381+
file could be downloaded with the following command:
382+
383+
```bash
384+
curl -X GET "http://localhost:4444/session/<sessionId>/se/file?filename=my_file.pdf"
385+
```
386+
387+
Below is an example in Java that shows how to download a file named `my_file.pdf`.
388+
371389
```java
372390
import static org.openqa.selenium.remote.http.Contents.string;
373391

@@ -390,26 +408,31 @@ import org.openqa.selenium.remote.http.HttpResponse;
390408
public class DownloadsSample {
391409

392410
public static void main(String[] args) throws InterruptedException, IOException {
393-
File dirToCopyTo = new File("/usr/downloads");
411+
// Make sure the following directory exists on your machine
412+
File dirToCopyTo = new File("/usr/downloads/file");
413+
// Assuming the Grid is running locally.
394414
URL gridUrl = new URL("http://localhost:4444");
395415
RemoteWebDriver driver = new RemoteWebDriver(gridUrl, firefoxOptions());
416+
// This public website resets the available files for dowload on a daily basis,
417+
// check the name of the file that will be downloaded and replace it below.
396418
driver.get("http://the-internet.herokuapp.com/download");
397419
WebElement element = driver.findElement(By.cssSelector(".example a"));
398420
element.click();
399421

422+
// The download happens in a remote Node, which makes difficult to know when the file
423+
// has been completely downloaded. For demonstration purposes, this example uses a
424+
// 10 second sleep which should be enough time for a file to be downloaded.
425+
// We strongly recommend to avoid hardcoded sleeps, and ideally, to modify your
426+
// application under test so it offers a way to know when the file has been completely
427+
// downloaded.
400428
TimeUnit.SECONDS.sleep(10);
401429

402-
// The file can be downloaded by accessing
403-
// curl -X GET "http://localhost:4444/session/<sessionId>/se/file?filename=my_file.pdf"
404-
405-
HttpRequest request = new HttpRequest(
406-
HttpMethod.GET,
407-
String.format("/session/%s/se/file", driver.getSessionId()));
408-
request.addQueryParameter("filename", "my_appointments-1.pdf");
430+
HttpRequest request = new HttpRequest(HttpMethod.GET, String.format("/session/%s/se/file", driver.getSessionId()));
431+
request.addQueryParameter("filename", "my_file.pdf");
409432
try (HttpClient client = HttpClient.Factory.createDefault().createClient(gridUrl)) {
410433
HttpResponse response = client.execute(request);
411434
Map<String, Object> map = new Json().toType(string(response), Json.MAP_TYPE);
412-
// The returned map would contain 2 keys viz.,
435+
// The returned map would contain 2 keys,
413436
// filename - This represents the name of the file (same as what was provided by the test)
414437
// contents - Base64 encoded String which contains the zipped file.
415438
String encodedContents = map.get("contents").toString();
@@ -423,6 +446,8 @@ public class DownloadsSample {
423446

424447
private static FirefoxOptions firefoxOptions() {
425448
FirefoxOptions options = new FirefoxOptions();
449+
// Options specific for Firefox to avoid prompting a dialog for downloads. They might
450+
// change in the future, so please refer to the Firefox documentation for up to date details.
426451
options.addPreference("browser.download.manager.showWhenStarting", false);
427452
options.addPreference("browser.helperApps.neverAsk.saveToDisk",
428453
"images/jpeg, application/pdf, application/octet-stream");
@@ -432,11 +457,3 @@ public class DownloadsSample {
432457
}
433458
```
434459

435-
##### Points to remember:
436-
437-
* The endpoint to `GET` from is `/session/<sessionId>/se/file?filename=`
438-
* The response contains two keys viz.,
439-
* `filename` - Same as what was specified in the request.
440-
* `contents` - Base64 encoded zipped contents of the file.
441-
* The file contents are Base64 encoded.
442-
* The contents need to be unzipped.

website_and_docs/content/documentation/grid/configuration/cli_options.pt-br.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ Set the custom capability to `false` in order to match the Node B.
357357

358358
#### Specifying path from where downloaded files can be retrieved
359359

360-
At times a test may need to access files that were downloaded by it on the Node. To retrieve such files, following can be done.
360+
At times a test may need to access files that were downloaded by it on the Node. To retrieve
361+
such files, following can be done.
361362

362363
##### Start the Hub
363364
```
@@ -368,9 +369,26 @@ java -jar selenium-server-<version>.jar hub
368369
```
369370
java -jar selenium-server-<version>.jar node --downloads-path /usr/downloads
370371
```
372+
##### Important information when dowloading a file:
373+
374+
* The endpoint to `GET` from is `/session/<sessionId>/se/file?filename=`
375+
* The session needs to be active in order for the command to work.
376+
* The response blob contains two keys,
377+
* `filename` - Same as what was specified in the request.
378+
* `contents` - Base64 encoded zipped contents of the file.
379+
* The file contents are Base64 encoded and they need to be unzipped.
371380

372381
##### Sample that retrieves the downloaded file
373382

383+
Assuming the downloaded file is named `my_file.pdf`, and using `curl`, the
384+
file could be downloaded with the following command:
385+
386+
```bash
387+
curl -X GET "http://localhost:4444/session/<sessionId>/se/file?filename=my_file.pdf"
388+
```
389+
390+
Below is an example in Java that shows how to download a file named `my_file.pdf`.
391+
374392
```java
375393
import static org.openqa.selenium.remote.http.Contents.string;
376394

@@ -393,26 +411,31 @@ import org.openqa.selenium.remote.http.HttpResponse;
393411
public class DownloadsSample {
394412

395413
public static void main(String[] args) throws InterruptedException, IOException {
396-
File dirToCopyTo = new File("/usr/downloads");
414+
// Make sure the following directory exists on your machine
415+
File dirToCopyTo = new File("/usr/downloads/file");
416+
// Assuming the Grid is running locally.
397417
URL gridUrl = new URL("http://localhost:4444");
398418
RemoteWebDriver driver = new RemoteWebDriver(gridUrl, firefoxOptions());
419+
// This public website resets the available files for dowload on a daily basis,
420+
// check the name of the file that will be downloaded and replace it below.
399421
driver.get("http://the-internet.herokuapp.com/download");
400422
WebElement element = driver.findElement(By.cssSelector(".example a"));
401423
element.click();
402424

425+
// The download happens in a remote Node, which makes difficult to know when the file
426+
// has been completely downloaded. For demonstration purposes, this example uses a
427+
// 10 second sleep which should be enough time for a file to be downloaded.
428+
// We strongly recommend to avoid hardcoded sleeps, and ideally, to modify your
429+
// application under test so it offers a way to know when the file has been completely
430+
// downloaded.
403431
TimeUnit.SECONDS.sleep(10);
404432

405-
// The file can be downloaded by accessing
406-
// curl -X GET "http://localhost:4444/session/<sessionId>/se/file?filename=my_file.pdf"
407-
408-
HttpRequest request = new HttpRequest(
409-
HttpMethod.GET,
410-
String.format("/session/%s/se/file", driver.getSessionId()));
411-
request.addQueryParameter("filename", "my_appointments-1.pdf");
433+
HttpRequest request = new HttpRequest(HttpMethod.GET, String.format("/session/%s/se/file", driver.getSessionId()));
434+
request.addQueryParameter("filename", "my_file.pdf");
412435
try (HttpClient client = HttpClient.Factory.createDefault().createClient(gridUrl)) {
413436
HttpResponse response = client.execute(request);
414437
Map<String, Object> map = new Json().toType(string(response), Json.MAP_TYPE);
415-
// The returned map would contain 2 keys viz.,
438+
// The returned map would contain 2 keys,
416439
// filename - This represents the name of the file (same as what was provided by the test)
417440
// contents - Base64 encoded String which contains the zipped file.
418441
String encodedContents = map.get("contents").toString();
@@ -426,6 +449,8 @@ public class DownloadsSample {
426449

427450
private static FirefoxOptions firefoxOptions() {
428451
FirefoxOptions options = new FirefoxOptions();
452+
// Options specific for Firefox to avoid prompting a dialog for downloads. They might
453+
// change in the future, so please refer to the Firefox documentation for up to date details.
429454
options.addPreference("browser.download.manager.showWhenStarting", false);
430455
options.addPreference("browser.helperApps.neverAsk.saveToDisk",
431456
"images/jpeg, application/pdf, application/octet-stream");
@@ -435,11 +460,3 @@ public class DownloadsSample {
435460
}
436461
```
437462

438-
##### Points to remember:
439-
440-
* The endpoint to `GET` from is `/session/<sessionId>/se/file?filename=`
441-
* The response contains two keys viz.,
442-
* `filename` - Same as what was specified in the request.
443-
* `contents` - Base64 encoded zipped contents of the file.
444-
* The file contents are Base64 encoded.
445-
* The contents need to be unzipped.

website_and_docs/content/documentation/grid/configuration/cli_options.zh-cn.md

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ Set the custom capability to `false` in order to match the Node B.
362362

363363
#### Specifying path from where downloaded files can be retrieved
364364

365-
At times a test may need to access files that were downloaded by it on the Node. To retrieve such files, following can be done.
365+
At times a test may need to access files that were downloaded by it on the Node. To retrieve
366+
such files, following can be done.
366367

367368
##### Start the Hub
368369
```
@@ -373,9 +374,26 @@ java -jar selenium-server-<version>.jar hub
373374
```
374375
java -jar selenium-server-<version>.jar node --downloads-path /usr/downloads
375376
```
377+
##### Important information when dowloading a file:
378+
379+
* The endpoint to `GET` from is `/session/<sessionId>/se/file?filename=`
380+
* The session needs to be active in order for the command to work.
381+
* The response blob contains two keys,
382+
* `filename` - Same as what was specified in the request.
383+
* `contents` - Base64 encoded zipped contents of the file.
384+
* The file contents are Base64 encoded and they need to be unzipped.
376385

377386
##### Sample that retrieves the downloaded file
378387

388+
Assuming the downloaded file is named `my_file.pdf`, and using `curl`, the
389+
file could be downloaded with the following command:
390+
391+
```bash
392+
curl -X GET "http://localhost:4444/session/<sessionId>/se/file?filename=my_file.pdf"
393+
```
394+
395+
Below is an example in Java that shows how to download a file named `my_file.pdf`.
396+
379397
```java
380398
import static org.openqa.selenium.remote.http.Contents.string;
381399

@@ -398,26 +416,31 @@ import org.openqa.selenium.remote.http.HttpResponse;
398416
public class DownloadsSample {
399417

400418
public static void main(String[] args) throws InterruptedException, IOException {
401-
File dirToCopyTo = new File("/usr/downloads");
419+
// Make sure the following directory exists on your machine
420+
File dirToCopyTo = new File("/usr/downloads/file");
421+
// Assuming the Grid is running locally.
402422
URL gridUrl = new URL("http://localhost:4444");
403423
RemoteWebDriver driver = new RemoteWebDriver(gridUrl, firefoxOptions());
424+
// This public website resets the available files for dowload on a daily basis,
425+
// check the name of the file that will be downloaded and replace it below.
404426
driver.get("http://the-internet.herokuapp.com/download");
405427
WebElement element = driver.findElement(By.cssSelector(".example a"));
406428
element.click();
407429

430+
// The download happens in a remote Node, which makes difficult to know when the file
431+
// has been completely downloaded. For demonstration purposes, this example uses a
432+
// 10 second sleep which should be enough time for a file to be downloaded.
433+
// We strongly recommend to avoid hardcoded sleeps, and ideally, to modify your
434+
// application under test so it offers a way to know when the file has been completely
435+
// downloaded.
408436
TimeUnit.SECONDS.sleep(10);
409437

410-
// The file can be downloaded by accessing
411-
// curl -X GET "http://localhost:4444/session/<sessionId>/se/file?filename=my_file.pdf"
412-
413-
HttpRequest request = new HttpRequest(
414-
HttpMethod.GET,
415-
String.format("/session/%s/se/file", driver.getSessionId()));
416-
request.addQueryParameter("filename", "my_appointments-1.pdf");
438+
HttpRequest request = new HttpRequest(HttpMethod.GET, String.format("/session/%s/se/file", driver.getSessionId()));
439+
request.addQueryParameter("filename", "my_file.pdf");
417440
try (HttpClient client = HttpClient.Factory.createDefault().createClient(gridUrl)) {
418441
HttpResponse response = client.execute(request);
419442
Map<String, Object> map = new Json().toType(string(response), Json.MAP_TYPE);
420-
// The returned map would contain 2 keys viz.,
443+
// The returned map would contain 2 keys,
421444
// filename - This represents the name of the file (same as what was provided by the test)
422445
// contents - Base64 encoded String which contains the zipped file.
423446
String encodedContents = map.get("contents").toString();
@@ -431,6 +454,8 @@ public class DownloadsSample {
431454

432455
private static FirefoxOptions firefoxOptions() {
433456
FirefoxOptions options = new FirefoxOptions();
457+
// Options specific for Firefox to avoid prompting a dialog for downloads. They might
458+
// change in the future, so please refer to the Firefox documentation for up to date details.
434459
options.addPreference("browser.download.manager.showWhenStarting", false);
435460
options.addPreference("browser.helperApps.neverAsk.saveToDisk",
436461
"images/jpeg, application/pdf, application/octet-stream");
@@ -440,11 +465,3 @@ public class DownloadsSample {
440465
}
441466
```
442467

443-
##### Points to remember:
444-
445-
* The endpoint to `GET` from is `/session/<sessionId>/se/file?filename=`
446-
* The response contains two keys viz.,
447-
* `filename` - Same as what was specified in the request.
448-
* `contents` - Base64 encoded zipped contents of the file.
449-
* The file contents are Base64 encoded.
450-
* The contents need to be unzipped.

0 commit comments

Comments
 (0)