Skip to content

Commit 10161fc

Browse files
committed
fix: use code from original repo
Use DatePickerPW from original repo to pass DatePickerIT. Use GridPw.getCell() from original repo to pass GridPlaywrightIT.
1 parent 0bb37f6 commit 10161fc

File tree

2 files changed

+34
-68
lines changed

2 files changed

+34
-68
lines changed
Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,16 @@
11
package in.virit.mopo;
22

3-
import com.microsoft.playwright.Locator;
4-
import com.microsoft.playwright.Page;
53
import 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
*/
1110
public 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+
}

src/main/java/in/virit/mopo/GridPw.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package in.virit.mopo;
22

3-
import com.microsoft.playwright.Locator;
4-
import com.microsoft.playwright.Page;
53
import java.util.ArrayList;
64
import java.util.List;
75

6+
import com.microsoft.playwright.Locator;
7+
import com.microsoft.playwright.Page;
8+
89
/**
910
* A helper class to work with the vaadin-grid component.
1011
*/
@@ -204,18 +205,21 @@ private RowPw(int rowIndex) {
204205
* @return the cell locator
205206
*/
206207
public Locator getCell(int cellIndex) {
207-
int indexInVirtualTable = (Integer) root.evaluate(
208-
"g => g._getRenderedRows().indexOf(g._getRenderedRows().filter(r => r.index == %s)[0]);"
209-
.formatted(rowIndex));
210-
indexInVirtualTable += 1; // 1-based :-)
211-
String name = root
212-
.locator("#items tr:nth-child(%s) td:nth-child(%s) slot"
213-
.formatted(indexInVirtualTable, cellIndex + 1))
214-
.getAttribute("name");
215-
return root.locator(
216-
"vaadin-grid-cell-content[slot='%s']".formatted(name));
208+
int indexInVirtualTable =
209+
(Integer)
210+
root.evaluate(
211+
"g => g._getRenderedRows().indexOf(g._getRenderedRows().filter(r => r.index == %s)[0]);"
212+
.formatted(rowIndex));
213+
Locator row =
214+
root.locator("#items tr")
215+
.filter(new Locator.FilterOptions().setVisible(true))
216+
.nth(indexInVirtualTable);
217+
String name =
218+
row.locator("td:nth-child(%s) slot".formatted(cellIndex + 1)).getAttribute("name");
219+
return root.locator("vaadin-grid-cell-content[slot='%s']".formatted(name));
217220
}
218221

222+
219223
/**
220224
* Gets the cell with the given header text.
221225
*

0 commit comments

Comments
 (0)