11package in .virit .mopo ;
22
3- import com .microsoft .playwright .Locator ;
4- import com .microsoft .playwright .Page ;
53import java .time .LocalDate ;
6- import java .time .format .DateTimeFormatter ;
4+
5+ import com .microsoft .playwright .Locator ;
76
87/**
98 * A helper class to work with vaadin-date-picker component.
109 */
1110public class DatePickerPw {
1211
1312 private final Locator root ;
14- private final Page page ;
15- private String dateFormat ;
1613
17- /**
18- * Creates a DatePicker page object for the specified Page and element ID.
19- *
20- * @param page
21- * The Page to which the date picker belongs.
22- * @param id
23- * The ID of the date picker element.
24- */
25- public DatePickerPw (Page page , String id ) {
26- this .page = page ;
27- this .root = page .locator ("#" + id + " > input" );
28- }
29-
3014 /**
3115 * Creates a DatePicker page object for the given locator.
3216 *
@@ -35,7 +19,6 @@ public DatePickerPw(Page page, String id) {
3519 */
3620 public DatePickerPw (Locator gridLocator ) {
3721 this .root = gridLocator ;
38- this .page = gridLocator .page ();
3922 }
4023
4124 /**
@@ -47,48 +30,27 @@ public DatePickerPw(Locator gridLocator) {
4730 public LocalDate getValue () {
4831 String str = (String ) root .evaluate ("db => db.value" );
4932 try {
50- return LocalDate .parse (str , DateTimeFormatter . ofPattern ( dateFormat ) );
51- } catch (java .time .format .DateTimeParseException e ) {
33+ return LocalDate .parse (str );
34+ } catch (java .time .format .DateTimeParseException e ) {
5235 return null ;
5336 }
5437 }
5538
56- /**
57- * Sets the value of the field.
58- *
59- * @param value
60- * the value to be set
61- */
62- public void setValue (LocalDate value ) {
63- String formattedDate = (dateFormat == null ? value .toString ()
64- : DateTimeFormatter .ofPattern (dateFormat ).format (value ));
65-
66- root .fill (formattedDate );
67- root .press ("Enter" );
68-
69- // Wait for the date picker overlay to be hidden
70- Page .WaitForSelectorOptions options = new Page .WaitForSelectorOptions ();
71- options .setState (options .state .HIDDEN );
72- page .waitForSelector ("vaadin-date-picker-overlay" , options );
73- }
74-
75- /**
76- * Sets the format to be used when setting the date value.
77- *
78- * @param format
79- * The format to be set.
80- */
81- public void setDateFormat (String format ) {
82- dateFormat = format ;
39+ /**
40+ * Sets the value of the field.
41+ *
42+ * @param value the value to be set
43+ */
44+ public void setValue (LocalDate value ) {
45+ root .evaluate ("db => db.value = '%s'" .formatted (value ));
8346 }
8447
85- /**
86- * Returns the raw string value in the field.
87- *
88- * @return the string value as it is formatted in the field. Note, this may
89- * be locale dependent.
90- */
91- public String getInputString () {
48+ /**
49+ * Returns the raw string value in the field.
50+ *
51+ * @return the string value as it is formatted in the field. Note, this may be locale dependent.
52+ */
53+ public String getInputString () {
9254 return root .locator ("input" ).inputValue ();
9355 }
94- }
56+ }
0 commit comments