org.openqa.selenium.devtools.runtime.model.RemoteObject Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of selenium-devtools Show documentation
Show all versions of selenium-devtools Show documentation
Selenium automates browsers. That's it! What you do with that power is entirely up to you.
package org.openqa.selenium.devtools.runtime.model;
import org.openqa.selenium.Beta;
import org.openqa.selenium.json.JsonInput;
/**
* Mirror object referencing original JavaScript object.
*/
public class RemoteObject {
public enum Type {
OBJECT("object"),
FUNCTION("function"),
UNDEFINED("undefined"),
STRING("string"),
NUMBER("number"),
BOOLEAN("boolean"),
SYMBOL("symbol"),
BIGINT("bigint"),
WASM("wasm");
private String value;
Type(String value) {
this.value = value;
}
public static Type fromString(String s) {
return java.util.Arrays.stream(Type.values()).filter(rs -> rs.value.equalsIgnoreCase(s)).findFirst().orElseThrow(() -> new org.openqa.selenium.devtools.DevToolsException("Given value " + s + " is not found within Type "));
}
public String toString() {
return value;
}
public String toJson() {
return value;
}
private static Type fromJson(JsonInput input) {
return fromString(input.nextString());
}
}
public enum Subtype {
ARRAY("array"),
NULL("null"),
NODE("node"),
REGEXP("regexp"),
DATE("date"),
MAP("map"),
SET("set"),
WEAKMAP("weakmap"),
WEAKSET("weakset"),
ITERATOR("iterator"),
GENERATOR("generator"),
ERROR("error"),
PROXY("proxy"),
PROMISE("promise"),
TYPEDARRAY("typedarray"),
ARRAYBUFFER("arraybuffer"),
DATAVIEW("dataview"),
I32("i32"),
I64("i64"),
F32("f32"),
F64("f64"),
V128("v128"),
ANYREF("anyref");
private String value;
Subtype(String value) {
this.value = value;
}
public static Subtype fromString(String s) {
return java.util.Arrays.stream(Subtype.values()).filter(rs -> rs.value.equalsIgnoreCase(s)).findFirst().orElseThrow(() -> new org.openqa.selenium.devtools.DevToolsException("Given value " + s + " is not found within Subtype "));
}
public String toString() {
return value;
}
public String toJson() {
return value;
}
private static Subtype fromJson(JsonInput input) {
return fromString(input.nextString());
}
}
private final Type type;
private final java.util.Optional subtype;
private final java.util.Optional className;
private final java.util.Optional> value;
private final java.util.Optional unserializableValue;
private final java.util.Optional description;
private final java.util.Optional objectId;
private final java.util.Optional preview;
private final java.util.Optional customPreview;
public RemoteObject(Type type, java.util.Optional subtype, java.util.Optional className, java.util.Optional> value, java.util.Optional unserializableValue, java.util.Optional description, java.util.Optional objectId, java.util.Optional preview, java.util.Optional customPreview) {
this.type = java.util.Objects.requireNonNull(type, "type is required");
this.subtype = subtype;
this.className = className;
this.value = value;
this.unserializableValue = unserializableValue;
this.description = description;
this.objectId = objectId;
this.preview = preview;
this.customPreview = customPreview;
}
/**
* Object type.
*/
public Type getType() {
return type;
}
/**
* Object subtype hint. Specified for `object` or `wasm` type values only.
*/
public java.util.Optional getSubtype() {
return subtype;
}
/**
* Object class (constructor) name. Specified for `object` type values only.
*/
public java.util.Optional getClassName() {
return className;
}
/**
* Remote object value in case of primitive values or JSON values (if it was requested).
*/
public java.util.Optional> getValue() {
return value;
}
/**
* Primitive value which can not be JSON-stringified does not have `value`, but gets this
* property.
*/
public java.util.Optional getUnserializableValue() {
return unserializableValue;
}
/**
* String representation of the object.
*/
public java.util.Optional getDescription() {
return description;
}
/**
* Unique object identifier (for non-primitive values).
*/
public java.util.Optional getObjectId() {
return objectId;
}
/**
* Preview containing abbreviated property values. Specified for `object` type values only.
*/
@Beta()
public java.util.Optional getPreview() {
return preview;
}
@Beta()
public java.util.Optional getCustomPreview() {
return customPreview;
}
private static RemoteObject fromJson(JsonInput input) {
Type type = null;
java.util.Optional subtype = java.util.Optional.empty();
java.util.Optional className = java.util.Optional.empty();
java.util.Optional> value = java.util.Optional.empty();
java.util.Optional unserializableValue = java.util.Optional.empty();
java.util.Optional description = java.util.Optional.empty();
java.util.Optional objectId = java.util.Optional.empty();
java.util.Optional preview = java.util.Optional.empty();
java.util.Optional customPreview = java.util.Optional.empty();
input.beginObject();
while (input.hasNext()) {
switch(input.nextName()) {
case "type":
type = Type.fromString(input.nextString());
break;
case "subtype":
subtype = java.util.Optional.ofNullable(Subtype.fromString(input.nextString()));
break;
case "className":
className = java.util.Optional.ofNullable(input.nextString());
break;
case "value":
value = java.util.Optional.ofNullable(input.read(new com.google.common.reflect.TypeToken>() {
}.getType()));
break;
case "unserializableValue":
unserializableValue = java.util.Optional.ofNullable(input.read(org.openqa.selenium.devtools.runtime.model.UnserializableValue.class));
break;
case "description":
description = java.util.Optional.ofNullable(input.nextString());
break;
case "objectId":
objectId = java.util.Optional.ofNullable(input.read(org.openqa.selenium.devtools.runtime.model.RemoteObjectId.class));
break;
case "preview":
preview = java.util.Optional.ofNullable(input.read(org.openqa.selenium.devtools.runtime.model.ObjectPreview.class));
break;
case "customPreview":
customPreview = java.util.Optional.ofNullable(input.read(org.openqa.selenium.devtools.runtime.model.CustomPreview.class));
break;
default:
input.skipValue();
break;
}
}
input.endObject();
return new RemoteObject(type, subtype, className, value, unserializableValue, description, objectId, preview, customPreview);
}
}