Skip to content

Commit ed0a688

Browse files
pujaganisandeepsuryaprasad
authored andcommitted
[bidi] Add source type to log entry (SeleniumHQ#14244)
1 parent 488df1e commit ed0a688

File tree

9 files changed

+93
-53
lines changed

9 files changed

+93
-53
lines changed

java/src/org/openqa/selenium/bidi/log/BaseLogEntry.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717

1818
package org.openqa.selenium.bidi.log;
1919

20+
import org.openqa.selenium.bidi.script.Source;
21+
2022
// @see <a
2123
// href="https://w3c.github.io/webdriver-bidi/#types-log-logentry">https://w3c.github.io/webdriver-bidi/#types-log-logentry</a>
2224
public class BaseLogEntry {
2325

2426
private final LogLevel level;
27+
private Source source;
2528
private final String text;
2629
private final long timestamp;
2730
private final StackTrace stackTrace;
@@ -42,8 +45,14 @@ public StackTrace getStackTrace() {
4245
return stackTrace;
4346
}
4447

45-
public BaseLogEntry(LogLevel level, String text, long timestamp, StackTrace stackTrace) {
48+
public Source getSource() {
49+
return source;
50+
}
51+
52+
public BaseLogEntry(
53+
LogLevel level, Source source, String text, long timestamp, StackTrace stackTrace) {
4654
this.level = level;
55+
this.source = source;
4756
this.text = text;
4857
this.timestamp = timestamp;
4958
this.stackTrace = stackTrace;

java/src/org/openqa/selenium/bidi/log/ConsoleLogEntry.java

+10-15
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.Map;
2424
import java.util.TreeMap;
2525
import org.openqa.selenium.bidi.script.RemoteValue;
26+
import org.openqa.selenium.bidi.script.Source;
2627
import org.openqa.selenium.json.JsonInput;
2728
import org.openqa.selenium.json.TypeToken;
2829

@@ -31,43 +32,37 @@
3132
public class ConsoleLogEntry extends GenericLogEntry {
3233

3334
private final String method;
34-
private final String realm;
3535
private final List<RemoteValue> args;
3636

3737
public ConsoleLogEntry(
3838
LogLevel level,
39+
Source source,
3940
String text,
4041
long timestamp,
4142
String type,
4243
String method,
43-
String realm,
4444
List<RemoteValue> args,
4545
StackTrace stackTrace) {
46-
super(level, text, timestamp, type, stackTrace);
46+
super(level, source, text, timestamp, type, stackTrace);
4747
this.method = method;
48-
this.realm = realm;
4948
this.args = args;
5049
}
5150

5251
public String getMethod() {
5352
return method;
5453
}
5554

56-
public String getRealm() {
57-
return realm;
58-
}
59-
6055
public List<RemoteValue> getArgs() {
6156
return args;
6257
}
6358

6459
public static ConsoleLogEntry fromJson(JsonInput input) {
6560
LogLevel level = null;
61+
Source source = null;
6662
String text = null;
6763
long timestamp = 0;
6864
String type = null;
6965
String method = null;
70-
String realm = null;
7166
List<RemoteValue> args = null;
7267
StackTrace stackTrace = null;
7368

@@ -78,6 +73,10 @@ public static ConsoleLogEntry fromJson(JsonInput input) {
7873
level = input.read(LogLevel.class);
7974
break;
8075

76+
case "source":
77+
source = input.read(Source.class);
78+
break;
79+
8180
case "text":
8281
text = input.read(String.class);
8382
break;
@@ -94,10 +93,6 @@ public static ConsoleLogEntry fromJson(JsonInput input) {
9493
method = input.read(String.class);
9594
break;
9695

97-
case "realm":
98-
realm = input.read(String.class);
99-
break;
100-
10196
case "args":
10297
args = input.read(new TypeToken<List<RemoteValue>>() {}.getType());
10398
break;
@@ -114,18 +109,18 @@ public static ConsoleLogEntry fromJson(JsonInput input) {
114109

115110
input.endObject();
116111

117-
return new ConsoleLogEntry(level, text, timestamp, type, method, realm, args, stackTrace);
112+
return new ConsoleLogEntry(level, source, text, timestamp, type, method, args, stackTrace);
118113
}
119114

120115
private Map<String, Object> toJson() {
121116
Map<String, Object> toReturn = new TreeMap<>();
122117

123118
toReturn.put("type", super.getType());
119+
toReturn.put("source", super.getSource());
124120
toReturn.put("level", super.getLevel());
125121
toReturn.put("text", super.getText());
126122
toReturn.put("timestamp", super.getTimestamp());
127123
toReturn.put("method", method);
128-
toReturn.put("realm", realm);
129124
toReturn.put("args", args);
130125
toReturn.put("stackTrace", super.getStackTrace());
131126

java/src/org/openqa/selenium/bidi/log/GenericLogEntry.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.util.Map;
2323
import java.util.TreeMap;
24+
import org.openqa.selenium.bidi.script.Source;
2425
import org.openqa.selenium.json.JsonInput;
2526

2627
// @see <a
@@ -30,8 +31,13 @@ public class GenericLogEntry extends BaseLogEntry {
3031
private final String type;
3132

3233
public GenericLogEntry(
33-
LogLevel level, String text, long timestamp, String type, StackTrace stackTrace) {
34-
super(level, text, timestamp, stackTrace);
34+
LogLevel level,
35+
Source source,
36+
String text,
37+
long timestamp,
38+
String type,
39+
StackTrace stackTrace) {
40+
super(level, source, text, timestamp, stackTrace);
3541
this.type = type;
3642
}
3743

@@ -41,6 +47,7 @@ public String getType() {
4147

4248
public static GenericLogEntry fromJson(JsonInput input) {
4349
LogLevel level = null;
50+
Source source = null;
4451
String text = null;
4552
long timestamp = 0;
4653
String type = null;
@@ -53,6 +60,10 @@ public static GenericLogEntry fromJson(JsonInput input) {
5360
level = input.read(LogLevel.class);
5461
break;
5562

63+
case "source":
64+
source = input.read(Source.class);
65+
break;
66+
5667
case "text":
5768
text = input.read(String.class);
5869
break;
@@ -77,7 +88,7 @@ public static GenericLogEntry fromJson(JsonInput input) {
7788

7889
input.endObject();
7990

80-
return new GenericLogEntry(level, text, timestamp, type, stackTrace);
91+
return new GenericLogEntry(level, source, text, timestamp, type, stackTrace);
8192
}
8293

8394
private Map<String, Object> toJson() {

java/src/org/openqa/selenium/bidi/log/JavascriptLogEntry.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.util.Map;
2323
import java.util.TreeMap;
24+
import org.openqa.selenium.bidi.script.Source;
2425
import org.openqa.selenium.json.JsonInput;
2526

2627
// @see <a
@@ -30,8 +31,13 @@ public class JavascriptLogEntry extends GenericLogEntry {
3031
private final String type;
3132

3233
public JavascriptLogEntry(
33-
LogLevel level, String text, long timestamp, String type, StackTrace stackTrace) {
34-
super(level, text, timestamp, "javascript", stackTrace);
34+
LogLevel level,
35+
Source source,
36+
String text,
37+
long timestamp,
38+
String type,
39+
StackTrace stackTrace) {
40+
super(level, source, text, timestamp, "javascript", stackTrace);
3541
this.type = "javascript";
3642
}
3743

@@ -41,6 +47,7 @@ public String getType() {
4147

4248
public static JavascriptLogEntry fromJson(JsonInput input) {
4349
LogLevel level = null;
50+
Source source = null;
4451
String text = null;
4552
long timestamp = 0;
4653
String type = null;
@@ -53,6 +60,10 @@ public static JavascriptLogEntry fromJson(JsonInput input) {
5360
level = input.read(LogLevel.class);
5461
break;
5562

63+
case "source":
64+
source = input.read(Source.class);
65+
break;
66+
5667
case "text":
5768
text = input.read(String.class);
5869
break;
@@ -77,7 +88,7 @@ public static JavascriptLogEntry fromJson(JsonInput input) {
7788

7889
input.endObject();
7990

80-
return new JavascriptLogEntry(level, text, timestamp, type, stackTrace);
91+
return new JavascriptLogEntry(level, source, text, timestamp, type, stackTrace);
8192
}
8293

8394
private Map<String, Object> toJson() {

java/test/org/openqa/selenium/bidi/log/LogInspectorTest.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.openqa.selenium.By;
3737
import org.openqa.selenium.WindowType;
3838
import org.openqa.selenium.bidi.module.LogInspector;
39+
import org.openqa.selenium.bidi.script.Source;
3940
import org.openqa.selenium.environment.webserver.AppServer;
4041
import org.openqa.selenium.environment.webserver.NettyAppServer;
4142
import org.openqa.selenium.testing.JupiterTestBase;
@@ -62,9 +63,10 @@ void canListenToConsoleLog() throws ExecutionException, InterruptedException, Ti
6263
driver.findElement(By.id("consoleLog")).click();
6364

6465
ConsoleLogEntry logEntry = future.get(5, TimeUnit.SECONDS);
65-
66+
Source source = logEntry.getSource();
67+
assertThat(source.getBrowsingContext().isPresent()).isTrue();
68+
assertThat(source.getRealm()).isNotNull();
6669
assertThat(logEntry.getText()).isEqualTo("Hello, world!");
67-
assertThat(logEntry.getRealm()).isNull();
6870
assertThat(logEntry.getArgs().size()).isEqualTo(1);
6971
assertThat(logEntry.getArgs().get(0).getType()).isEqualTo("string");
7072
assertThat(logEntry.getType()).isEqualTo("console");
@@ -86,7 +88,6 @@ void canFilterConsoleLogs() throws ExecutionException, InterruptedException, Tim
8688
ConsoleLogEntry logEntry = future.get(5, TimeUnit.SECONDS);
8789

8890
assertThat(logEntry.getText()).isEqualTo("Hello, world!");
89-
assertThat(logEntry.getRealm()).isNull();
9091
assertThat(logEntry.getArgs().size()).isEqualTo(1);
9192
assertThat(logEntry.getType()).isEqualTo("console");
9293
assertThat(logEntry.getLevel()).isEqualTo(LogLevel.INFO);
@@ -100,7 +101,6 @@ void canFilterConsoleLogs() throws ExecutionException, InterruptedException, Tim
100101
ConsoleLogEntry errorLogEntry = errorLogfuture.get(5, TimeUnit.SECONDS);
101102

102103
assertThat(errorLogEntry.getText()).isEqualTo("I am console error");
103-
assertThat(errorLogEntry.getRealm()).isNull();
104104
assertThat(errorLogEntry.getArgs().size()).isEqualTo(1);
105105
assertThat(errorLogEntry.getType()).isEqualTo("console");
106106
assertThat(errorLogEntry.getLevel()).isEqualTo(LogLevel.ERROR);
@@ -123,6 +123,10 @@ void canListenToJavascriptLog()
123123

124124
JavascriptLogEntry logEntry = future.get(5, TimeUnit.SECONDS);
125125

126+
Source source = logEntry.getSource();
127+
assertThat(source.getBrowsingContext().isPresent()).isTrue();
128+
assertThat(source.getRealm()).isNotNull();
129+
126130
assertThat(logEntry.getText()).isEqualTo("Error: Not working");
127131
assertThat(logEntry.getType()).isEqualTo("javascript");
128132
assertThat(logEntry.getLevel()).isEqualTo(LogLevel.ERROR);
@@ -218,7 +222,6 @@ void canFilterLogs() throws ExecutionException, InterruptedException {
218222

219223
ConsoleLogEntry consoleLogEntry = logEntry.getConsoleLogEntry().get();
220224
assertThat(consoleLogEntry.getText()).isEqualTo("Hello, world!");
221-
assertThat(consoleLogEntry.getRealm()).isNull();
222225
assertThat(consoleLogEntry.getArgs().size()).isEqualTo(1);
223226
assertThat(consoleLogEntry.getType()).isEqualTo("console");
224227
assertThat(consoleLogEntry.getLevel()).isEqualTo(LogLevel.INFO);
@@ -243,7 +246,6 @@ void canListenToConsoleLogForABrowsingContext()
243246
ConsoleLogEntry logEntry = future.get(5, TimeUnit.SECONDS);
244247

245248
assertThat(logEntry.getText()).isEqualTo("Hello, world!");
246-
assertThat(logEntry.getRealm()).isNull();
247249
assertThat(logEntry.getArgs().size()).isEqualTo(1);
248250
assertThat(logEntry.getType()).isEqualTo("console");
249251
assertThat(logEntry.getLevel()).isEqualTo(LogLevel.INFO);

java/test/org/openqa/selenium/grid/router/RemoteWebDriverBiDiTest.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.openqa.selenium.bidi.log.ConsoleLogEntry;
4343
import org.openqa.selenium.bidi.log.LogLevel;
4444
import org.openqa.selenium.bidi.module.LogInspector;
45+
import org.openqa.selenium.bidi.script.Source;
4546
import org.openqa.selenium.environment.webserver.AppServer;
4647
import org.openqa.selenium.environment.webserver.NettyAppServer;
4748
import org.openqa.selenium.grid.config.TomlConfig;
@@ -108,8 +109,10 @@ void canListenToLogs() throws ExecutionException, InterruptedException, TimeoutE
108109

109110
ConsoleLogEntry logEntry = future.get(5, TimeUnit.SECONDS);
110111

112+
Source source = logEntry.getSource();
113+
assertThat(source.getBrowsingContext().isPresent()).isTrue();
114+
assertThat(source.getRealm()).isNotNull();
111115
assertThat(logEntry.getText()).isEqualTo("Hello, world!");
112-
assertThat(logEntry.getRealm()).isNull();
113116
assertThat(logEntry.getArgs().size()).isEqualTo(1);
114117
assertThat(logEntry.getType()).isEqualTo("console");
115118
assertThat(logEntry.getLevel()).isEqualTo(LogLevel.INFO);

0 commit comments

Comments
 (0)