Skip to content

Commit ffb03bd

Browse files
authored
[bidi][java] Add methods to allow all parameters for script callFunction and evaluate method (#13873)
1 parent 7f25fd1 commit ffb03bd

File tree

8 files changed

+908
-11
lines changed

8 files changed

+908
-11
lines changed

java/src/org/openqa/selenium/bidi/module/Script.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,7 @@
3333
import org.openqa.selenium.bidi.Command;
3434
import org.openqa.selenium.bidi.Event;
3535
import org.openqa.selenium.bidi.HasBiDi;
36-
import org.openqa.selenium.bidi.script.ChannelValue;
37-
import org.openqa.selenium.bidi.script.EvaluateResult;
38-
import org.openqa.selenium.bidi.script.EvaluateResultExceptionValue;
39-
import org.openqa.selenium.bidi.script.EvaluateResultSuccess;
40-
import org.openqa.selenium.bidi.script.ExceptionDetails;
41-
import org.openqa.selenium.bidi.script.LocalValue;
42-
import org.openqa.selenium.bidi.script.Message;
43-
import org.openqa.selenium.bidi.script.RealmInfo;
44-
import org.openqa.selenium.bidi.script.RealmType;
45-
import org.openqa.selenium.bidi.script.RemoteValue;
46-
import org.openqa.selenium.bidi.script.ResultOwnership;
36+
import org.openqa.selenium.bidi.script.*;
4737
import org.openqa.selenium.internal.Require;
4838
import org.openqa.selenium.json.Json;
4939
import org.openqa.selenium.json.JsonInput;
@@ -118,6 +108,11 @@ public Script(Set<String> browsingContextIds, WebDriver driver) {
118108
this.browsingContextIds = browsingContextIds;
119109
}
120110

111+
public EvaluateResult callFunction(CallFunctionParameters parameters) {
112+
return this.bidi.send(
113+
new Command<>("script.callFunction", parameters.toMap(), evaluateResultMapper));
114+
}
115+
121116
public EvaluateResult callFunctionInRealm(
122117
String realmId,
123118
String functionDeclaration,
@@ -179,6 +174,11 @@ public EvaluateResult callFunctionInBrowsingContext(
179174
return this.bidi.send(new Command<>("script.callFunction", params, evaluateResultMapper));
180175
}
181176

177+
public EvaluateResult evaluateFunction(EvaluateParameters parameters) {
178+
return this.bidi.send(
179+
new Command<>("script.evaluate", parameters.toMap(), evaluateResultMapper));
180+
}
181+
182182
public EvaluateResult evaluateFunctionInRealm(
183183
String realmId,
184184
String expression,
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.bidi.script;
19+
20+
import java.util.HashMap;
21+
import java.util.List;
22+
import java.util.Map;
23+
24+
public class CallFunctionParameters {
25+
26+
private final Map<String, Object> map = new HashMap<>();
27+
28+
public CallFunctionParameters(Target target, String functionDeclaration, boolean awaitPromise) {
29+
map.put("target", target.toMap());
30+
map.put("functionDeclaration", functionDeclaration);
31+
map.put("awaitPromise", awaitPromise);
32+
}
33+
34+
public CallFunctionParameters arguments(List<LocalValue> arguments) {
35+
map.put("arguments", arguments);
36+
return this;
37+
}
38+
39+
public CallFunctionParameters resultOwnership(ResultOwnership ownership) {
40+
map.put("resultOwnership", ownership.toString());
41+
return this;
42+
}
43+
44+
public CallFunctionParameters serializationOptions(SerializationOptions serializationOptions) {
45+
map.put("serializationOptions", serializationOptions.toJson());
46+
return this;
47+
}
48+
49+
public CallFunctionParameters thisParameter(LocalValue localValue) {
50+
map.put("this", localValue.toJson());
51+
return this;
52+
}
53+
54+
public CallFunctionParameters userActivation(boolean userActivation) {
55+
map.put("userActivation", userActivation);
56+
return this;
57+
}
58+
59+
public Map<String, Object> toMap() {
60+
return map;
61+
}
62+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.bidi.script;
19+
20+
public class ContextTarget extends Target {
21+
public ContextTarget(String id) {
22+
super.map.put("context", id);
23+
}
24+
25+
public ContextTarget(String id, String sandbox) {
26+
super.map.put("context", id);
27+
super.map.put("sandbox", sandbox);
28+
}
29+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.bidi.script;
19+
20+
import java.util.HashMap;
21+
import java.util.Map;
22+
23+
public class EvaluateParameters {
24+
25+
private final Map<String, Object> map = new HashMap<>();
26+
27+
public EvaluateParameters(Target target, String expression, boolean awaitPromise) {
28+
map.put("target", target.toMap());
29+
map.put("expression", expression);
30+
map.put("awaitPromise", awaitPromise);
31+
}
32+
33+
public EvaluateParameters resultOwnership(ResultOwnership ownership) {
34+
map.put("resultOwnership", ownership.toString());
35+
return this;
36+
}
37+
38+
public EvaluateParameters serializationOptions(SerializationOptions serializationOptions) {
39+
map.put("serializationOptions", serializationOptions.toJson());
40+
return this;
41+
}
42+
43+
public EvaluateParameters userActivation(boolean userActivation) {
44+
map.put("userActivation", userActivation);
45+
return this;
46+
}
47+
48+
public Map<String, Object> toMap() {
49+
return map;
50+
}
51+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.bidi.script;
19+
20+
public class RealmTarget extends Target {
21+
22+
public RealmTarget(String id) {
23+
super.map.put("realm", id);
24+
}
25+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.openqa.selenium.bidi.script;
19+
20+
import java.util.HashMap;
21+
import java.util.Map;
22+
23+
public abstract class Target {
24+
protected final Map<String, Object> map = new HashMap<>();
25+
26+
public Map<String, Object> toMap() {
27+
return this.map;
28+
}
29+
}

0 commit comments

Comments
 (0)