Complete Test Example

Below is a complete UI test, used to test a multi-level model CRUD page. Note that only a single method is annotated with @Test, because JUnit 4 does not guarantee test method execution order, and order is generally important for UI tests.

public class ModelCRUDUITest extends AbstractUITest {
private static final PlatformLogger LOG = PlatformLogger.get(ModelCRUDUITest.class);
public static CommandCenter cc;
private static Tab tab;
private String name = "" + System.currentTimeMillis();
@BeforeClass
public static void setUp() {
cc = new CommandCenter();
cc.login("ShowcaseUser", "password");
}
@Test
public void test() {
openCreatePage();
setFieldValues();
addMilestones();
createTask();
verifyFieldValues();
deleteMilestone();
deleteTask();
}
protected void openCreatePage() {
tab = cc.openTabFromMenu("Advanced Components", "ModelCRUD", "Custom Layout Create");
}
protected void setFieldValues() {
context.waitUntilUnmask();
((TextField) tab.getFieldByLabel("Summary")).setValue(name);
((StringEnumerationField) tab.getFieldByLabel("Priority")).setValue("Medium");
((ModelLinkField) tab.getFieldByLabel("Assigned User")).setValue("ShowcaseUser", true);
((com.onenetwork.platform.tools.test.ui.components.TextField) tab.getFieldByLabel("Estimated Effort Days")).setValue("4");
}
protected void addMilestones() {
Hyperlink addLink = (Hyperlink) tab.getLink("Add");
addLink.click();
Grid grid = tab.getGrid();
((TextField) grid.startEditing(0, "Milestone Description").getEditor()).setValue("Milestone A");
((StringEnumerationField) grid.startEditing(0, "Milestone Status").getEditor()).setValue("In Progress");
}
protected void createTask() {
Button btn = tab.getButton("Create Task Full");
btn.click();
tab.waitForSuccessMessage();
}
protected void verifyFieldValues() {
Assert.assertEquals(name, ((DisplayField) tab.getFieldByLabel("Summary")).getValue());
Assert.assertEquals("ShowcaseUser", ((DisplayField) tab.getFieldByLabel("Assigned User")).getValue());
Assert.assertEquals("Medium", ((DisplayField) tab.getFieldByLabel("Priority")).getValue());
Assert.assertEquals("4", ((DisplayField) tab.getFieldByLabel("Estimated Effort Days")).getValue());
}
protected void deleteMilestone() {
Grid grid = tab.getGrid();
List<WebElement> rows = grid.getRows();
Assert.assertEquals(1, rows.size());
tab.clickMenuItem("Actions", "Update Task");
context.waitUntilUnmask();
// delete the row
context.waitUntilElementExists(tab.getGrid().getRows().get(0), By.className("model-form-grid-delete-icon")).click();
tab.getButton("Submit").click();
tab.waitForSuccessMessage();
cc.refreshTab();
Assert.assertEquals(0, tab.getGrid().getRowCount());
}
protected void deleteTask() {
tab.clickMenuItem("Actions", "Delete Task");
tab.getWindow().getButton("Yes").click();
tab.waitForSuccessMessage();
}
@AfterClass
public static void tearDown() {
cc.logout();
}
}

Here's a screenshot of the page in Showcase that this test is used on, for reference:

images/download/attachments/144836450/ui-test-version-1-modificationdate-1645139689000-api-v2.png