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

Method send

java/src/org/openqa/selenium/devtools/Connection.java:145–195  ·  view source on GitHub ↗
(@Nullable SessionID sessionId, Command<X> command)

Source from the content-addressed store, hash-verified

143 }
144
145 public <X> CompletableFuture<X> send(@Nullable SessionID sessionId, Command<X> command) {
146 long id = NEXT_ID.getAndIncrement();
147
148 CompletableFuture<X> result = new CompletableFuture<>();
149 if (command.getSendsResponse()) {
150 methodCallbacks.put(
151 id,
152 NamedConsumer.of(
153 command.getMethod(),
154 inputOrException -> {
155 if (inputOrException.isRight()) {
156 try {
157 X value = command.getMapper().apply(inputOrException.right());
158 result.complete(value);
159 } catch (Throwable e) {
160 LOG.log(
161 Level.WARNING,
162 String.format("Unable to map result for %s", command.getMethod()),
163 e);
164 result.completeExceptionally(e);
165 }
166 } else {
167 result.completeExceptionally(inputOrException.left());
168 }
169 }));
170 }
171
172 Map<String, Object> serialized = new LinkedHashMap<>();
173 serialized.put("id", id);
174 serialized.put("method", command.getMethod());
175 serialized.put("params", command.getParams());
176 if (sessionId != null) {
177 serialized.put("sessionId", sessionId);
178 }
179
180 StringBuilder json = new StringBuilder();
181 try (JsonOutput out = JSON.newOutput(json).writeClassName(false)) {
182 out.write(Map.copyOf(serialized));
183 }
184 LOG.log(getDebugLogLevel(), "-> {0}", json);
185 socket.sendText(json);
186
187 if (!command.getSendsResponse()) {
188 // As far as I see, it never happens.
189 // All DevTools commands return something - at least empty map.
190 //noinspection DataFlowIssue
191 result.complete(null);
192 }
193
194 return result;
195 }
196
197 public <X> X sendAndWait(@Nullable SessionID sessionId, Command<X> command, Duration timeout) {
198 try {

Callers 1

sendAndWaitMethod · 0.95

Calls 15

ofMethod · 0.95
rightMethod · 0.80
leftMethod · 0.80
writeClassNameMethod · 0.80
newOutputMethod · 0.80
copyOfMethod · 0.80
getDebugLogLevelMethod · 0.80
sendTextMethod · 0.80
putMethod · 0.65
getMapperMethod · 0.65
logMethod · 0.65
getSendsResponseMethod · 0.45

Tested by

no test coverage detected