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

chore: deprecate getAttribute #1865

Merged
merged 1 commit into from
Feb 7, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ protected void waitForElementVisible(final By by) {
* @return <code>true</code> if matches, <code>false</code> if not
*/
protected boolean hasCssClass(WebElement element, String className) {
String classes = element.getAttribute("class");
String classes = element.getDomAttribute("class");
if (classes == null || classes.isEmpty()) {
return className == null || className.isEmpty();
}
Expand All @@ -338,7 +338,7 @@ protected boolean hasCssClass(WebElement element, String className) {
* the actual element
*/
protected static void assertEquals(WebElement expectedElement,
WebElement actualElement) {
WebElement actualElement) {
WebElement unwrappedExpected = expectedElement;
WebElement unwrappedActual = actualElement;
while (unwrappedExpected instanceof WrapsElement) {
Expand Down Expand Up @@ -528,8 +528,8 @@ private static class LazyDndSimulationLoad {
private static String loadDndScript(String scriptLocation) {
InputStream stream = AbstractBrowserTestBase.class
.getResourceAsStream(scriptLocation);
return IOUtils.readLines(stream, StandardCharsets.UTF_8)
.stream().collect(Collectors.joining("\n"));
return IOUtils.readLines(stream, StandardCharsets.UTF_8).stream()
.collect(Collectors.joining("\n"));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class TestBenchElementTest {
public void testIsEnabled_VaadinComponentDisabled_returnsFalse()
throws Exception {
WebElement webElement = Mockito.mock(WebElement.class);
Mockito.when(webElement.getAttribute("class"))
Mockito.when(webElement.getDomAttribute("class"))
.thenReturn("v-button v-disabled");

TestBenchElement element = TestBenchElement.wrapElement(webElement,
Expand Down Expand Up @@ -116,7 +116,7 @@ private <T> Set<T> set(T... items) {

private TestBenchElement createElementWithClass(String className) {
WebElement webElement = Mockito.mock(WebElement.class);
Mockito.when(webElement.getAttribute("class")).thenReturn(className);
Mockito.when(webElement.getDomAttribute("class")).thenReturn(className);

return TestBenchElement.wrapElement(webElement, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class TestBenchElementTest {
public void testIsEnabled_VaadinComponentDisabled_returnsFalse()
throws Exception {
WebElement webElement = Mockito.mock(WebElement.class);
Mockito.when(webElement.getAttribute("class"))
Mockito.when(webElement.getDomAttribute("class"))
.thenReturn("v-button v-disabled");

TestBenchElement element = TestBenchElement.wrapElement(webElement,
Expand Down Expand Up @@ -115,7 +115,7 @@ private <T> Set<T> set(T... items) {

private TestBenchElement createElementWithClass(String className) {
WebElement webElement = Mockito.mock(WebElement.class);
Mockito.when(webElement.getAttribute("class")).thenReturn(className);
Mockito.when(webElement.getDomAttribute("class")).thenReturn(className);

return TestBenchElement.wrapElement(webElement, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.stream.IntStream;
import java.util.stream.Stream;

import org.jspecify.annotations.Nullable;
import org.openqa.selenium.By;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.Dimension;
Expand Down Expand Up @@ -215,12 +216,34 @@ public String getTagName() {
return wrappedElement.getTagName();
}

/**
* @param name
* The name of the attribute.
* @return The attribute/ property's current value or null if the value is
* not set.
*
* @deprecated This method is deprecated. Use getDomProperty(String) or
* getDomAttribute(String) for more precise attribute retrieval.
*/
@Override
@Deprecated
public String getAttribute(String name) {
waitForVaadin();
return wrappedElement.getAttribute(name);
}

@Override
public @Nullable String getDomAttribute(String name) {
waitForVaadin();
return wrappedElement.getDomAttribute(name);
}

@Override
public @Nullable String getDomProperty(String name) {
waitForVaadin();
return wrappedElement.getDomProperty(name);
}

/**
* Checks if the given attribute is present on the element.
*
Expand Down Expand Up @@ -397,7 +420,7 @@ public Rectangle getRect() {
* @return a set of class names
*/
public Set<String> getClassNames() {
String classAttribute = getAttribute("class");
String classAttribute = getDomAttribute("class");
Set<String> classes = new HashSet<>();
if (classAttribute == null) {
return classes;
Expand Down Expand Up @@ -644,9 +667,7 @@ public Object getProperty(String... propertyNames) {
return Double.parseDouble(str);
}
}
return executeScript(
script + "return value;",
jsParameters);
return executeScript(script + "return value;", jsParameters);
}

private static String createPropertyChain(String[] propertyNames) {
Expand Down