1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.demo.travel.application;
17
18 import org.apache.commons.lang.RandomStringUtils;
19 import org.junit.Test;
20 import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
21 import org.kuali.rice.testtools.selenium.WebDriverUtils;
22 import org.openqa.selenium.By;
23 import org.openqa.selenium.WebElement;
24
25 import java.util.List;
26
27
28
29
30 public class DemoTravelCompanySequenceGenerationAft extends WebDriverLegacyITBase {
31
32
33
34
35 public static final String BOOKMARK_URL = "/kr-krad/lookup?methodToCall=start&dataObjectClassName=edu.sampleu.travel.dataobject.TravelCompany";
36
37 public static final String DESCRIPTION_FIELD = "document.documentHeader.documentDescription";
38 public static final String COMPANY_NAME_FIELD = "document.newMaintainableObject.dataObject.travelCompanyName";
39 public static final String TRAVEL_COMPANY_ID = "lookupCriteria[travelCompanyId]";
40 public static final String TRAVEL_CO_ID_XPATH = "//div[@data-label=\"Id\"]";
41
42 @Override
43 public String getBookmarkUrl() {
44 return BOOKMARK_URL;
45 }
46
47 protected void navigate() throws Exception {
48 waitAndClickDemoLink();
49 waitAndClickByLinkText("Travel Company Lookup");
50 }
51
52 protected void testTravelCompanyCreateNewDocumentSequenceGeneration() throws Exception {
53 waitAndClickByLinkText("Create New");
54
55 createTravelCompanyDoc();
56 int travelCompanyIdDoc1 = Integer.parseInt(findElement(By.xpath(TRAVEL_CO_ID_XPATH)).getText());
57
58 navigate();
59 waitAndClickByLinkText("Create New");
60
61 createTravelCompanyDoc();
62 int travelCompanyIdDoc2 = Integer.parseInt(findElement(By.xpath(TRAVEL_CO_ID_XPATH)).getText());
63
64 assertTrue("The Travel Company Id on the second document should be one higher than the first document. "
65 + "travelCompanyIdDoc1: " + travelCompanyIdDoc1 + ", travelCompanyIdDoc2: " + travelCompanyIdDoc2 ,
66 travelCompanyIdDoc2 == travelCompanyIdDoc1 + 1);
67 }
68
69 protected void testTravelCompanyCopyDocumentSequenceGeneration() throws Exception {
70 waitAndClickButtonByText(SEARCH);
71 waitAndClickCopy();
72 createTravelCompanyDoc();
73
74 int travelCompanyIdDoc1 = determineNewTravelCompanyId();
75
76 navigate();
77
78 waitAndTypeByName(TRAVEL_COMPANY_ID, Integer.toString(travelCompanyIdDoc1));
79 waitAndClickButtonByText(SEARCH);
80 waitAndClickCopy();
81 createTravelCompanyDoc();
82 int travelCompanyIdDoc2 = determineNewTravelCompanyId();
83
84 assertTrue("The Travel Company Id on the second document should be one higher than the first document. "
85 + "travelCompanyIdDoc1: " + travelCompanyIdDoc1 + ", travelCompanyIdDoc2: " + travelCompanyIdDoc2 ,
86 travelCompanyIdDoc2 == travelCompanyIdDoc1 + 1);
87 }
88
89 private void createTravelCompanyDoc() throws Exception {
90 waitAndTypeByName(DESCRIPTION_FIELD,"Travel Company Sequence Generation Test");
91 String randomCode = RandomStringUtils.randomAlphabetic(5).toUpperCase();
92 clearTextByName(COMPANY_NAME_FIELD);
93 waitAndTypeByName(COMPANY_NAME_FIELD, "Company Name " + randomCode);
94
95 waitAndClickSubmitByText();
96 waitAndClickConfirmSubmitOk();
97 waitForProgress("Loading...", WebDriverUtils.configuredImplicityWait() * 8);
98 waitForTextPresent("Document was successfully submitted.", WebDriverUtils.configuredImplicityWait() * 2);
99 }
100
101 private int determineNewTravelCompanyId() throws Exception {
102 int highestTravelCompanyId = 0;
103 List<WebElement> travelCompanyIds = findElements(By.xpath(TRAVEL_CO_ID_XPATH));
104
105 for (WebElement travelCompanyId: travelCompanyIds) {
106 int potentialNewId = Integer.parseInt(travelCompanyId.getText());
107 if (potentialNewId > highestTravelCompanyId) {
108 highestTravelCompanyId = potentialNewId;
109 }
110 }
111
112 return highestTravelCompanyId;
113 }
114
115 @Test
116 public void testTravelCompanyCreateNewDocumentSequenceGenerationBookmark() throws Exception {
117 testTravelCompanyCreateNewDocumentSequenceGeneration();
118 passed();
119 }
120
121 @Test
122 public void testTravelCompanyCreateNewDocumentSequenceGenerationNav() throws Exception {
123 testTravelCompanyCreateNewDocumentSequenceGeneration();
124 passed();
125 }
126
127 @Test
128 public void testTravelCompanyCopyDocumentSequenceGenerationBookmark() throws Exception {
129 testTravelCompanyCopyDocumentSequenceGeneration();
130 passed();
131 }
132
133 @Test
134 public void testTravelCompanyCopyDocumentSequenceGenerationNav() throws Exception {
135 testTravelCompanyCopyDocumentSequenceGeneration();
136 passed();
137 }
138 }