Skip to content

Commit b149e9a

Browse files
authored
refactor!: make setInputValue simulate real user input (#3576)
1 parent d01fb77 commit b149e9a

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

  • vaadin-date-picker-flow-parent/vaadin-date-picker-testbench/src/main/java/com/vaadin/flow/component/datepicker/testbench

‎vaadin-date-picker-flow-parent/vaadin-date-picker-testbench/src/main/java/com/vaadin/flow/component/datepicker/testbench/DatePickerElement.java‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.stream.Collectors;
2727

2828
import org.openqa.selenium.By;
29+
import org.openqa.selenium.Keys;
2930

3031
/**
3132
* A TestBench element representing a <code>&lt;vaadin-date-picker&gt;</code>
@@ -154,14 +155,17 @@ protected String getValue() {
154155
}
155156

156157
/**
157-
* Opens the overlay, sets the value to the inner input element as a string
158-
* and closes the overlay. This simulates the user typing into the input and
159-
* triggering an update of the value property.
158+
* Simulates the user selecting a date via the input element. This
159+
* effectively clears the input element with a key shortcut, then types the
160+
* given date string and finally presses {@code Enter} to commit the new
161+
* date.
162+
*
163+
* @param value
164+
* the date string to enter.
160165
*/
161166
public void setInputValue(String value) {
162-
this.open();
163-
setProperty("_inputValue", value);
164-
this.close();
167+
sendKeys(Keys.chord(Keys.SHIFT, Keys.HOME), Keys.BACK_SPACE);
168+
sendKeys(value, Keys.ENTER);
165169
}
166170

167171
/**
@@ -171,7 +175,8 @@ public void setInputValue(String value) {
171175
* @return
172176
*/
173177
public String getInputValue() {
174-
return getPropertyString("_inputValue");
178+
TestBenchElement input = $("input").first();
179+
return input.getPropertyString("value");
175180
}
176181

177182
/**

0 commit comments

Comments
 (0)