Skip to content

Commit 3ccb965

Browse files
committed
Add UIB features examples to servicenow module
1 parent 91662a0 commit 3ccb965

File tree

26 files changed

+348
-129
lines changed

26 files changed

+348
-129
lines changed

bellatrix.servicenow/src/main/java/solutions/bellatrix/servicenow/components/uiBuilder/RecordCheckbox.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package solutions.bellatrix.servicenow.components.uiBuilder;
2+
import solutions.bellatrix.servicenow.components.enums.UibComponentType;
23
import solutions.bellatrix.web.components.*;
34
import solutions.bellatrix.web.components.contracts.ComponentDisabled;
45

5-
public class RecordCheckbox extends WebComponent implements ComponentDisabled {
6-
6+
public class RecordCheckbox extends UIBDefaultComponent implements ComponentDisabled {
77
protected CheckBox checkbox() {
88
return this.createByCss(CheckBox.class, "input[type='checkbox']");
99
}
@@ -12,11 +12,20 @@ public boolean isChecked() {
1212
return checkbox().isChecked();
1313
}
1414

15+
@Override
16+
public void setText(String text) {
17+
}
18+
1519
@Override
1620
public boolean isDisabled() {
1721
return getAttribute("readonly") != null || checkbox().isDisabled() || getAttribute("disabled") != null;
1822
}
1923

24+
@Override
25+
public UibComponentType componentType() {
26+
return null;
27+
}
28+
2029
public void check() {
2130
if (!isChecked() && !isDisabled()) {
2231
checkbox().check();
@@ -40,4 +49,9 @@ public void assertIsChecked() {
4049
public void assertIsUnchecked() {
4150
checkbox().validateIsUnchecked();
4251
}
52+
53+
@Override
54+
public String getText() {
55+
return "";
56+
}
4357
}

bellatrix.servicenow/src/main/java/solutions/bellatrix/servicenow/infrastructure/enums/ServiceNowWorkspaces.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
@Getter
66
public enum ServiceNowWorkspaces {
7+
ASSET_WORKSPACE("Asset Workspace"),
78
CUSTOM_WORKSPACE_NAME("Custom workspace name");
89

910
private final String value;

bellatrix.servicenow/src/main/java/solutions/bellatrix/servicenow/pages/uib/pages/baseUIBPage/BaseUIBPage.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import org.junit.jupiter.api.Assertions;
44
import org.openqa.selenium.Keys;
55
import org.openqa.selenium.NotFoundException;
6+
import org.openqa.selenium.interactions.Actions;
67
import solutions.bellatrix.core.utilities.InstanceFactory;
78
import solutions.bellatrix.core.utilities.Log;
89
import solutions.bellatrix.servicenow.components.models.ServiceNowForm;
10+
import solutions.bellatrix.servicenow.components.uiBuilder.RecordCheckbox;
911
import solutions.bellatrix.servicenow.components.uiBuilder.UIBDefaultComponent;
1012
import solutions.bellatrix.servicenow.components.uiBuilder.UiBuilderRecordChoice;
1113
import solutions.bellatrix.servicenow.models.annotations.snFieldAnnotations.FieldLabel;
@@ -15,13 +17,15 @@
1517
import solutions.bellatrix.servicenow.pages.uib.sections.mainContentSection.MainContentSection;
1618
import solutions.bellatrix.servicenow.pages.uib.sections.menuHeader.MenuHeaderSection;
1719
import solutions.bellatrix.servicenow.pages.uib.sections.tabsSection.TabsSection;
20+
import solutions.bellatrix.web.components.Div;
1821
import solutions.bellatrix.web.components.TextInput;
1922
import solutions.bellatrix.web.components.WebComponent;
2023
import solutions.bellatrix.web.components.shadowdom.ShadowRoot;
2124
import solutions.bellatrix.web.pages.WebPage;
2225

2326
import java.lang.reflect.Field;
2427
import java.lang.reflect.Method;
28+
import java.time.Duration;
2529
import java.util.ArrayList;
2630
import java.util.Arrays;
2731
import java.util.List;
@@ -73,13 +77,15 @@ protected <TFormModel extends ServiceNowForm> TFormModel readForm(WebComponent c
7377
var componentClass = field.getDeclaredAnnotation(UibComponent.class).value();
7478
var elementLabel = field.getDeclaredAnnotation(FieldLabel.class).value();
7579
try {
76-
var foundComponentWrappers = container.createAllByXPath(componentClass, String.format(".//*[contains(name(),'sn-record-') and descendant::*[text()='%s']]", elementLabel)).stream().findAny();
80+
var foundComponentWrappers = container.createAllByXPath(componentClass, String.format("./descendant::*[(contains(name(),'sn-record-') or contains(name(),'now-record-')) and @context='form' and descendant::*[text()='%s']]", elementLabel)).stream().findAny();
7781

7882
if (foundComponentWrappers.isPresent()) {
7983
var component = foundComponentWrappers.get();
8084
String actualValue;
8185
if (componentClass.getName().contains("Reference")) {
8286
actualValue = component.getValue();
87+
} else if (componentClass.getName().contains("Checkbox")) {
88+
actualValue = component.createByXPath(RecordCheckbox.class, "./descendant::now-checkbox").getValue();
8389
} else {
8490
actualValue = component.getShadowRoot().createByCss(TextInput.class,"input" ).getValue();
8591
}
@@ -138,8 +144,18 @@ protected <FormClass extends ServiceNowForm> void fillForm(FormClass model, Web
138144
if (foundComponentWrappers.isPresent()) {
139145
var component = foundComponentWrappers.get();
140146
if (componentClass.getName().contains("Reference")) {
141-
component.getWrappedElement().sendKeys(Keys.chord(Keys.CONTROL, "a"), Keys.BACK_SPACE, field.get(model).toString(), Keys.ENTER);
142-
} else if (componentClass.getName().contains("Choice")){
147+
var value = field.get(model).toString();
148+
149+
Actions actions = new Actions(browser().getWrappedDriver());
150+
151+
actions.sendKeys(component.getWrappedElement(), value)
152+
.pause(Duration.ofMillis(500))
153+
.sendKeys(Keys.ARROW_DOWN)
154+
.pause(Duration.ofMillis(500))
155+
.sendKeys(Keys.ENTER)
156+
.perform();
157+
158+
} else if (componentClass.getName().contains("Choice")){
143159

144160
var choice = ((UiBuilderRecordChoice)component);
145161
choice.dropdownButton().click();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
package solutions.bellatrix.servicenow.pages.uib.pages.uibRecordViewPage;
22

33
public class Asserts<MapT extends Map> extends solutions.bellatrix.servicenow.pages.uib.pages.baseUIBPage.Asserts<MapT> {
4+
public void assertRecordHeading (String record) {
5+
map().recordHeading().validateTextIs(record);
6+
}
47
}

bellatrix.servicenow/src/main/java/solutions/bellatrix/servicenow/pages/uib/pages/uibRecordViewPage/Map.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package solutions.bellatrix.servicenow.pages.uib.pages.uibRecordViewPage;
22

33
import solutions.bellatrix.core.utilities.Log;
4+
import solutions.bellatrix.web.components.Div;
45
import solutions.bellatrix.web.components.shadowdom.ShadowRoot;
56

67
import java.util.List;
@@ -13,4 +14,9 @@ public ShadowRoot getActiveScreen() {
1314
Log.info("Visible Screens found: %s. Selecting the last one.".formatted(allVisibleScreens.size()));
1415
return allVisibleScreens.get(allVisibleScreens.size() - 1);
1516
}
17+
18+
public Div recordHeading() {
19+
var xpathLocator = "./descendant::now-heading/descendant::h1";
20+
return getActiveScreen().createByXPath(Div.class, xpathLocator);
21+
}
1622
}

bellatrix.servicenow/src/main/java/solutions/bellatrix/servicenow/pages/uib/sections/leftSidebarSection/LeftSidebarSection.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ public LeftSidebarSection(BaseUIBPage parentPage) {
1919
public enum MenuItems {
2020
DASHBOARD("dashboard"),
2121
LIST("list"),
22-
HOME("dashboard-btn");
22+
HOME("home"),
23+
INVENTORY("inventory"),
24+
ASSET_ESTATE("assetestate"),
25+
MODEL_MANAGEMENT("modelmanagement"),
26+
CONTRACT_MANAGEMENT("contractmanagement"),
27+
ASSET_OPERATIONS("assetoperations");
2328

2429
@Getter
2530
@Setter
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package O8_UIB;
2+
3+
import solutions.bellatrix.servicenow.contracts.ServiceNowTable;
4+
5+
public enum ProjectTables implements ServiceNowTable {
6+
CATALOG_ITEM_TABLE("sc_cat_item");
7+
private final String value;
8+
9+
ProjectTables(String table) {
10+
this.value = table;
11+
}
12+
13+
@Override
14+
public String getTableName() {
15+
return value;
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package O8_UIB.data.entities;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
6+
import lombok.experimental.SuperBuilder;
7+
import solutions.bellatrix.servicenow.infrastructure.core.entities.ServiceNowEntity;
8+
import solutions.bellatrix.servicenow.models.annotations.TableTarget;
9+
10+
@Data
11+
@SuperBuilder
12+
@EqualsAndHashCode(callSuper = true)
13+
@TableTarget("sc_cat_item")
14+
public class CatalogItem extends ServiceNowEntity<O7_DataCreationHttp.data.incident.Incident> {
15+
@SerializedName("name")
16+
String name;
17+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package O8_UIB.data.entities;
2+
3+
import O8_UIB.ProjectTables;
4+
import solutions.bellatrix.servicenow.infrastructure.core.repositories.TableApiRepository;
5+
6+
public class CatalogItemRepository extends TableApiRepository<CatalogItem> {
7+
public CatalogItemRepository() {
8+
super(CatalogItem.class, ProjectTables.CATALOG_ITEM_TABLE);
9+
}
10+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package O8_UIB.data.models;
2+
3+
import lombok.Data;
4+
import lombok.NoArgsConstructor;
5+
import lombok.experimental.SuperBuilder;
6+
import solutions.bellatrix.servicenow.components.models.ServiceNowForm;
7+
8+
import solutions.bellatrix.servicenow.components.uiBuilder.*;
9+
import solutions.bellatrix.servicenow.models.annotations.snFieldAnnotations.*;
10+
11+
@Data
12+
@SuperBuilder
13+
@NoArgsConstructor
14+
public class RequestItemModel extends ServiceNowForm {
15+
@FieldLabel("Number")
16+
@UibComponent(RecordInput.class)
17+
@FieldLocator("number")
18+
private String number;
19+
20+
@FieldLabel("Item")
21+
@UibComponent(RecordReference.class)
22+
@FieldLocator("cat_item_input")
23+
private String item;
24+
25+
@FieldLabel("Request")
26+
@UibComponent(RecordReference.class)
27+
@FieldLocator("request_input")
28+
private String request;
29+
30+
@FieldLabel("Requested for")
31+
@UibComponent(RecordReference.class)
32+
@FieldLocator("requested_for_input")
33+
private String requestedFor;
34+
35+
@Disabled
36+
@FieldLabel("Due date")
37+
@UibComponent(RecordDateTimeInput.class)
38+
@FieldLocator("due_date-date")
39+
private String dueDate;
40+
41+
@FieldLabel("Configuration item")
42+
@UibComponent(RecordReference.class)
43+
@FieldLocator("configuration_item_input")
44+
private String configurationItem;
45+
46+
@FieldLabel("Watch list")
47+
@UibComponent(RecordReference.class)
48+
@FieldLocator("_input")
49+
private String watchList;
50+
51+
@Disabled
52+
@FieldLabel("Opened")
53+
@UibComponent(RecordDateTimeInput.class)
54+
@FieldLocator("opened_at-date")
55+
private String opened;
56+
57+
@FieldLabel("Opened by")
58+
@UibComponent(RecordReference.class)
59+
@FieldLocator("opened_by_input")
60+
private String openedBy;
61+
62+
@FieldLabel("Stage")
63+
@UibComponent(RecordInput.class)
64+
@FieldLocator("")
65+
private String stage;
66+
67+
@FieldLabel("Quantity")
68+
@UibComponent(RecordInput.class)
69+
@FieldLocator("quantity")
70+
private String quantity;
71+
72+
@Disabled
73+
@FieldLabel("Estimated delivery")
74+
@UibComponent(RecordDateTimeInput.class)
75+
@FieldLocator("estimated_delivery-date")
76+
private String estimatedDelivery;
77+
78+
@Disabled
79+
@FieldLabel("Backordered")
80+
@UibComponent(RecordCheckbox.class)
81+
@FieldLocator("backordered")
82+
private String backordered;
83+
84+
@FieldLabel("Order Guide")
85+
@UibComponent(RecordReference.class)
86+
@FieldLocator("order_guide_input")
87+
private String orderGuide;
88+
89+
public String getNumber() {
90+
return number;
91+
}
92+
93+
public void setNumber(String number) {
94+
this.number = number;
95+
}
96+
}

0 commit comments

Comments
 (0)