aboutsummaryrefslogtreecommitdiffstats
path: root/testbench-api/src/main/java/com/vaadin/testbench/elements/DateTimeFieldElement.java
diff options
context:
space:
mode:
Diffstat (limited to 'testbench-api/src/main/java/com/vaadin/testbench/elements/DateTimeFieldElement.java')
-rw-r--r--testbench-api/src/main/java/com/vaadin/testbench/elements/DateTimeFieldElement.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/testbench-api/src/main/java/com/vaadin/testbench/elements/DateTimeFieldElement.java b/testbench-api/src/main/java/com/vaadin/testbench/elements/DateTimeFieldElement.java
index 8e6155e33c..2a714d9a33 100644
--- a/testbench-api/src/main/java/com/vaadin/testbench/elements/DateTimeFieldElement.java
+++ b/testbench-api/src/main/java/com/vaadin/testbench/elements/DateTimeFieldElement.java
@@ -15,6 +15,9 @@
*/
package com.vaadin.testbench.elements;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
@@ -63,4 +66,38 @@ public class DateTimeFieldElement extends AbstractDateFieldElement {
findElement(By.tagName("button")).click();
}
+ /**
+ * Sets the value to the given date and time.
+ *
+ * @param value
+ * the date and time to set.
+ */
+ public void setDateTime(LocalDateTime value) {
+ setISOValue(value.format(getISOFormatter()));
+ }
+
+ /**
+ * Gets the value as a LocalDateTime object.
+ *
+ * @return the current value as a date object, or null if a date is not set
+ * or if the text field contains an invalid date
+ */
+ public LocalDateTime getDateTime() {
+ String value = getISOValue();
+ if (value == null) {
+ return null;
+ }
+ return LocalDateTime.parse(value, getISOFormatter());
+ }
+
+ /**
+ * Gets a date and time formatter for ISO-8601.
+ *
+ * @return a date and time formatter for ISO-8601
+ * @since
+ */
+ protected DateTimeFormatter getISOFormatter() {
+ return DateTimeFormatter.ISO_LOCAL_DATE_TIME;
+ }
+
}