Skip to content

Commit

Permalink
[bidi][java] Deprecate using builder for Locate Node parameters. (#13767
Browse files Browse the repository at this point in the history
)
  • Loading branch information
pujagani committed Apr 3, 2024
1 parent 911b312 commit 309b3e8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
public class LocateNodeParameters {

private final Locator locator;
private final Optional<Long> maxNodeCount;
private final Optional<ResultOwnership> ownership;
private final Optional<String> sandbox;
private final Optional<SerializationOptions> serializationOptions;
private final Optional<List<RemoteReference>> startNodes;
private Optional<Long> maxNodeCount = Optional.empty();
private Optional<ResultOwnership> ownership = Optional.empty();
private Optional<String> sandbox = Optional.empty();
private Optional<SerializationOptions> serializationOptions = Optional.empty();
private Optional<List<RemoteReference>> startNodes = Optional.empty();

private LocateNodeParameters(Builder builder) {
this.locator = builder.locator;
Expand All @@ -44,6 +44,35 @@ private LocateNodeParameters(Builder builder) {
this.startNodes = Optional.ofNullable(builder.startNodes);
}

public LocateNodeParameters(Locator locator) {
this.locator = locator;
}

public LocateNodeParameters setMaxNodeCount(long maxNodeCount) {
this.maxNodeCount = Optional.of(maxNodeCount);
return this;
}

public LocateNodeParameters setOwnership(ResultOwnership ownership) {
this.ownership = Optional.of(ownership);
return this;
}

public LocateNodeParameters setSandbox(String sandbox) {
this.sandbox = Optional.of(sandbox);
return this;
}

public LocateNodeParameters setSerializationOptions(SerializationOptions options) {
this.serializationOptions = Optional.of(options);
return this;
}

public LocateNodeParameters setStartNodes(List<RemoteReference> startNodes) {
this.startNodes = Optional.of(startNodes);
return this;
}

public Map<String, Object> toMap() {
final Map<String, Object> map = new HashMap<>();

Expand All @@ -62,6 +91,12 @@ public Map<String, Object> toMap() {
return map;
}

/**
* @deprecated Use the chaining of LocateNodeParameters methods to add optional parameters. This
* is in favor of keeping the usage pattern consistent for BiDi parameters. Use the {@link
* LocateNodeParameters#LocateNodeParameters(Locator locator)} constructor and chain methods.
*/
@Deprecated(since = "4.20", forRemoval = true)
public static class Builder {

private final Locator locator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void canLocateNodes() {

driver.get(pages.xhtmlTestPage);

LocateNodeParameters parameters = new LocateNodeParameters.Builder(Locator.css("div")).build();
LocateNodeParameters parameters = new LocateNodeParameters(Locator.css("div"));

List<RemoteValue> elements = browsingContext.locateNodes(parameters);
assertThat(elements.size()).isEqualTo(13);
Expand Down Expand Up @@ -113,9 +113,7 @@ void canLocateNodesWithCSSLocator() {
driver.get(pages.xhtmlTestPage);

LocateNodeParameters parameters =
new LocateNodeParameters.Builder(Locator.css("div.extraDiv, div.content"))
.setMaxNodeCount(1)
.build();
new LocateNodeParameters(Locator.css("div.extraDiv, div.content")).setMaxNodeCount(1);

List<RemoteValue> elements = browsingContext.locateNodes(parameters);
assertThat(elements.size()).isGreaterThanOrEqualTo(1);
Expand All @@ -141,9 +139,7 @@ void canLocateNodesWithXPathLocator() {
driver.get(pages.xhtmlTestPage);

LocateNodeParameters parameters =
new LocateNodeParameters.Builder(Locator.xpath("/html/body/div[2]"))
.setMaxNodeCount(1)
.build();
new LocateNodeParameters(Locator.xpath("/html/body/div[2]")).setMaxNodeCount(1);

List<RemoteValue> elements = browsingContext.locateNodes(parameters);
assertThat(elements.size()).isGreaterThanOrEqualTo(1);
Expand All @@ -170,9 +166,7 @@ void canLocateNodesWithInnerText() {
driver.get(pages.xhtmlTestPage);

LocateNodeParameters parameters =
new LocateNodeParameters.Builder(Locator.innerText("Spaced out"))
.setMaxNodeCount(1)
.build();
new LocateNodeParameters(Locator.innerText("Spaced out")).setMaxNodeCount(1);

List<RemoteValue> elements = browsingContext.locateNodes(parameters);
assertThat(elements.size()).isGreaterThanOrEqualTo(1);
Expand All @@ -194,7 +188,7 @@ void canLocateNodesWithMaxNodeCount() {
driver.get(pages.xhtmlTestPage);

LocateNodeParameters parameters =
new LocateNodeParameters.Builder(Locator.css("div")).setMaxNodeCount(4).build();
new LocateNodeParameters(Locator.css("div")).setMaxNodeCount(4);

List<RemoteValue> elements = browsingContext.locateNodes(parameters);
assertThat(elements.size()).isEqualTo(4);
Expand All @@ -212,9 +206,7 @@ void canLocateNodesWithNoneOwnershipParameter() {
driver.get(pages.xhtmlTestPage);

LocateNodeParameters parameters =
new LocateNodeParameters.Builder(Locator.css("div"))
.setOwnership(ResultOwnership.NONE)
.build();
new LocateNodeParameters(Locator.css("div")).setOwnership(ResultOwnership.NONE);

List<RemoteValue> elements = browsingContext.locateNodes(parameters);
assertThat(elements.size()).isEqualTo(13);
Expand All @@ -233,9 +225,7 @@ void canLocateNodesWithRootOwnershipParameter() {
driver.get(pages.xhtmlTestPage);

LocateNodeParameters parameters =
new LocateNodeParameters.Builder(Locator.css("div"))
.setOwnership(ResultOwnership.ROOT)
.build();
new LocateNodeParameters(Locator.css("div")).setOwnership(ResultOwnership.ROOT);

List<RemoteValue> elements = browsingContext.locateNodes(parameters);
assertThat(elements.size()).isEqualTo(13);
Expand Down Expand Up @@ -276,10 +266,9 @@ void canLocateNodesGivenStartNodes() {
new RemoteReference(RemoteReference.Type.SHARED_ID, value.getSharedId().get())));

LocateNodeParameters parameters =
new LocateNodeParameters.Builder(Locator.css("input"))
new LocateNodeParameters(Locator.css("input"))
.setStartNodes(startNodes)
.setMaxNodeCount(50)
.build();
.setMaxNodeCount(50);

List<RemoteValue> elements = browsingContext.locateNodes(parameters);
assertThat(elements.size()).isEqualTo(35);
Expand All @@ -298,10 +287,7 @@ void canLocateNodesInAGivenSandbox() {
browsingContext.navigate(pages.xhtmlTestPage, ReadinessState.COMPLETE);

LocateNodeParameters parameters =
new LocateNodeParameters.Builder(Locator.css("div"))
.setSandbox(sandbox)
.setMaxNodeCount(1)
.build();
new LocateNodeParameters(Locator.css("div")).setSandbox(sandbox).setMaxNodeCount(1);

List<RemoteValue> elements = browsingContext.locateNodes(parameters);
assertThat(elements.size()).isEqualTo(1);
Expand Down

0 comments on commit 309b3e8

Please sign in to comment.