Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bidi][java] Deprecate using builder for Locate Node parameters. #13767

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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