Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bidi] Add source type to log entry #14244

Merged
merged 3 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion java/src/org/openqa/selenium/bidi/log/BaseLogEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@

package org.openqa.selenium.bidi.log;

import org.openqa.selenium.bidi.script.Source;

// @see <a
// href="https://w3c.github.io/webdriver-bidi/#types-log-logentry">https://w3c.github.io/webdriver-bidi/#types-log-logentry</a>
public class BaseLogEntry {

private final LogLevel level;
private Source source;
private final String text;
private final long timestamp;
private final StackTrace stackTrace;
Expand All @@ -42,8 +45,14 @@ public StackTrace getStackTrace() {
return stackTrace;
}

public BaseLogEntry(LogLevel level, String text, long timestamp, StackTrace stackTrace) {
public Source getSource() {
return source;
}

public BaseLogEntry(
LogLevel level, Source source, String text, long timestamp, StackTrace stackTrace) {
this.level = level;
this.source = source;
this.text = text;
this.timestamp = timestamp;
this.stackTrace = stackTrace;
Expand Down
25 changes: 10 additions & 15 deletions java/src/org/openqa/selenium/bidi/log/ConsoleLogEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;
import java.util.TreeMap;
import org.openqa.selenium.bidi.script.RemoteValue;
import org.openqa.selenium.bidi.script.Source;
import org.openqa.selenium.json.JsonInput;
import org.openqa.selenium.json.TypeToken;

Expand All @@ -31,43 +32,37 @@
public class ConsoleLogEntry extends GenericLogEntry {

private final String method;
private final String realm;
private final List<RemoteValue> args;

public ConsoleLogEntry(
LogLevel level,
Source source,
String text,
long timestamp,
String type,
String method,
String realm,
List<RemoteValue> args,
StackTrace stackTrace) {
super(level, text, timestamp, type, stackTrace);
super(level, source, text, timestamp, type, stackTrace);
this.method = method;
this.realm = realm;
this.args = args;
}

public String getMethod() {
return method;
}

public String getRealm() {
return realm;
}

public List<RemoteValue> getArgs() {
return args;
}

public static ConsoleLogEntry fromJson(JsonInput input) {
LogLevel level = null;
Source source = null;
String text = null;
long timestamp = 0;
String type = null;
String method = null;
String realm = null;
List<RemoteValue> args = null;
StackTrace stackTrace = null;

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

case "source":
source = input.read(Source.class);
break;

case "text":
text = input.read(String.class);
break;
Expand All @@ -94,10 +93,6 @@ public static ConsoleLogEntry fromJson(JsonInput input) {
method = input.read(String.class);
break;

case "realm":
realm = input.read(String.class);
break;

case "args":
args = input.read(new TypeToken<List<RemoteValue>>() {}.getType());
break;
Expand All @@ -114,18 +109,18 @@ public static ConsoleLogEntry fromJson(JsonInput input) {

input.endObject();

return new ConsoleLogEntry(level, text, timestamp, type, method, realm, args, stackTrace);
return new ConsoleLogEntry(level, source, text, timestamp, type, method, args, stackTrace);
}

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

toReturn.put("type", super.getType());
toReturn.put("source", super.getSource());
toReturn.put("level", super.getLevel());
toReturn.put("text", super.getText());
toReturn.put("timestamp", super.getTimestamp());
toReturn.put("method", method);
toReturn.put("realm", realm);
toReturn.put("args", args);
toReturn.put("stackTrace", super.getStackTrace());

Expand Down
17 changes: 14 additions & 3 deletions java/src/org/openqa/selenium/bidi/log/GenericLogEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.Map;
import java.util.TreeMap;
import org.openqa.selenium.bidi.script.Source;
import org.openqa.selenium.json.JsonInput;

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

public GenericLogEntry(
LogLevel level, String text, long timestamp, String type, StackTrace stackTrace) {
super(level, text, timestamp, stackTrace);
LogLevel level,
Source source,
String text,
long timestamp,
String type,
StackTrace stackTrace) {
super(level, source, text, timestamp, stackTrace);
this.type = type;
}

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

public static GenericLogEntry fromJson(JsonInput input) {
LogLevel level = null;
Source source = null;
String text = null;
long timestamp = 0;
String type = null;
Expand All @@ -53,6 +60,10 @@ public static GenericLogEntry fromJson(JsonInput input) {
level = input.read(LogLevel.class);
break;

case "source":
source = input.read(Source.class);
break;

case "text":
text = input.read(String.class);
break;
Expand All @@ -77,7 +88,7 @@ public static GenericLogEntry fromJson(JsonInput input) {

input.endObject();

return new GenericLogEntry(level, text, timestamp, type, stackTrace);
return new GenericLogEntry(level, source, text, timestamp, type, stackTrace);
}

private Map<String, Object> toJson() {
Expand Down
17 changes: 14 additions & 3 deletions java/src/org/openqa/selenium/bidi/log/JavascriptLogEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.Map;
import java.util.TreeMap;
import org.openqa.selenium.bidi.script.Source;
import org.openqa.selenium.json.JsonInput;

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

public JavascriptLogEntry(
LogLevel level, String text, long timestamp, String type, StackTrace stackTrace) {
super(level, text, timestamp, "javascript", stackTrace);
LogLevel level,
Source source,
String text,
long timestamp,
String type,
StackTrace stackTrace) {
super(level, source, text, timestamp, "javascript", stackTrace);
this.type = "javascript";
}

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

public static JavascriptLogEntry fromJson(JsonInput input) {
LogLevel level = null;
Source source = null;
String text = null;
long timestamp = 0;
String type = null;
Expand All @@ -53,6 +60,10 @@ public static JavascriptLogEntry fromJson(JsonInput input) {
level = input.read(LogLevel.class);
break;

case "source":
source = input.read(Source.class);
break;

case "text":
text = input.read(String.class);
break;
Expand All @@ -77,7 +88,7 @@ public static JavascriptLogEntry fromJson(JsonInput input) {

input.endObject();

return new JavascriptLogEntry(level, text, timestamp, type, stackTrace);
return new JavascriptLogEntry(level, source, text, timestamp, type, stackTrace);
}

private Map<String, Object> toJson() {
Expand Down
14 changes: 8 additions & 6 deletions java/test/org/openqa/selenium/bidi/log/LogInspectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.openqa.selenium.By;
import org.openqa.selenium.WindowType;
import org.openqa.selenium.bidi.module.LogInspector;
import org.openqa.selenium.bidi.script.Source;
import org.openqa.selenium.environment.webserver.AppServer;
import org.openqa.selenium.environment.webserver.NettyAppServer;
import org.openqa.selenium.testing.JupiterTestBase;
Expand All @@ -62,9 +63,10 @@ void canListenToConsoleLog() throws ExecutionException, InterruptedException, Ti
driver.findElement(By.id("consoleLog")).click();

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

Source source = logEntry.getSource();
assertThat(source.getBrowsingContext().isPresent()).isTrue();
assertThat(source.getRealm()).isNotNull();
assertThat(logEntry.getText()).isEqualTo("Hello, world!");
assertThat(logEntry.getRealm()).isNull();
assertThat(logEntry.getArgs().size()).isEqualTo(1);
assertThat(logEntry.getArgs().get(0).getType()).isEqualTo("string");
assertThat(logEntry.getType()).isEqualTo("console");
Expand All @@ -86,7 +88,6 @@ void canFilterConsoleLogs() throws ExecutionException, InterruptedException, Tim
ConsoleLogEntry logEntry = future.get(5, TimeUnit.SECONDS);

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

assertThat(errorLogEntry.getText()).isEqualTo("I am console error");
assertThat(errorLogEntry.getRealm()).isNull();
assertThat(errorLogEntry.getArgs().size()).isEqualTo(1);
assertThat(errorLogEntry.getType()).isEqualTo("console");
assertThat(errorLogEntry.getLevel()).isEqualTo(LogLevel.ERROR);
Expand All @@ -123,6 +123,10 @@ void canListenToJavascriptLog()

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

Source source = logEntry.getSource();
assertThat(source.getBrowsingContext().isPresent()).isTrue();
assertThat(source.getRealm()).isNotNull();

assertThat(logEntry.getText()).isEqualTo("Error: Not working");
assertThat(logEntry.getType()).isEqualTo("javascript");
assertThat(logEntry.getLevel()).isEqualTo(LogLevel.ERROR);
Expand Down Expand Up @@ -218,7 +222,6 @@ void canFilterLogs() throws ExecutionException, InterruptedException {

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

assertThat(logEntry.getText()).isEqualTo("Hello, world!");
assertThat(logEntry.getRealm()).isNull();
assertThat(logEntry.getArgs().size()).isEqualTo(1);
assertThat(logEntry.getType()).isEqualTo("console");
assertThat(logEntry.getLevel()).isEqualTo(LogLevel.INFO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.openqa.selenium.bidi.log.ConsoleLogEntry;
import org.openqa.selenium.bidi.log.LogLevel;
import org.openqa.selenium.bidi.module.LogInspector;
import org.openqa.selenium.bidi.script.Source;
import org.openqa.selenium.environment.webserver.AppServer;
import org.openqa.selenium.environment.webserver.NettyAppServer;
import org.openqa.selenium.grid.config.TomlConfig;
Expand Down Expand Up @@ -108,8 +109,10 @@ void canListenToLogs() throws ExecutionException, InterruptedException, TimeoutE

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

Source source = logEntry.getSource();
assertThat(source.getBrowsingContext().isPresent()).isTrue();
assertThat(source.getRealm()).isNotNull();
assertThat(logEntry.getText()).isEqualTo("Hello, world!");
assertThat(logEntry.getRealm()).isNull();
assertThat(logEntry.getArgs().size()).isEqualTo(1);
assertThat(logEntry.getType()).isEqualTo("console");
assertThat(logEntry.getLevel()).isEqualTo(LogLevel.INFO);
Expand Down
Loading
Loading