MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / Script

Class Script

java/src/org/openqa/selenium/bidi/module/Script.java:57–437  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55import org.openqa.selenium.json.TypeToken;
56
57@Beta
58public class Script implements Closeable {
59 private final Set<String> browsingContextIds;
60
61 private static final Json JSON = new Json();
62
63 private final BiDi bidi;
64
65 private static final Function<@Nullable Object, EvaluateResult> evaluateResultMapper =
66 result -> createEvaluateResult(asMap(result));
67
68 private static final Function<@Nullable Object, List<RealmInfo>> realmInfoMapper =
69 ConverterFunctions.map("realms", new TypeToken<List<RealmInfo>>() {}.getType());
70
71 private static final Event<Message> messageEvent =
72 new Event<>("script.message", params -> JSON.convert(params, Message.class));
73
74 private static final Event<RealmInfo> realmCreated =
75 new Event<>("script.realmCreated", params -> JSON.convert(params, RealmInfo.class));
76
77 private static final Event<RealmInfo> realmDestroyed =
78 new Event<>("script.realmDestroyed", params -> JSON.convert(params, RealmInfo.class));
79
80 public Script(WebDriver driver) {
81 this(new HashSet<>(), driver);
82 }
83
84 public Script(String browsingContextId, WebDriver driver) {
85 this(Collections.singleton(Require.nonNull("Browsing context id", browsingContextId)), driver);
86 }
87
88 public Script(Set<String> browsingContextIds, WebDriver driver) {
89 Require.nonNull("WebDriver", driver);
90 Require.nonNull("Browsing context id list", browsingContextIds);
91
92 if (!(driver instanceof HasBiDi)) {
93 throw new IllegalArgumentException("WebDriver instance must support BiDi protocol");
94 }
95
96 this.bidi = ((HasBiDi) driver).getBiDi();
97 this.browsingContextIds = browsingContextIds;
98 }
99
100 public EvaluateResult callFunction(CallFunctionParameters parameters) {
101 return this.bidi.send(
102 new Command<>("script.callFunction", parameters.toMap(), evaluateResultMapper));
103 }
104
105 public EvaluateResult callFunctionInRealm(
106 String realmId,
107 String functionDeclaration,
108 boolean awaitPromise,
109 Optional<List<LocalValue>> arguments,
110 Optional<LocalValue> thisParameter,
111 Optional<ResultOwnership> resultOwnership) {
112 Map<String, Object> params =
113 getCallFunctionParams(
114 "realm",

Callers

nothing calls this directly

Calls 5

createEvaluateResultMethod · 0.95
asMapMethod · 0.95
mapMethod · 0.95
getTypeMethod · 0.45
convertMethod · 0.45

Tested by

no test coverage detected