Skip to content

Commit

Permalink
[bidi][java] Add methods to allow all parameters for script callFunct…
Browse files Browse the repository at this point in the history
…ion and evaluate method
  • Loading branch information
pujagani committed Apr 25, 2024
1 parent 3e3cf89 commit ef0551b
Show file tree
Hide file tree
Showing 8 changed files with 906 additions and 11 deletions.
22 changes: 11 additions & 11 deletions java/src/org/openqa/selenium/bidi/module/Script.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,7 @@
import org.openqa.selenium.bidi.Command;
import org.openqa.selenium.bidi.Event;
import org.openqa.selenium.bidi.HasBiDi;
import org.openqa.selenium.bidi.script.ChannelValue;
import org.openqa.selenium.bidi.script.EvaluateResult;
import org.openqa.selenium.bidi.script.EvaluateResultExceptionValue;
import org.openqa.selenium.bidi.script.EvaluateResultSuccess;
import org.openqa.selenium.bidi.script.ExceptionDetails;
import org.openqa.selenium.bidi.script.LocalValue;
import org.openqa.selenium.bidi.script.Message;
import org.openqa.selenium.bidi.script.RealmInfo;
import org.openqa.selenium.bidi.script.RealmType;
import org.openqa.selenium.bidi.script.RemoteValue;
import org.openqa.selenium.bidi.script.ResultOwnership;
import org.openqa.selenium.bidi.script.*;
import org.openqa.selenium.internal.Require;
import org.openqa.selenium.json.Json;
import org.openqa.selenium.json.JsonInput;
Expand Down Expand Up @@ -118,6 +108,11 @@ public Script(Set<String> browsingContextIds, WebDriver driver) {
this.browsingContextIds = browsingContextIds;
}

public EvaluateResult callFunction(CallFunctionParameters parameters) {
return this.bidi.send(
new Command<>("script.callFunction", parameters.toMap(), evaluateResultMapper));
}

public EvaluateResult callFunctionInRealm(
String realmId,
String functionDeclaration,
Expand Down Expand Up @@ -179,6 +174,11 @@ public EvaluateResult callFunctionInBrowsingContext(
return this.bidi.send(new Command<>("script.callFunction", params, evaluateResultMapper));
}

public EvaluateResult evaluateFunction(EvaluateParameters parameters) {
return this.bidi.send(
new Command<>("script.evaluate", parameters.toMap(), evaluateResultMapper));
}

public EvaluateResult evaluateFunctionInRealm(
String realmId,
String expression,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.bidi.script;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CallFunctionParameters {

private final Map<String, Object> map = new HashMap<>();

public CallFunctionParameters(Target target, String functionDeclaration, boolean awaitPromise) {
map.put("target", target.toMap());
map.put("functionDeclaration", functionDeclaration);
map.put("awaitPromise", awaitPromise);
}

public CallFunctionParameters arguments(List<LocalValue> arguments) {
map.put("arguments", arguments);
return this;
}

public CallFunctionParameters resultOwnership(ResultOwnership ownership) {
map.put("resultOwnership", ownership.toString());
return this;
}

public CallFunctionParameters serializationOptions(SerializationOptions serializationOptions) {
map.put("serializationOptions", serializationOptions.toJson());
return this;
}

public CallFunctionParameters thisParameter(LocalValue localValue) {
map.put("this", localValue.toJson());
return this;
}

public CallFunctionParameters userActivation(boolean userActivation) {
map.put("userActivation", userActivation);
return this;
}

public Map<String, Object> toMap() {
return map;
}
}
29 changes: 29 additions & 0 deletions java/src/org/openqa/selenium/bidi/script/ContextTarget.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.bidi.script;

public class ContextTarget extends Target {
public ContextTarget(String id) {
super.map.put("context", id);
}

public ContextTarget(String id, String sandbox) {
super.map.put("context", id);
super.map.put("sandbox", sandbox);
}
}
51 changes: 51 additions & 0 deletions java/src/org/openqa/selenium/bidi/script/EvaluateParameters.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.bidi.script;

import java.util.HashMap;
import java.util.Map;

public class EvaluateParameters {

private final Map<String, Object> map = new HashMap<>();

public EvaluateParameters(Target target, String expression, boolean awaitPromise) {
map.put("target", target.toMap());
map.put("expression", expression);
map.put("awaitPromise", awaitPromise);
}

public EvaluateParameters resultOwnership(ResultOwnership ownership) {
map.put("resultOwnership", ownership.toString());
return this;
}

public EvaluateParameters serializationOptions(SerializationOptions serializationOptions) {
map.put("serializationOptions", serializationOptions.toJson());
return this;
}

public EvaluateParameters userActivation(boolean userActivation) {
map.put("userActivation", userActivation);
return this;
}

public Map<String, Object> toMap() {
return map;
}
}
25 changes: 25 additions & 0 deletions java/src/org/openqa/selenium/bidi/script/RealmTarget.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.bidi.script;

public class RealmTarget extends Target {

public RealmTarget(String id) {
super.map.put("realm", id);
}
}
29 changes: 29 additions & 0 deletions java/src/org/openqa/selenium/bidi/script/Target.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the Software Freedom Conservancy (SFC) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The SFC licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.openqa.selenium.bidi.script;

import java.util.HashMap;
import java.util.Map;

public abstract class Target {
protected final Map<String, Object> map = new HashMap<>();

public Map<String, Object> toMap() {
return this.map;
}
}

0 comments on commit ef0551b

Please sign in to comment.