Skip to content

Commit 385131e

Browse files
authored
chore: roll driver to 1.25.0 (#1026)
1 parent 6cb9f60 commit 385131e

File tree

11 files changed

+94
-27
lines changed

11 files changed

+94
-27
lines changed

playwright/src/main/java/com/microsoft/playwright/APIRequestContext.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030
*
3131
* <p> **Cookie management**
3232
*
33-
* <p> {@code APIRequestContext} retuned by {@link BrowserContext#request BrowserContext.request()} and {@link Page#request
33+
* <p> {@code APIRequestContext} returned by {@link BrowserContext#request BrowserContext.request()} and {@link Page#request
3434
* Page.request()} shares cookie storage with the corresponding {@code BrowserContext}. Each API request will have {@code Cookie}
3535
* header populated with the values from the browser context. If the API response contains {@code Set-Cookie} header it will
3636
* automatically update {@code BrowserContext} cookies and requests made from the page will pick them up. This means that if you
3737
* log in using this API, your e2e test will be logged in and vice versa.
3838
*
39-
* <p> If you want API requests to not interfere with the browser cookies you shoud create a new {@code APIRequestContext} by calling
40-
* {@link APIRequest#newContext APIRequest.newContext()}. Such {@code APIRequestContext} object will have its own isolated cookie
41-
* storage.
39+
* <p> If you want API requests to not interfere with the browser cookies you should create a new {@code APIRequestContext} by
40+
* calling {@link APIRequest#newContext APIRequest.newContext()}. Such {@code APIRequestContext} object will have its own
41+
* isolated cookie storage.
4242
*/
4343
public interface APIRequestContext {
4444
class StorageStateOptions {

playwright/src/main/java/com/microsoft/playwright/Browser.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ public StartTracingOptions setScreenshots(boolean screenshots) {
10991099
/**
11001100
* Creates a new browser context. It won't share cookies/cache with other browser contexts.
11011101
*
1102-
* <p> <strong>NOTE:</strong> If directly using this method to create {@code BrowserContext}s, it is best practice to explicilty close the returned context
1102+
* <p> <strong>NOTE:</strong> If directly using this method to create {@code BrowserContext}s, it is best practice to explicitly close the returned context
11031103
* via {@link BrowserContext#close BrowserContext.close()} when your code is done with the {@code BrowserContext}, and before
11041104
* calling {@link Browser#close Browser.close()}. This will ensure the {@code context} is closed gracefully and any
11051105
* artifacts—like HARs and videos—are fully flushed and saved.
@@ -1111,7 +1111,7 @@ public StartTracingOptions setScreenshots(boolean screenshots) {
11111111
* Page page = context.newPage();
11121112
* page.navigate('https://example.com');
11131113
*
1114-
* // Gracefull close up everything
1114+
* // Graceful close up everything
11151115
* context.close();
11161116
* browser.close();
11171117
* }</pre>
@@ -1122,7 +1122,7 @@ default BrowserContext newContext() {
11221122
/**
11231123
* Creates a new browser context. It won't share cookies/cache with other browser contexts.
11241124
*
1125-
* <p> <strong>NOTE:</strong> If directly using this method to create {@code BrowserContext}s, it is best practice to explicilty close the returned context
1125+
* <p> <strong>NOTE:</strong> If directly using this method to create {@code BrowserContext}s, it is best practice to explicitly close the returned context
11261126
* via {@link BrowserContext#close BrowserContext.close()} when your code is done with the {@code BrowserContext}, and before
11271127
* calling {@link Browser#close Browser.close()}. This will ensure the {@code context} is closed gracefully and any
11281128
* artifacts—like HARs and videos—are fully flushed and saved.
@@ -1134,7 +1134,7 @@ default BrowserContext newContext() {
11341134
* Page page = context.newPage();
11351135
* page.navigate('https://example.com');
11361136
*
1137-
* // Gracefull close up everything
1137+
* // Graceful close up everything
11381138
* context.close();
11391139
* browser.close();
11401140
* }</pre>

playwright/src/main/java/com/microsoft/playwright/ElementHandle.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ class ScreenshotOptions {
586586
*/
587587
public ScreenshotCaret caret;
588588
/**
589-
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlayed with a pink box
589+
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
590590
* {@code #FF00FF} that completely covers its bounding box.
591591
*/
592592
public List<Locator> mask;
@@ -647,7 +647,7 @@ public ScreenshotOptions setCaret(ScreenshotCaret caret) {
647647
return this;
648648
}
649649
/**
650-
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlayed with a pink box
650+
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
651651
* {@code #FF00FF} that completely covers its bounding box.
652652
*/
653653
public ScreenshotOptions setMask(List<Locator> mask) {

playwright/src/main/java/com/microsoft/playwright/Locator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ class ScreenshotOptions {
10131013
*/
10141014
public ScreenshotCaret caret;
10151015
/**
1016-
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlayed with a pink box
1016+
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
10171017
* {@code #FF00FF} that completely covers its bounding box.
10181018
*/
10191019
public List<Locator> mask;
@@ -1074,7 +1074,7 @@ public ScreenshotOptions setCaret(ScreenshotCaret caret) {
10741074
return this;
10751075
}
10761076
/**
1077-
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlayed with a pink box
1077+
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
10781078
* {@code #FF00FF} that completely covers its bounding box.
10791079
*/
10801080
public ScreenshotOptions setMask(List<Locator> mask) {

playwright/src/main/java/com/microsoft/playwright/Page.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,7 +2080,7 @@ class ScreenshotOptions {
20802080
*/
20812081
public Boolean fullPage;
20822082
/**
2083-
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlayed with a pink box
2083+
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
20842084
* {@code #FF00FF} that completely covers its bounding box.
20852085
*/
20862086
public List<Locator> mask;
@@ -2162,7 +2162,7 @@ public ScreenshotOptions setFullPage(boolean fullPage) {
21622162
return this;
21632163
}
21642164
/**
2165-
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlayed with a pink box
2165+
* Specify locators that should be masked when the screenshot is taken. Masked elements will be overlaid with a pink box
21662166
* {@code #FF00FF} that completely covers its bounding box.
21672167
*/
21682168
public ScreenshotOptions setMask(List<Locator> mask) {

playwright/src/main/java/com/microsoft/playwright/Response.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public interface Response {
4040
*/
4141
Frame frame();
4242
/**
43-
* Indicates whether this Response was fullfilled by a Service Worker's Fetch Handler (i.e. via <a
43+
* Indicates whether this Response was fulfilled by a Service Worker's Fetch Handler (i.e. via <a
4444
* href="https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/respondWith">FetchEvent.respondWith</a>).
4545
*/
4646
boolean fromServiceWorker();

playwright/src/main/java/com/microsoft/playwright/assertions/PlaywrightAssertions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static PageAssertions assertThat(Page page) {
8888
}
8989

9090
/**
91-
* Changes default timeout for Playwright assertions from 5 seconds to the speicified value.
91+
* Changes default timeout for Playwright assertions from 5 seconds to the specified value.
9292
* <pre>{@code
9393
* PlaywrightAssertions.setDefaultAssertionTimeout(30_000);
9494
* }</pre>

playwright/src/main/java/com/microsoft/playwright/impl/APIResponseAssertionsImpl.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.opentest4j.AssertionFailedError;
2222

2323
import java.util.List;
24+
import java.util.regex.Pattern;
2425

2526
public class APIResponseAssertionsImpl implements APIResponseAssertions {
2627
private final APIResponse actual;
@@ -54,6 +55,20 @@ public void isOK() {
5455
if (!log.isEmpty()) {
5556
log = "\nCall log:\n" + log;
5657
}
57-
throw new AssertionFailedError(message + log);
58+
59+
String contentType = actual.headers().get("content-type");
60+
boolean isTextEncoding = contentType == null ? false : isTextualMimeType(contentType);
61+
String responseText = "";
62+
if (isTextEncoding) {
63+
String text = actual.text();
64+
if (text != null) {
65+
responseText = "\nResponse text:\n" + (text.length() > 1000 ? text.substring(0, 1000) : text);
66+
}
67+
}
68+
69+
throw new AssertionFailedError(message + log + responseText);
70+
}
71+
static boolean isTextualMimeType(String mimeType) {
72+
return Pattern.matches("^(text/.*?|application/(json|(x-)?javascript|xml.*?|ecmascript|graphql|x-www-form-urlencoded)|image/svg(\\+xml)?|application/.*?(\\+json|\\+xml))(;\\s*charset=.*)?$", mimeType);
5873
}
5974
}

playwright/src/test/java/com/microsoft/playwright/Server.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ public void handle(HttpExchange exchange) throws IOException {
195195
String resourcePath = "resources" + path;
196196
InputStream resource = getClass().getClassLoader().getResourceAsStream(resourcePath);
197197
if (resource == null) {
198+
exchange.getResponseHeaders().add("Content-Type", "text/plain");
198199
exchange.sendResponseHeaders(404, 0);
199200
try (Writer writer = new OutputStreamWriter(exchange.getResponseBody())) {
200201
writer.write("File not found: " + resourcePath);

playwright/src/test/java/com/microsoft/playwright/TestAPIResponseAssertions.java

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
import org.junit.jupiter.api.Test;
2020
import org.opentest4j.AssertionFailedError;
2121

22+
import java.io.OutputStreamWriter;
23+
import java.io.Writer;
24+
2225
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
23-
import static org.junit.jupiter.api.Assertions.assertTrue;
26+
import static org.junit.jupiter.api.Assertions.*;
2427

2528
public class TestAPIResponseAssertions extends TestBase {
2629
@Test
@@ -38,14 +41,62 @@ void passWithNot() {
3841
@Test
3942
void fail() {
4043
APIResponse res = page.request().get(server.PREFIX + "/unknown");
41-
boolean didThrow = false;
42-
try {
43-
assertThat(res).isOK();
44-
} catch (AssertionFailedError e) {
45-
didThrow = true;
46-
assertTrue(e.getMessage().contains("→ GET " + server.PREFIX + "/unknown"), "Actual error: " + e.toString());
47-
assertTrue(e.getMessage().contains("← 404 Not Found"), "Actual error: " + e.toString());
44+
AssertionFailedError e = assertThrows(AssertionFailedError.class, () -> assertThat(res).isOK());
45+
assertTrue(e.getMessage().contains("→ GET " + server.PREFIX + "/unknown"), "Actual error: " + e.toString());
46+
assertTrue(e.getMessage().contains("← 404 Not Found"), "Actual error: " + e.toString());
47+
}
48+
49+
@Test
50+
void shouldPrintResponseTextIfIdOkFails() {
51+
APIResponse res = page.request().get(server.PREFIX + "/unknown");
52+
AssertionFailedError e = assertThrows(AssertionFailedError.class, () -> assertThat(res).isOK());
53+
assertTrue(e.getMessage().contains("File not found"), "Actual error: " + e.toString());
54+
}
55+
56+
@Test
57+
void shouldOnlyPrintResponseWithTextContentTypeIfIsOkFails() {
58+
{
59+
server.setRoute("/text-content-type", exchange -> {
60+
exchange.getResponseHeaders().set("Content-type", "text/plain");
61+
exchange.sendResponseHeaders(404, 0);
62+
try (Writer writer = new OutputStreamWriter(exchange.getResponseBody())) {
63+
writer.write("Text error");
64+
}
65+
});
66+
AssertionFailedError e = assertThrows(AssertionFailedError.class, () -> assertThat(page.request().get(server.PREFIX + "/text-content-type")).isOK());
67+
assertTrue(e.getMessage().contains("Text error"), "Actual error: " + e);
68+
}
69+
{
70+
server.setRoute("/svg-xml-content-type", exchange -> {
71+
exchange.getResponseHeaders().set("Content-type", "image/svg+xml");
72+
exchange.sendResponseHeaders(404, 0);
73+
try (Writer writer = new OutputStreamWriter(exchange.getResponseBody())) {
74+
writer.write("Json error");
75+
}
76+
});
77+
AssertionFailedError e = assertThrows(AssertionFailedError.class, () -> assertThat(page.request().get(server.PREFIX + "/svg-xml-content-type")).isOK());
78+
assertTrue(e.getMessage().contains("Json error"), "Actual error: " + e);
79+
}
80+
{
81+
server.setRoute("/no-content-type", exchange -> {
82+
exchange.sendResponseHeaders(404, 0);
83+
try (Writer writer = new OutputStreamWriter(exchange.getResponseBody())) {
84+
writer.write("No content type error");
85+
}
86+
});
87+
AssertionFailedError e = assertThrows(AssertionFailedError.class, () -> assertThat(page.request().get(server.PREFIX + "/no-content-type")).isOK());
88+
assertFalse(e.getMessage().contains("No content type error"), "Actual error: " + e);
89+
}
90+
{
91+
server.setRoute("/image-content-type", exchange -> {
92+
exchange.getResponseHeaders().set("Content-type", "image/bmp");
93+
exchange.sendResponseHeaders(404, 0);
94+
try (Writer writer = new OutputStreamWriter(exchange.getResponseBody())) {
95+
writer.write("Image type error");
96+
}
97+
});
98+
AssertionFailedError e = assertThrows(AssertionFailedError.class, () -> assertThat(page.request().get(server.PREFIX + "/image-content-type")).isOK());
99+
assertFalse(e.getMessage().contains("Image type error"), "Actual error: " + e);
48100
}
49-
assertTrue(didThrow);
50101
}
51102
}

0 commit comments

Comments
 (0)