Skip to content

Commit 164bf79

Browse files
committed
[bidi][java] Remove the method that converts node value to RemoteWebElement
Adding dependency on "remote" in build file is causing circular dependency. Tried a few approaches but could not find a feasible solution. Also, this part can be added in the BiDiDelegator in the future when we port the findElement method.
1 parent e8745c6 commit 164bf79

File tree

3 files changed

+1
-52
lines changed

3 files changed

+1
-52
lines changed

java/src/org/openqa/selenium/bidi/browsingcontext/BUILD.bazel

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ java_library(
2020
"//java/src/org/openqa/selenium/bidi",
2121
"//java/src/org/openqa/selenium/bidi/script",
2222
"//java/src/org/openqa/selenium/json",
23-
"//java/src/org/openqa/selenium/remote:api",
2423
"//java/src/org/openqa/selenium/remote/http",
2524
artifact("com.google.auto.service:auto-service-annotations"),
2625
],

java/src/org/openqa/selenium/bidi/browsingcontext/BrowsingContext.java

-38
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
import java.util.List;
2525
import java.util.Map;
2626
import java.util.function.Function;
27-
import java.util.stream.Collectors;
2827
import org.openqa.selenium.WebDriver;
29-
import org.openqa.selenium.WebElement;
3028
import org.openqa.selenium.WindowType;
3129
import org.openqa.selenium.bidi.BiDi;
3230
import org.openqa.selenium.bidi.Command;
@@ -37,8 +35,6 @@
3735
import org.openqa.selenium.json.JsonInput;
3836
import org.openqa.selenium.json.TypeToken;
3937
import org.openqa.selenium.print.PrintOptions;
40-
import org.openqa.selenium.remote.RemoteWebDriver;
41-
import org.openqa.selenium.remote.RemoteWebElement;
4238

4339
public class BrowsingContext {
4440

@@ -415,44 +411,10 @@ public RemoteValue locateNode(Locator locator) {
415411
return remoteValues.get(0);
416412
}
417413

418-
public WebElement locateElement(Locator locator) {
419-
List<RemoteValue> remoteValues =
420-
this.bidi.send(
421-
new Command<>(
422-
"browsingContext.locateNodes",
423-
Map.of("context", id, "locator", locator.toMap(), "maxNodeCount", 1),
424-
jsonInput -> {
425-
Map<String, Object> result = jsonInput.read(Map.class);
426-
try (StringReader reader = new StringReader(JSON.toJson(result.get("nodes")));
427-
JsonInput input = JSON.newInput(reader)) {
428-
return input.read(new TypeToken<List<RemoteValue>>() {}.getType());
429-
}
430-
}));
431-
432-
List<WebElement> elements = nodeRemoteValueToWebElementConverter(remoteValues);
433-
return elements.get(0);
434-
}
435-
436414
public void close() {
437415
// This might need more clean up actions once the behavior is defined.
438416
// Specially when last tab or window is closed.
439417
// Refer: https://github.com/w3c/webdriver-bidi/issues/187
440418
this.bidi.send(new Command<>("browsingContext.close", Map.of(CONTEXT, id)));
441419
}
442-
443-
private List<WebElement> nodeRemoteValueToWebElementConverter(List<RemoteValue> remoteValues) {
444-
return remoteValues.stream()
445-
.map(
446-
remoteValue -> {
447-
WebElement element = new RemoteWebElement();
448-
((RemoteWebElement) element).setParent(((RemoteWebDriver) this.driver));
449-
((RemoteWebElement) element)
450-
.setFileDetector(((RemoteWebDriver) this.driver).getFileDetector());
451-
remoteValue
452-
.getSharedId()
453-
.ifPresent(sharedId -> ((RemoteWebElement) element).setId(sharedId));
454-
return element;
455-
})
456-
.collect(Collectors.toList());
457-
}
458420
}

java/test/org/openqa/selenium/bidi/browsingcontext/LocateNodesTest.java

+1-13
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.junit.jupiter.api.AfterEach;
2828
import org.junit.jupiter.api.BeforeEach;
2929
import org.junit.jupiter.api.Test;
30-
import org.openqa.selenium.WebElement;
3130
import org.openqa.selenium.bidi.module.Script;
3231
import org.openqa.selenium.bidi.script.EvaluateResult;
3332
import org.openqa.selenium.bidi.script.EvaluateResultSuccess;
@@ -243,18 +242,7 @@ void canLocateNodesInAGivenSandbox() {
243242

244243
String sharedId = (String) ((RemoteValue) sharedIdMap.get("sharedId")).getValue().get();
245244
assertThat(sharedId).isEqualTo(nodeId);
246-
}
247-
248-
@Test
249-
void canFindElement() {
250-
BrowsingContext browsingContext = new BrowsingContext(driver, driver.getWindowHandle());
251-
assertThat(browsingContext.getId()).isNotEmpty();
252-
253-
driver.get(pages.xhtmlTestPage);
254-
255-
WebElement element = browsingContext.locateElement(Locator.css("p"));
256-
assertThat(element.getText()).isEqualTo("Open new window");
257-
}
245+
}
258246

259247
@AfterEach
260248
public void quitDriver() {

0 commit comments

Comments
 (0)