Skip to content

Commit 1ff3029

Browse files
committed
titles
1 parent b59d88c commit 1ff3029

File tree

8 files changed

+110
-93
lines changed

8 files changed

+110
-93
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,27 @@ class AssertionsBase {
3838
this.isNot = isNot;
3939
}
4040

41-
void expectImpl(String expression, ExpectedTextValue textValue, Object expected, String message, FrameExpectOptions options) {
42-
expectImpl(expression, asList(textValue), expected, message, options);
41+
void expectImpl(String expression, ExpectedTextValue textValue, Object expected, String message, FrameExpectOptions options, String title) {
42+
expectImpl(expression, asList(textValue), expected, message, options, title);
4343
}
4444

45-
void expectImpl(String expression, List<ExpectedTextValue> expectedText, Object expected, String message, FrameExpectOptions options) {
45+
void expectImpl(String expression, List<ExpectedTextValue> expectedText, Object expected, String message, FrameExpectOptions options, String title) {
4646
if (options == null) {
4747
options = new FrameExpectOptions();
4848
}
4949
options.expectedText = expectedText;
50-
expectImpl(expression, options, expected, message);
50+
expectImpl(expression, options, expected, message, title);
5151
}
5252

53-
void expectImpl(String expression, FrameExpectOptions expectOptions, Object expected, String message) {
53+
void expectImpl(String expression, FrameExpectOptions expectOptions, Object expected, String message, String title) {
5454
if (expectOptions.timeout == null) {
5555
expectOptions.timeout = AssertionsTimeout.defaultTimeout;
5656
}
5757
expectOptions.isNot = isNot;
5858
if (isNot) {
5959
message = message.replace("expected to", "expected not to");
6060
}
61-
FrameExpectResult result = actualLocator.expect(expression, expectOptions);
61+
FrameExpectResult result = actualLocator.expect(expression, expectOptions, title);
6262
if (result.matches == isNot) {
6363
Object actual = result.received == null ? null : Serialization.deserialize(result.received);
6464
String log = (result.log == null) ? "" : String.join("\n", result.log);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private BrowserContextImpl newContextImpl(NewContextOptions options) {
229229

230230
@Override
231231
public Page newPage(NewPageOptions options) {
232-
return withLogging("Browser.newPage", () -> newPageImpl(options));
232+
return withTitle("Create Page", () -> newPageImpl(options));
233233
}
234234

235235
@Override

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,27 @@ <T> T withWaitLogging(String apiName, Function<Logger, T> code) {
8282
return new WaitForEventLogger<>(this, apiName, code).get();
8383
}
8484

85+
@Deprecated
8586
@Override
8687
<T> T withLogging(String apiName, Supplier<T> code) {
87-
String previousApiName = connection.setApiName(apiName);
88+
// this has so many callers, removing it would clutter this PR.
89+
// it's a no-op for now, and i'll remove it from the codebase in the next PR.
90+
return super.withLogging(apiName, code);
91+
}
92+
93+
void withTitle(String title, Runnable code) {
94+
withTitle(title, () -> {
95+
code.run();
96+
return null;
97+
});
98+
}
99+
100+
<T> T withTitle(String title, Supplier<T> code) {
101+
String previousTitle = connection.setTitle(title);
88102
try {
89-
return super.withLogging(apiName, code);
103+
return code.get();
90104
} finally {
91-
connection.setApiName(previousApiName);
105+
connection.setTitle(previousTitle);
92106
}
93107
}
94108

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import com.google.gson.JsonArray;
2020
import com.google.gson.JsonElement;
2121
import com.google.gson.JsonObject;
22-
import com.microsoft.playwright.Playwright;
2322
import com.microsoft.playwright.PlaywrightException;
2423
import com.microsoft.playwright.TimeoutError;
2524

@@ -64,7 +63,8 @@ public class Connection {
6463
private int lastId = 0;
6564
private final StackTraceCollector stackTraceCollector;
6665
private final Map<Integer, WaitableResult<JsonElement>> callbacks = new HashMap<>();
67-
private String apiName;
66+
private String title;
67+
private boolean titleReported = false;
6868
private static final boolean isLogging;
6969
static {
7070
String debug = System.getenv("DEBUG");
@@ -116,9 +116,10 @@ void setIsTracing(boolean tracing) {
116116
}
117117
}
118118

119-
String setApiName(String name) {
120-
String previous = apiName;
121-
apiName = name;
119+
String setTitle(String newTitle) {
120+
String previous = title;
121+
titleReported = false;
122+
title = newTitle;
122123
return previous;
123124
}
124125

@@ -146,12 +147,12 @@ private WaitableResult<JsonElement> internalSendMessage(String guid, String meth
146147
JsonObject metadata = new JsonObject();
147148
metadata.addProperty("wallTime", currentTimeMillis());
148149
JsonArray stack = null;
149-
if (apiName == null) {
150+
if (titleReported) {
150151
metadata.addProperty("internal", true);
151152
} else {
152-
metadata.addProperty("apiName", apiName);
153-
// All but first message in an API call are considered internal and will be hidden from the inspector.
154-
apiName = null;
153+
metadata.addProperty("title", title);
154+
// All but first message in a custom-titled API call are considered internal and will be hidden from the inspector.
155+
titleReported = true;
155156
if (stackTraceCollector != null) {
156157
stack = stackTraceCollector.currentStackTrace();
157158
if (!stack.isEmpty()) {

0 commit comments

Comments
 (0)