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

Class Storage

java/src/org/openqa/selenium/bidi/module/Storage.java:37–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35import org.openqa.selenium.json.JsonInput;
36
37@Beta
38public class Storage {
39 private static final Json JSON = new Json();
40
41 private final BiDi bidi;
42
43 private static final Function<JsonInput, GetCookiesResult> getCookiesResultMapper =
44 jsonInput -> jsonInput.readNonNull(GetCookiesResult.class);
45
46 private static final Function<JsonInput, PartitionKey> partitionKeyResultMapper =
47 jsonInput -> {
48 Map<String, String> partitionKey = jsonInput.readMapElement("partitionKey");
49 try (StringReader reader = new StringReader(JSON.toJson(partitionKey));
50 JsonInput input = JSON.newInput(reader)) {
51 return input.readNonNull(PartitionKey.class);
52 }
53 };
54
55 public Storage(WebDriver driver) {
56 Require.nonNull("WebDriver", driver);
57
58 if (!(driver instanceof HasBiDi)) {
59 throw new IllegalArgumentException("WebDriver instance must support BiDi protocol");
60 }
61
62 this.bidi = ((HasBiDi) driver).getBiDi();
63 }
64
65 public GetCookiesResult getCookies(GetCookiesParameters params) {
66 return this.bidi.send(
67 new Command<>("storage.getCookies", params.toMap(), getCookiesResultMapper));
68 }
69
70 public PartitionKey setCookie(SetCookieParameters params) {
71 return this.bidi.send(
72 new Command<>("storage.setCookie", params.toMap(), partitionKeyResultMapper));
73 }
74
75 public PartitionKey deleteCookies(DeleteCookiesParameters params) {
76 return this.bidi.send(
77 new Command<>("storage.deleteCookies", params.toMap(), partitionKeyResultMapper));
78 }
79}

Callers

nothing calls this directly

Calls 4

readNonNullMethod · 0.80
readMapElementMethod · 0.80
toJsonMethod · 0.65
newInputMethod · 0.45

Tested by

no test coverage detected