blob: ce9a5b69724a665880da22b1677264cdbb10a60d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
package webui.pages;
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
import java.net.URL;
import java.util.List;
import com.microsoft.playwright.Locator;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.options.AriaRole;
import dev.submelon.model.PantryItem;
/**
* Provide locators and methodical tests for the index page of the Pantry application
*/
public class IndexPage extends ApplicationPage {
private static final String INDEX_PAGE_TITLE = "Pantry";
private static final String ADD_ITEM_LABEL = "Add Item";
private static final String ITEM_NAME_LABEL = "Item Name";
private static final String ITEM_DESCRIPTION_LABEL = "Item Description";
private static final String ITEM_QUANTITY_LABEL = "Item Quantity";
private static final String ITEM_QUANTITY_TYPE_LABEL = "Quantity Type";
private static final String SUBMIT_ITEM_LABEL = "Submit Item";
private static final String CANCEL_LABEL = "Cancel";
private static final String PANTRY_TABLE_ROW_SELECTOR = "css=table#tbl-pantry > tbody > tr";
private static final String EMPTY_TABLE_MESSAGE_SELECTOR = "div#tbl-msg-empty";
private static final String EMPTY_TABLE_MESSAGE_TEXT = "Nothing's in the pantry at the moment!";
private static final String ADD_ITEM_NOTIFICATION_HEADER = "Item added successfully";
private static final String ADD_ITEM_NOTIFICATION_TEMPLATE = "Stored \"%s\" in the pantry!";
public IndexPage(Page page) {
super(page);
}
/**
* Navigate to page with table of Pantry Items
*/
public void loadAndVerifyPage(URL location) {
loadAndVerifyPage(location, INDEX_PAGE_TITLE);
}
/**
* Check table is empty with appropriate message
*/
public void checkItemTableIsEmpty() {
Locator td = page.locator(EMPTY_TABLE_MESSAGE_SELECTOR);
assertThat(td).isVisible();
assertThat(td).containsText(EMPTY_TABLE_MESSAGE_TEXT);
}
/**
* Obtain a list of items or rows (`tr`s) in the Pantry Item table
*/
public List<Locator> getCurrentItems(int numExpectedItems) {
if (numExpectedItems == 0) {
checkItemTableIsEmpty();
}
Locator table = page.locator(PANTRY_TABLE_ROW_SELECTOR)
.filter(new Locator.FilterOptions().setHasNotText(EMPTY_TABLE_MESSAGE_TEXT));
assertThat(table).hasCount(numExpectedItems);
return table.all();
}
/**
* Obtain the add item button on the index page
*/
public Locator getAddItemButton() {
return page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(ADD_ITEM_LABEL));
}
/**
* Obtain the item name input in the add item component
*/
public Locator getItemNameInput() {
return page.getByLabel(ITEM_NAME_LABEL);
}
/**
* Obtain the item description input in the add item component
*/
public Locator getItemDescriptionInput() {
return page.getByLabel(ITEM_DESCRIPTION_LABEL);
}
/**
* Obtain the item quantity input in the add item component
*/
public Locator getItemQuantityInput() {
return page.getByLabel(ITEM_QUANTITY_LABEL);
}
/**
* Obtain the item quantity type input in the add item component
*/
public Locator getQuantityTypeInput() {
return page.getByLabel(ITEM_QUANTITY_TYPE_LABEL);
}
/**
* Obtain the submit item button in the add item component
*/
public Locator getSubmitItemButton() {
return page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(SUBMIT_ITEM_LABEL));
}
/**
* Obtain the cancel button in the add item component
*/
public Locator getCancelButton() {
return page.getByRole(AriaRole.BUTTON, new Page.GetByRoleOptions().setName(CANCEL_LABEL));
}
/**
* assert notification is displayed that item has been added
*/
public Locator validateAddItemNotification(final PantryItem item) {
return findAndValidateNotification(ADD_ITEM_NOTIFICATION_HEADER,
String.format(ADD_ITEM_NOTIFICATION_TEMPLATE, item.getName()));
}
}
|