Skip to content

Commit 4b08b35

Browse files
committed
Restructure and bump version
1 parent 061e24d commit 4b08b35

File tree

8 files changed

+90
-23
lines changed

8 files changed

+90
-23
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.1.0
2+
* Internal restructuring - new interfaces to deduplicate code
3+
* Added `SimpleImprovedWebElement` which can be for direct instantiation
4+
15
# 1.0.8
26
* Fix `ImprovedRemoteWebElement` not using correct search context
37

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>software.xdev</groupId>
88
<artifactId>selenium-elements-root</artifactId>
9-
<version>1.0.9-SNAPSHOT</version>
9+
<version>1.1.0-SNAPSHOT</version>
1010
<packaging>pom</packaging>
1111

1212
<organization>

selenium-elements/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>software.xdev</groupId>
88
<artifactId>selenium-elements</artifactId>
9-
<version>1.0.9-SNAPSHOT</version>
9+
<version>1.1.0-SNAPSHOT</version>
1010
<packaging>jar</packaging>
1111

1212
<name>selenium-elements</name>

selenium-elements/src/main/java/software/xdev/selenium/elements/CanFindElements.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,32 @@ default <T extends WebElement> T waitForFirst(
8888
final Duration duration)
8989
{
9090
return this.elementProxyCreator().find(
91-
by -> this.waitUntil(
92-
wd -> this.determineSearchContext(wd)
93-
.findElement(additionalAndBy != null ? new ByAnd(by, additionalAndBy) : by),
94-
duration),
91+
by -> {
92+
final By byToUse;
93+
94+
final boolean byPresent = by != null;
95+
final boolean additionalByPresent = additionalAndBy != null;
96+
if(byPresent && additionalByPresent)
97+
{
98+
byToUse = new ByAnd(by, additionalAndBy);
99+
}
100+
else if(byPresent)
101+
{
102+
byToUse = by;
103+
}
104+
else if(additionalByPresent)
105+
{
106+
byToUse = additionalAndBy;
107+
}
108+
else
109+
{
110+
throw new IllegalStateException("No locator that is not null present");
111+
}
112+
113+
return this.waitUntil(
114+
wd -> this.determineSearchContext(wd).findElement(byToUse),
115+
duration);
116+
},
95117
clazz);
96118
}
97119

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright © 2025 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.selenium.elements;
17+
18+
import org.openqa.selenium.SearchContext;
19+
import org.openqa.selenium.WebDriver;
20+
21+
22+
public interface CanFindElementsSelfSearchContext extends SearchContext, CanFindElements
23+
{
24+
@Override
25+
default SearchContext determineSearchContext(final WebDriver webDriver)
26+
{
27+
return this;
28+
}
29+
}

selenium-elements/src/main/java/software/xdev/selenium/elements/ImprovedWebElement.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.stream.IntStream;
2121
import java.util.stream.Stream;
2222

23-
import org.openqa.selenium.SearchContext;
2423
import org.openqa.selenium.WebDriver;
2524
import org.openqa.selenium.WebElement;
2625
import org.openqa.selenium.WrapsElement;
@@ -37,7 +36,7 @@
3736
*
3837
* @apiNote Requires a underlying {@link ImprovedRemoteWebElement}
3938
*/
40-
public interface ImprovedWebElement extends WebElement, CanFindElements, WrapsElement
39+
public interface ImprovedWebElement extends WebElement, CanFindElementsSelfSearchContext, WrapsElement
4140
{
4241
default void performJsClick()
4342
{
@@ -49,12 +48,6 @@ default void nativeClick()
4948
this.getWrappedRemoteElement().nativeClick();
5049
}
5150

52-
@Override
53-
default SearchContext determineSearchContext(final WebDriver webDriver)
54-
{
55-
return this;
56-
}
57-
5851
@Override
5952
default WebDriver getWebDriver()
6053
{
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright © 2025 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.selenium.elements;
17+
18+
/**
19+
* This is a simple implementation of {@link ImprovedWebElement} because the later can't be directly instantiated.
20+
* <p>
21+
* Please note that it has no selectors and an additional selector is required for it to work properly.
22+
* </p>
23+
*/
24+
public abstract class SimpleImprovedWebElement implements ImprovedWebElement
25+
{
26+
}

selenium-elements/src/main/java/software/xdev/selenium/elements/remote/ImprovedRemoteWebElement.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
package software.xdev.selenium.elements.remote;
1717

1818
import org.openqa.selenium.ElementNotInteractableException;
19-
import org.openqa.selenium.SearchContext;
2019
import org.openqa.selenium.WebDriver;
2120
import org.openqa.selenium.remote.RemoteWebElement;
2221
import org.slf4j.Logger;
2322
import org.slf4j.LoggerFactory;
2423

25-
import software.xdev.selenium.elements.CanFindElements;
24+
import software.xdev.selenium.elements.CanFindElementsSelfSearchContext;
2625

2726

2827
/**
@@ -34,7 +33,7 @@
3433
* </ul>
3534
*/
3635
@SuppressWarnings("java:S2160")
37-
public class ImprovedRemoteWebElement extends RemoteWebElement implements CanFindElements
36+
public class ImprovedRemoteWebElement extends RemoteWebElement implements CanFindElementsSelfSearchContext
3837
{
3938
protected Logger logger;
4039
protected final String waitForServerLoadToFinishFunction;
@@ -66,12 +65,6 @@ public WebDriver getWebDriver()
6665
return this.getWrappedDriver();
6766
}
6867

69-
@Override
70-
public SearchContext determineSearchContext(final WebDriver webDriver)
71-
{
72-
return this;
73-
}
74-
7568
@Override
7669
public void click()
7770
{

0 commit comments

Comments
 (0)