Skip to content

Commit

Permalink
Add hasAttribute helper (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur- authored Jan 29, 2018
1 parent 08e8113 commit 907c179
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ public class ElementQueryView extends Div {

public ElementQueryView() {
for (int i = 0; i < 10; i++) {
add(new Div(new NativeButton("Button " + i)));
NativeButton button = new NativeButton("Button " + i);
add(new Div(button));
if (i == 5) {
button.getElement().setAttribute("boolean", true);
button.getElement().setAttribute("string", "value");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,20 @@ public void waitForNonExistant() {
$(PolymerTemplateViewElement.class).waitForFirst();
Assert.fail("Should not have found an element which does not exist");
}

@Test
public void hasAttribute() {
NativeButtonElement withAttributes = $(NativeButtonElement.class)
.get(5);
NativeButtonElement withoutAttributes = $(NativeButtonElement.class)
.get(6);

Assert.assertTrue(withAttributes.hasAttribute("string"));
Assert.assertTrue(withAttributes.hasAttribute("boolean"));
Assert.assertFalse(withAttributes.hasAttribute("nonexistant"));

Assert.assertFalse(withoutAttributes.hasAttribute("string"));
Assert.assertFalse(withoutAttributes.hasAttribute("boolean"));
Assert.assertFalse(withoutAttributes.hasAttribute("nonexistant"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,18 @@ public String getAttribute(String name) {
return wrappedElement.getAttribute(name);
}

/**
* Checks if the given attribute is present on the element.
*
* @param attribute
* the name of the attribute
* @return <code>true</code> if the attribute is present, <code>false</code>
* otherwise
*/
public boolean hasAttribute(String attribute) {
return (boolean) callFunction("hasAttribute", attribute);
}

@Override
public boolean isSelected() {
autoScrollIntoView();
Expand Down

0 comments on commit 907c179

Please sign in to comment.