|
20 | 20 | import static org.assertj.core.api.Assertions.assertThat;
|
21 | 21 | import static org.openqa.selenium.remote.http.Contents.asJson;
|
22 | 22 | import static org.openqa.selenium.remote.http.Contents.string;
|
| 23 | +import static org.openqa.selenium.remote.http.HttpMethod.DELETE; |
23 | 24 | import static org.openqa.selenium.remote.http.HttpMethod.GET;
|
24 | 25 | import static org.openqa.selenium.remote.http.HttpMethod.POST;
|
25 | 26 | import static org.openqa.selenium.testing.drivers.Browser.IE;
|
@@ -115,14 +116,8 @@ void testCanListDownloadedFiles() throws InterruptedException {
|
115 | 116 | // Waiting for the file to be remotely downloaded
|
116 | 117 | TimeUnit.SECONDS.sleep(3);
|
117 | 118 |
|
118 |
| - HttpRequest request = new HttpRequest(GET, String.format("/session/%s/se/files", sessionId)); |
119 | 119 | try (HttpClient client = HttpClient.Factory.createDefault().createClient(gridUrl)) {
|
120 |
| - HttpResponse response = client.execute(request); |
121 |
| - Map<String, Object> jsonResponse = new Json().toType(string(response), Json.MAP_TYPE); |
122 |
| - @SuppressWarnings("unchecked") |
123 |
| - Map<String, Object> value = (Map<String, Object>) jsonResponse.get("value"); |
124 |
| - @SuppressWarnings("unchecked") |
125 |
| - List<String> names = (List<String>) value.get("names"); |
| 120 | + List<String> names = getDownloadedFilesList(client, sessionId); |
126 | 121 | assertThat(names).contains("file_1.txt", "file_2.jpg");
|
127 | 122 | } finally {
|
128 | 123 | driver.quit();
|
@@ -158,4 +153,45 @@ void testCanDownloadFiles() throws InterruptedException, IOException {
|
158 | 153 | driver.quit();
|
159 | 154 | }
|
160 | 155 | }
|
| 156 | + |
| 157 | + @Test |
| 158 | + @Ignore(IE) |
| 159 | + @Ignore(SAFARI) |
| 160 | + void testCanDeleteFiles() throws InterruptedException { |
| 161 | + URL gridUrl = server.getUrl(); |
| 162 | + RemoteWebDriver driver = new RemoteWebDriver(gridUrl, capabilities); |
| 163 | + driver.get(appServer.whereIs("downloads/download.html")); |
| 164 | + driver.findElement(By.id("file-1")).click(); |
| 165 | + SessionId sessionId = driver.getSessionId(); |
| 166 | + |
| 167 | + // Waiting for the file to be remotely downloaded |
| 168 | + TimeUnit.SECONDS.sleep(3); |
| 169 | + |
| 170 | + try (HttpClient client = HttpClient.Factory.createDefault().createClient(gridUrl)) { |
| 171 | + List<String> names = getDownloadedFilesList(client, sessionId); |
| 172 | + assertThat(names).contains("file_1.txt"); |
| 173 | + |
| 174 | + HttpRequest |
| 175 | + deleteRequest = |
| 176 | + new HttpRequest(DELETE, String.format("/session/%s/se/files", sessionId)); |
| 177 | + HttpResponse deleteResponse = client.execute(deleteRequest); |
| 178 | + assertThat(deleteResponse.isSuccessful()).isTrue(); |
| 179 | + |
| 180 | + List<String> afterDeleteNames = getDownloadedFilesList(client, sessionId); |
| 181 | + assertThat(afterDeleteNames.isEmpty()).isTrue(); |
| 182 | + } finally { |
| 183 | + driver.quit(); |
| 184 | + } |
| 185 | + } |
| 186 | + |
| 187 | + private static List<String> getDownloadedFilesList(HttpClient client, SessionId sessionId) { |
| 188 | + HttpRequest request = new HttpRequest(GET, String.format("/session/%s/se/files", sessionId)); |
| 189 | + HttpResponse response = client.execute(request); |
| 190 | + Map<String, Object> jsonResponse = new Json().toType(string(response), Json.MAP_TYPE); |
| 191 | + @SuppressWarnings("unchecked") |
| 192 | + Map<String, Object> value = (Map<String, Object>) jsonResponse.get("value"); |
| 193 | + @SuppressWarnings("unchecked") |
| 194 | + List<String> names = (List<String>) value.get("names"); |
| 195 | + return names; |
| 196 | + } |
161 | 197 | }
|
0 commit comments