-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bidi][java] Add locate nodes command
- Loading branch information
Showing
5 changed files
with
551 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
java/src/org/openqa/selenium/bidi/browsingcontext/LocateNodeParameters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// 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.browsingcontext; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import org.openqa.selenium.bidi.script.RemoteReference; | ||
import org.openqa.selenium.bidi.script.ResultOwnership; | ||
import org.openqa.selenium.bidi.script.SerializationOptions; | ||
|
||
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 LocateNodeParameters(Builder builder) { | ||
this.locator = builder.locator; | ||
this.maxNodeCount = Optional.ofNullable(builder.maxNodeCount); | ||
this.ownership = Optional.ofNullable(builder.ownership); | ||
this.sandbox = Optional.ofNullable(builder.sandbox); | ||
this.serializationOptions = Optional.ofNullable(builder.serializationOptions); | ||
this.startNodes = Optional.ofNullable(builder.startNodes); | ||
} | ||
|
||
public Map<String, Object> toMap() { | ||
final Map<String, Object> map = new HashMap<>(); | ||
|
||
map.put("locator", locator.toMap()); | ||
maxNodeCount.ifPresent(value -> map.put("maxNodeCount", value)); | ||
ownership.ifPresent(value -> map.put("ownership", value.toString())); | ||
sandbox.ifPresent(value -> map.put("sandbox", value)); | ||
serializationOptions.ifPresent(value -> map.put("serializationOptions", value.toJson())); | ||
startNodes.ifPresent( | ||
value -> { | ||
List<Map<String, Object>> startNodesJson = new ArrayList<>(); | ||
value.forEach(remoteNode -> startNodesJson.add(remoteNode.toJson())); | ||
map.put("startNodes", startNodesJson); | ||
}); | ||
|
||
return map; | ||
} | ||
|
||
public static class Builder { | ||
|
||
private final Locator locator; | ||
private Long maxNodeCount = null; | ||
private ResultOwnership ownership; | ||
private String sandbox; | ||
private SerializationOptions serializationOptions; | ||
private List<RemoteReference> startNodes; | ||
|
||
public Builder(Locator locator) { | ||
this.locator = locator; | ||
} | ||
|
||
public Builder setMaxNodeCount(long maxNodeCount) { | ||
this.maxNodeCount = maxNodeCount; | ||
return this; | ||
} | ||
|
||
public Builder setOwnership(ResultOwnership ownership) { | ||
this.ownership = ownership; | ||
return this; | ||
} | ||
|
||
public Builder setSandbox(String sandbox) { | ||
this.sandbox = sandbox; | ||
return this; | ||
} | ||
|
||
public Builder setSerializationOptions(SerializationOptions options) { | ||
this.serializationOptions = options; | ||
return this; | ||
} | ||
|
||
public Builder setStartNodes(List<RemoteReference> startNodes) { | ||
this.startNodes = startNodes; | ||
return this; | ||
} | ||
|
||
public LocateNodeParameters build() { | ||
return new LocateNodeParameters(this); | ||
} | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
java/src/org/openqa/selenium/bidi/browsingcontext/Locator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// 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.browsingcontext; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public class Locator { | ||
private enum Type { | ||
CSS("css"), | ||
INNER("innerText"), | ||
XPATH("xpath"); | ||
|
||
private final String value; | ||
|
||
Type(String value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return value; | ||
} | ||
} | ||
|
||
private final Type type; | ||
|
||
private final String value; | ||
|
||
private Optional<Boolean> ignoreCase = Optional.empty(); | ||
|
||
private Optional<String> matchType = Optional.empty(); | ||
|
||
private Optional<Long> maxDepth = Optional.empty(); | ||
|
||
private Locator(Type type, String value) { | ||
this.type = type; | ||
this.value = value; | ||
} | ||
|
||
public Locator( | ||
Type type, | ||
String value, | ||
Optional<Boolean> ignoreCase, | ||
Optional<String> matchType, | ||
Optional<Long> maxDepth) { | ||
this.type = type; | ||
this.value = value; | ||
this.ignoreCase = ignoreCase; | ||
this.matchType = matchType; | ||
this.maxDepth = maxDepth; | ||
} | ||
|
||
public static Locator css(String value) { | ||
return new Locator(Type.CSS, value); | ||
} | ||
|
||
public static Locator innerText( | ||
String value, | ||
Optional<Boolean> ignoreCase, | ||
Optional<String> matchType, | ||
Optional<Long> maxDepth) { | ||
return new Locator(Type.INNER, value, ignoreCase, matchType, maxDepth); | ||
} | ||
|
||
public static Locator innerText(String value) { | ||
return new Locator(Type.INNER, value); | ||
} | ||
|
||
public static Locator xpath(String value) { | ||
return new Locator(Type.XPATH, value); | ||
} | ||
|
||
public Map<String, Object> toMap() { | ||
final Map<String, Object> map = new HashMap<>(); | ||
map.put("type", type.toString()); | ||
map.put("value", value); | ||
|
||
ignoreCase.ifPresent(val -> map.put("ignoreCase", val)); | ||
matchType.ifPresent(val -> map.put("matchType", val)); | ||
maxDepth.ifPresent(val -> map.put("maxDepth", val)); | ||
|
||
return map; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.