diff --git a/website_and_docs/content/documentation/grid/configuration/cli_options.en.md b/website_and_docs/content/documentation/grid/configuration/cli_options.en.md index 3347239ee20a..3e702590939f 100644 --- a/website_and_docs/content/documentation/grid/configuration/cli_options.en.md +++ b/website_and_docs/content/documentation/grid/configuration/cli_options.en.md @@ -224,6 +224,7 @@ pull request updating this page. | `--drain-after-session-count`| int | `1` | Drain and shutdown the Node after X sessions have been executed. Useful for environments like Kubernetes. A value higher than zero enables this feature. | | `--hub`| string | `http://localhost:4444` | The address of the Hub in a Hub-and-Node configuration. Can be a hostname or IP address (`hostname`), in which case the Hub will be assumed to be `http://hostname:4444`, the `--grid-url` will be the same `--publish-events` will be `tcp://hostname:4442` and `--subscribe-events` will be `tcp://hostname:4443`. If `hostname` contains a port number, that will be used for `--grid-url` but the URIs for the event bus will remain the same. Any of these default values may be overridden but setting the correct flags. If the hostname has a protocol (such as `https`) that will be used too. | | `--enable-cdp`| boolean | `true` | Enable CDP proxying in Grid. A Grid admin can disable CDP if the network doesnot allow websockets. True by default. | +| `--downloads-path`| string | `/usr/downloads` | The default location wherein all browser triggered file downloads would be available to be retrieved from. This is usually the directory that you configure in your browser as the default location for storing downloaded files. | ### Relay @@ -349,3 +350,92 @@ driver.quit(); ``` Set the custom capability to `false` in order to match the Node B. + +#### Specifying path from where downloaded files can be retrieved + +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. + +##### Start the Hub +``` +java -jar selenium-server-.jar hub +``` + +##### Start the Node with downloads path specified +``` +java -jar selenium-server-.jar node --downloads-path /usr/downloads +``` + +##### Sample that retrieves the downloaded file + +```java +import static org.openqa.selenium.remote.http.Contents.string; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import org.openqa.selenium.By; +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; + +public class DownloadsSample { + + public static void main(String[] args) throws InterruptedException, IOException { + File dirToCopyTo = new File("/usr/downloads"); + URL gridUrl = new URL("http://localhost:4444"); + RemoteWebDriver driver = new RemoteWebDriver(gridUrl, firefoxOptions()); + driver.get("http://the-internet.herokuapp.com/download"); + WebElement element = driver.findElement(By.cssSelector(".example a")); + element.click(); + + TimeUnit.SECONDS.sleep(10); + + // The file can be downloaded by accessing + // curl -X GET "http://localhost:4444/session//se/file?filename=my_file.pdf" + + 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 map = new Json().toType(string(response), Json.MAP_TYPE); + // The returned map would contain 2 keys viz., + // filename - This represents the name of the file (same as what was provided by the test) + // contents - Base64 encoded String which contains the zipped file. + String encodedContents = map.get("contents").toString(); + + //The file contents would always be a zip file and has to be unzipped. + Zip.unzip(encodedContents, dirToCopyTo); + } finally { + driver.quit(); + } + } + + private static FirefoxOptions firefoxOptions() { + 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); + return options; + } +} +``` + +##### Points to remember: + +* The endpoint to `GET` from is `/session//se/file?filename=` +* The response contains two keys viz., + * `filename` - Same as what was specified in the request. + * `contents` - Base64 encoded zipped contents of the file. +* The file contents are Base64 encoded. +* The contents need to be unzipped. \ No newline at end of file diff --git a/website_and_docs/content/documentation/grid/configuration/cli_options.ja.md b/website_and_docs/content/documentation/grid/configuration/cli_options.ja.md index aace4b0aca2f..1442910cd25d 100644 --- a/website_and_docs/content/documentation/grid/configuration/cli_options.ja.md +++ b/website_and_docs/content/documentation/grid/configuration/cli_options.ja.md @@ -223,6 +223,7 @@ Grid の設定には、さまざまなセクションが用意されています | `--drain-after-session-count` | int | `1` | X 個のセッションが実行された後に、ノードをドレインしてシャットダウンします。 Kubernetes のような環境で有用です。 0 より大きい値を指定すると、この機能が有効になります。 | | `--hub` | string | `http://localhost:4444` | ハブ・ノード構成におけるハブのアドレスを指定します。ホスト名か IP アドレスが指定できます。この場合、ハブは `http://hostname:4444` とみなされ、 `--grid-url` は同じものになります。 `--publish-events` は `tcp://hostname:4442` 、`--subscribe-events` は `tcp://hostname:4443` となります。 `hostname` にポート番号が含まれている場合は、それが `--grid-url` に使用されますが、イベントバスの URI は変更されません。これらのデフォルト値は、適切なフラグを設定することでオーバーライドすることができます。ホスト名にプロトコル(`https`のような)が含まれる場合もそれが利用されます。 | | `--enable-cdp` | boolean | `true` | Grid 内で CDP プロキシーを有効にします。もしネットワークが web socket を許可していない場合、Grid 管理者は CDP を無効にできます。デフォルトは true です。 | +| `--downloads-path`| string | `/usr/downloads` | The default location wherein all browser triggered file downloads would be available to be retrieved from. This is usually the directory that you configure in your browser as the default location for storing downloaded files. | ### Relay @@ -349,3 +350,93 @@ driver.quit(); ``` ノード B とマッチさせるにはカスタム capability を `false` に設定します。 + + +#### Specifying path from where downloaded files can be retrieved + +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. + +##### Start the Hub +``` +java -jar selenium-server-.jar hub +``` + +##### Start the Node with downloads path specified +``` +java -jar selenium-server-.jar node --downloads-path /usr/downloads +``` + +##### Sample that retrieves the downloaded file + +```java +import static org.openqa.selenium.remote.http.Contents.string; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import org.openqa.selenium.By; +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; + +public class DownloadsSample { + + public static void main(String[] args) throws InterruptedException, IOException { + File dirToCopyTo = new File("/usr/downloads"); + URL gridUrl = new URL("http://localhost:4444"); + RemoteWebDriver driver = new RemoteWebDriver(gridUrl, firefoxOptions()); + driver.get("http://the-internet.herokuapp.com/download"); + WebElement element = driver.findElement(By.cssSelector(".example a")); + element.click(); + + TimeUnit.SECONDS.sleep(10); + + // The file can be downloaded by accessing + // curl -X GET "http://localhost:4444/session//se/file?filename=my_file.pdf" + + 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 map = new Json().toType(string(response), Json.MAP_TYPE); + // The returned map would contain 2 keys viz., + // filename - This represents the name of the file (same as what was provided by the test) + // contents - Base64 encoded String which contains the zipped file. + String encodedContents = map.get("contents").toString(); + + //The file contents would always be a zip file and has to be unzipped. + Zip.unzip(encodedContents, dirToCopyTo); + } finally { + driver.quit(); + } + } + + private static FirefoxOptions firefoxOptions() { + 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); + return options; + } +} +``` + +##### Points to remember: + +* The endpoint to `GET` from is `/session//se/file?filename=` +* The response contains two keys viz., + * `filename` - Same as what was specified in the request. + * `contents` - Base64 encoded zipped contents of the file. +* The file contents are Base64 encoded. +* The contents need to be unzipped. \ No newline at end of file diff --git a/website_and_docs/content/documentation/grid/configuration/cli_options.pt-br.md b/website_and_docs/content/documentation/grid/configuration/cli_options.pt-br.md index 1bb6cb1bf2d7..656794b6d8d9 100644 --- a/website_and_docs/content/documentation/grid/configuration/cli_options.pt-br.md +++ b/website_and_docs/content/documentation/grid/configuration/cli_options.pt-br.md @@ -226,6 +226,8 @@ e esteja à vontade para nos enviar um pull request com alterações a esta pág | `--drain-after-session-count`| int | `1` | Drain and shutdown the Node after X sessions have been executed. Useful for environments like Kubernetes. A value higher than zero enables this feature. | | `--hub`| string | `http://localhost:4444` | The address of the Hub in a Hub-and-Node configuration. Can be a hostname or IP address (`hostname`), in which case the Hub will be assumed to be `http://hostname:4444`, the `--grid-url` will be the same `--publish-events` will be `tcp://hostname:4442` and `--subscribe-events` will be `tcp://hostname:4443`. If `hostname` contains a port number, that will be used for `--grid-url` but the URIs for the event bus will remain the same. Any of these default values may be overridden but setting the correct flags. If the hostname has a protocol (such as `https`) that will be used too. | | `--enable-cdp`| boolean | `true` | Enable CDP proxying in Grid. A Grid admin can disable CDP if the network doesnot allow websockets. True by default. | +| `--downloads-path`| string | `/usr/downloads` | The default location wherein all browser triggered file downloads would be available to be retrieved from. This is usually the directory that you configure in your browser as the default location for storing downloaded files. | + ### Relay @@ -351,3 +353,93 @@ driver.quit(); ``` Set the custom capability to `false` in order to match the Node B. + + +#### Specifying path from where downloaded files can be retrieved + +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. + +##### Start the Hub +``` +java -jar selenium-server-.jar hub +``` + +##### Start the Node with downloads path specified +``` +java -jar selenium-server-.jar node --downloads-path /usr/downloads +``` + +##### Sample that retrieves the downloaded file + +```java +import static org.openqa.selenium.remote.http.Contents.string; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import org.openqa.selenium.By; +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; + +public class DownloadsSample { + + public static void main(String[] args) throws InterruptedException, IOException { + File dirToCopyTo = new File("/usr/downloads"); + URL gridUrl = new URL("http://localhost:4444"); + RemoteWebDriver driver = new RemoteWebDriver(gridUrl, firefoxOptions()); + driver.get("http://the-internet.herokuapp.com/download"); + WebElement element = driver.findElement(By.cssSelector(".example a")); + element.click(); + + TimeUnit.SECONDS.sleep(10); + + // The file can be downloaded by accessing + // curl -X GET "http://localhost:4444/session//se/file?filename=my_file.pdf" + + 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 map = new Json().toType(string(response), Json.MAP_TYPE); + // The returned map would contain 2 keys viz., + // filename - This represents the name of the file (same as what was provided by the test) + // contents - Base64 encoded String which contains the zipped file. + String encodedContents = map.get("contents").toString(); + + //The file contents would always be a zip file and has to be unzipped. + Zip.unzip(encodedContents, dirToCopyTo); + } finally { + driver.quit(); + } + } + + private static FirefoxOptions firefoxOptions() { + 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); + return options; + } +} +``` + +##### Points to remember: + +* The endpoint to `GET` from is `/session//se/file?filename=` +* The response contains two keys viz., + * `filename` - Same as what was specified in the request. + * `contents` - Base64 encoded zipped contents of the file. +* The file contents are Base64 encoded. +* The contents need to be unzipped. diff --git a/website_and_docs/content/documentation/grid/configuration/cli_options.zh-cn.md b/website_and_docs/content/documentation/grid/configuration/cli_options.zh-cn.md index f103516e9948..e3a1ccd44d85 100644 --- a/website_and_docs/content/documentation/grid/configuration/cli_options.zh-cn.md +++ b/website_and_docs/content/documentation/grid/configuration/cli_options.zh-cn.md @@ -233,6 +233,7 @@ pull request updating this page. | `--drain-after-session-count`| int | `1` | Drain and shutdown the Node after X sessions have been executed. Useful for environments like Kubernetes. A value higher than zero enables this feature. | | `--hub`| string | `http://localhost:4444` | The address of the Hub in a Hub-and-Node configuration. Can be a hostname or IP address (`hostname`), in which case the Hub will be assumed to be `http://hostname:4444`, the `--grid-url` will be the same `--publish-events` will be `tcp://hostname:4442` and `--subscribe-events` will be `tcp://hostname:4443`. If `hostname` contains a port number, that will be used for `--grid-url` but the URIs for the event bus will remain the same. Any of these default values may be overridden but setting the correct flags. If the hostname has a protocol (such as `https`) that will be used too. | | `--enable-cdp`| boolean | `true` | Enable CDP proxying in Grid. A Grid admin can disable CDP if the network doesnot allow websockets. True by default. | +| `--downloads-path`| string | `/usr/downloads` | The default location wherein all browser triggered file downloads would be available to be retrieved from. This is usually the directory that you configure in your browser as the default location for storing downloaded files. | ### Relay @@ -358,3 +359,92 @@ driver.quit(); ``` Set the custom capability to `false` in order to match the Node B. + +#### Specifying path from where downloaded files can be retrieved + +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. + +##### Start the Hub +``` +java -jar selenium-server-.jar hub +``` + +##### Start the Node with downloads path specified +``` +java -jar selenium-server-.jar node --downloads-path /usr/downloads +``` + +##### Sample that retrieves the downloaded file + +```java +import static org.openqa.selenium.remote.http.Contents.string; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import org.openqa.selenium.By; +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; + +public class DownloadsSample { + + public static void main(String[] args) throws InterruptedException, IOException { + File dirToCopyTo = new File("/usr/downloads"); + URL gridUrl = new URL("http://localhost:4444"); + RemoteWebDriver driver = new RemoteWebDriver(gridUrl, firefoxOptions()); + driver.get("http://the-internet.herokuapp.com/download"); + WebElement element = driver.findElement(By.cssSelector(".example a")); + element.click(); + + TimeUnit.SECONDS.sleep(10); + + // The file can be downloaded by accessing + // curl -X GET "http://localhost:4444/session//se/file?filename=my_file.pdf" + + 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 map = new Json().toType(string(response), Json.MAP_TYPE); + // The returned map would contain 2 keys viz., + // filename - This represents the name of the file (same as what was provided by the test) + // contents - Base64 encoded String which contains the zipped file. + String encodedContents = map.get("contents").toString(); + + //The file contents would always be a zip file and has to be unzipped. + Zip.unzip(encodedContents, dirToCopyTo); + } finally { + driver.quit(); + } + } + + private static FirefoxOptions firefoxOptions() { + 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); + return options; + } +} +``` + +##### Points to remember: + +* The endpoint to `GET` from is `/session//se/file?filename=` +* The response contains two keys viz., + * `filename` - Same as what was specified in the request. + * `contents` - Base64 encoded zipped contents of the file. +* The file contents are Base64 encoded. +* The contents need to be unzipped. diff --git a/website_and_docs/content/documentation/grid/configuration/toml_options.en.md b/website_and_docs/content/documentation/grid/configuration/toml_options.en.md index 5b8d176f20e8..8777259f976a 100644 --- a/website_and_docs/content/documentation/grid/configuration/toml_options.en.md +++ b/website_and_docs/content/documentation/grid/configuration/toml_options.en.md @@ -188,4 +188,12 @@ driver.get("https://selenium.dev"); driver.quit(); ``` +### Retrieving downloaded files from Node. +To be able to retrieve the files that were downloaded by a test at the Node, its location can be specified as below: + +```toml +[node] +downloads-path = "/usr/downloads" +``` +Refer [here]({{< ref "cli_options.md#sample-that-retrieves-the-downloaded-file">}}) for a complete Java example. \ No newline at end of file diff --git a/website_and_docs/content/documentation/grid/configuration/toml_options.ja.md b/website_and_docs/content/documentation/grid/configuration/toml_options.ja.md index 469cf6637307..12020ddba9d3 100644 --- a/website_and_docs/content/documentation/grid/configuration/toml_options.ja.md +++ b/website_and_docs/content/documentation/grid/configuration/toml_options.ja.md @@ -185,3 +185,13 @@ WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444"), options driver.get("https://selenium.dev"); driver.quit(); ``` + +### Retrieving downloaded files from Node. + +To be able to retrieve the files that were downloaded by a test at the Node, its location can be specified as below: + +```toml +[node] +downloads-path = "/usr/downloads" +``` +Refer [here]({{< ref "cli_options.md#sample-that-retrieves-the-downloaded-file">}}) for a complete Java example. diff --git a/website_and_docs/content/documentation/grid/configuration/toml_options.pt-br.md b/website_and_docs/content/documentation/grid/configuration/toml_options.pt-br.md index 092d98e4cfe5..e1a1204ed718 100644 --- a/website_and_docs/content/documentation/grid/configuration/toml_options.pt-br.md +++ b/website_and_docs/content/documentation/grid/configuration/toml_options.pt-br.md @@ -196,3 +196,13 @@ WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444"), options driver.get("https://selenium.dev"); driver.quit(); ``` + +### Retrieving downloaded files from Node. + +To be able to retrieve the files that were downloaded by a test at the Node, its location can be specified as below: + +```toml +[node] +downloads-path = "/usr/downloads" +``` +Refer [here]({{< ref "cli_options.md#sample-that-retrieves-the-downloaded-file">}}) for a complete Java example. \ No newline at end of file diff --git a/website_and_docs/content/documentation/grid/configuration/toml_options.zh-cn.md b/website_and_docs/content/documentation/grid/configuration/toml_options.zh-cn.md index 85736e8ea4ed..2824cf6b2255 100644 --- a/website_and_docs/content/documentation/grid/configuration/toml_options.zh-cn.md +++ b/website_and_docs/content/documentation/grid/configuration/toml_options.zh-cn.md @@ -204,3 +204,14 @@ WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444"), options driver.get("https://selenium.dev"); driver.quit(); ``` + +### Retrieving downloaded files from Node. + +To be able to retrieve the files that were downloaded by a test at the Node, its location can be specified as below: + +```toml +[node] +downloads-path = "/usr/downloads" +``` +Refer [here]({{< ref "cli_options.md#sample-that-retrieves-the-downloaded-file">}}) for a complete Java example. +

AltStyle によって変換されたページ (->オリジナル) /