Skip to content

Commit

Permalink
[bidi][java] Add missing code example for Script module
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani committed Feb 23, 2024
1 parent 4b3e644 commit e24abbe
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.selenium.bidirectional.webdriver_bidi;

import dev.selenium.BaseTest;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
Expand All @@ -24,6 +26,7 @@
import org.openqa.selenium.bidi.script.EvaluateResultExceptionValue;
import org.openqa.selenium.bidi.script.EvaluateResultSuccess;
import org.openqa.selenium.bidi.script.LocalValue;
import org.openqa.selenium.bidi.script.PrimitiveProtocolValue;
import org.openqa.selenium.bidi.script.RealmInfo;
import org.openqa.selenium.bidi.script.RealmType;
import org.openqa.selenium.bidi.script.RemoteReference;
Expand Down Expand Up @@ -52,6 +55,30 @@ void canCallFunctionWithDeclaration() {
}
}

@Test
void canCallFunctionWithArguments() {
String id = driver.getWindowHandle();
try (Script script = new Script(id, driver)) {
List<LocalValue> arguments = new ArrayList<>();
LocalValue value1 = PrimitiveProtocolValue.stringValue("ARGUMENT_STRING_VALUE");
LocalValue value2 = PrimitiveProtocolValue.numberValue(42);
arguments.add(value1);
arguments.add(value2);

EvaluateResult result =
script.callFunctionInBrowsingContext(
id,
"(...args)=>{return args}",
false,
Optional.of(arguments),
Optional.empty(),
Optional.empty());

EvaluateResultSuccess successResult = (EvaluateResultSuccess) result;
Assertions.assertEquals(2, ((List<Object>) successResult.getResult().getValue().get()).size());
}
}

@Test
void canCallFunctionWithAwaitPromise() {
String id = driver.getWindowHandle();
Expand Down

0 comments on commit e24abbe

Please sign in to comment.