Skip to content

Commit 0491b03

Browse files
authored
Update to use Selenium 4.24.0 (#146) +semver:feature
Use new FindElements logic from aquality-selenium-core to avoid possible StaleElementReference while iterating WebElements list Add Clear method to ITextBox interface Fix error on clearAndType to close #145
1 parent bad9669 commit 0491b03

File tree

7 files changed

+52
-8
lines changed

7 files changed

+52
-8
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@
8282
<dependency>
8383
<groupId>com.github.aquality-automation</groupId>
8484
<artifactId>aquality-selenium-core</artifactId>
85-
<version>4.0.4</version>
85+
<version>4.1.0</version>
8686
</dependency>
8787
<dependency>
8888
<groupId>org.apache.commons</groupId>
8989
<artifactId>commons-lang3</artifactId>
90-
<version>3.14.0</version>
90+
<version>3.17.0</version>
9191
</dependency>
9292
<dependency>
9393
<groupId>com.fasterxml.jackson.core</groupId>
9494
<artifactId>jackson-databind</artifactId>
95-
<version>2.17.0</version>
95+
<version>2.17.2</version>
9696
</dependency>
9797
<dependency>
9898
<groupId>org.slf4j</groupId>

src/main/java/aquality/selenium/elements/TextBox.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package aquality.selenium.elements;
22

33
import aquality.selenium.core.elements.ElementState;
4+
import aquality.selenium.core.utilities.IElementActionRetrier;
45
import aquality.selenium.elements.interfaces.ITextBox;
56
import org.openqa.selenium.By;
7+
import org.openqa.selenium.JavascriptException;
68
import org.openqa.selenium.Keys;
79

10+
import java.util.ArrayList;
11+
812
/**
913
* The class that describes an input field
1014
*/
@@ -37,6 +41,15 @@ public void clearAndType(final String value) {
3741
clearAndType(value, false);
3842
}
3943

44+
@Override
45+
public void clear() {
46+
logElementAction(LOG_CLEARING);
47+
getJsActions().highlightElement();
48+
doWithRetry(() -> {
49+
getElement().clear();
50+
});
51+
}
52+
4053
@Override
4154
public void clearAndTypeSecret(final String value) {
4255
clearAndType(value, true);
@@ -62,7 +75,16 @@ public void unfocus() {
6275
doWithRetry(() -> getElement().sendKeys(Keys.TAB));
6376
}
6477

65-
private void type(final String value, final boolean maskValueInLog) {
78+
@Override
79+
protected void doWithRetry(Runnable action) {
80+
IElementActionRetrier retrier = getElementActionRetrier();
81+
ArrayList<Class<? extends Throwable>> handledExceptions = new ArrayList<>(retrier.getHandledExceptions());
82+
handledExceptions.add(JavascriptException.class);
83+
retrier.doWithRetry(action, handledExceptions);
84+
}
85+
86+
private void type(final String value, final boolean maskValueInLog)
87+
{
6688
logElementAction(LOG_TYPING, maskValueInLog ? logMaskedValue : value);
6789
getJsActions().highlightElement();
6890
doWithRetry(() -> getElement().sendKeys(value));

src/main/java/aquality/selenium/elements/interfaces/ITextBox.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ public interface ITextBox extends IElement {
1515
*/
1616
void typeSecret(String value);
1717

18+
/**
19+
* Clears element text.
20+
*/
21+
void clear();
22+
1823
/**
1924
* Clears input and enters text in the box, inputted value isn't logging
2025
*

src/test/java/tests/integration/ActionTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import aquality.selenium.elements.interfaces.ILabel;
55
import aquality.selenium.elements.interfaces.ILink;
66
import aquality.selenium.elements.interfaces.ITextBox;
7+
import org.apache.commons.lang3.StringUtils;
78
import org.openqa.selenium.Keys;
89
import org.testng.Assert;
910
import org.testng.annotations.BeforeMethod;
@@ -131,6 +132,22 @@ public void testSetFocus() {
131132
Assert.assertEquals(textBox.getValue(), expectedText, "One character should be removed from " + expectedText);
132133
}
133134

135+
@Test
136+
public void testClear() {
137+
FormAuthenticationForm form = new FormAuthenticationForm();
138+
getBrowser().goTo(form.getUrl());
139+
ITextBox textBox = form.getTxbUsername();
140+
textBox.clear();
141+
Assert.assertTrue(StringUtils.isEmpty(textBox.getValue()), "Clear should work when was initially empty");
142+
textBox.type("anything");
143+
textBox.clear();
144+
Assert.assertTrue(StringUtils.isEmpty(textBox.getValue()), "Clear should work when was not empty");
145+
textBox.type("anything");
146+
textBox.clear();
147+
textBox.clear();
148+
Assert.assertTrue(StringUtils.isEmpty(textBox.getValue()), "Clear should work called twice");
149+
}
150+
134151
@Test
135152
public void testSetValue() {
136153
final String expectedValue = "2";

src/test/java/tests/usecases/devtools/DeviceEmulationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import aquality.selenium.browser.AqualityServices;
44
import aquality.selenium.browser.devtools.EmulationHandling;
55
import com.google.common.collect.ImmutableMap;
6-
import org.openqa.selenium.devtools.v127.emulation.Emulation;
7-
import org.openqa.selenium.devtools.v127.emulation.model.DisplayFeature;
6+
import org.openqa.selenium.devtools.v128.emulation.Emulation;
7+
import org.openqa.selenium.devtools.v128.emulation.model.DisplayFeature;
88
import org.testng.Assert;
99
import org.testng.annotations.BeforeMethod;
1010
import org.testng.annotations.Test;

src/test/java/tests/usecases/devtools/NetworkSpeedEmulationTest.java

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

33
import aquality.selenium.browser.AqualityServices;
44
import org.openqa.selenium.TimeoutException;
5-
import org.openqa.selenium.devtools.v127.network.model.ConnectionType;
5+
import org.openqa.selenium.devtools.v128.network.model.ConnectionType;
66
import org.testng.Assert;
77
import org.testng.annotations.Test;
88
import tests.BaseTest;

src/test/java/tests/usecases/devtools/OverrideUserAgentTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import manytools.BrowserLanguageForm;
99
import manytools.UserAgentForm;
1010
import org.openqa.selenium.devtools.idealized.Network;
11-
import org.openqa.selenium.devtools.v127.emulation.Emulation;
11+
import org.openqa.selenium.devtools.v128.emulation.Emulation;
1212
import org.testng.Assert;
1313
import org.testng.annotations.BeforeMethod;
1414
import org.testng.annotations.Test;

0 commit comments

Comments
 (0)