View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package edu.sampleu.main;
17  
18  import org.junit.Before;
19  import org.kuali.rice.testtools.selenium.AutomatedFunctionalTestUtils;
20  import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
21  import org.kuali.rice.testtools.selenium.WebDriverUtils;
22  import org.junit.Test;
23  import org.openqa.selenium.By;
24  
25  /**
26   * @author Kuali Rice Team (rice.collab@kuali.org)
27   */
28  public class CreateNewAgendaAft extends WebDriverLegacyITBase {
29  
30      protected static final String NAME_LABEL = "Name:";
31      protected static final String NAMESPACE_LABEL = "Namespace:";
32      protected static final String CONTEXT_LABEL = "Context:";
33      private boolean useUi = false;
34  
35      protected static String[][] inputVerifyDetails;
36  
37      /**
38       * ITUtil.PORTAL + "?channelTitle=Create%20New%20Agenda&channelUrl=" + WebDriverUtils.getBaseUrlString() +
39       *  "/kr-krad/krmsAgendaEditor?methodToCall=start&dataObjectClassName=org.kuali.rice.krms.impl.ui.AgendaEditor&returnLocation=" +
40       *  ITUtil.PORTAL_URL + ITUtil.HIDE_RETURN_LINK;
41       */
42      public static final String BOOKMARK_URL = AutomatedFunctionalTestUtils.PORTAL + "?channelTitle=Create%20New%20Agenda&channelUrl=" + WebDriverUtils
43              .getBaseUrlString() +"/kr-krad/krmsAgendaEditor?methodToCall=start&dataObjectClassName=org.kuali.rice.krms.impl.ui.AgendaEditor&returnLocation=" +
44              AutomatedFunctionalTestUtils.PORTAL_URL + AutomatedFunctionalTestUtils.HIDE_RETURN_LINK;
45  
46      @Before
47      @Override
48      public void testSetUp() {
49          super.testSetUp();
50          inputVerifyDetails = new String[][] {
51                  {NAME_LABEL, getDescriptionUnique()},
52                  {NAMESPACE_LABEL, "Kuali Rules Test"},
53                  {CONTEXT_LABEL, "Context1"}
54          };
55  
56      }
57  
58      @Override
59      protected String getBookmarkUrl() {
60          return BOOKMARK_URL;
61      }
62  
63      // Lots of Overrides as KRMS was early KRAD
64      @Override
65      protected void assertBlanketApproveButtonsPresent() {
66          assertTrue(isVisible(By.xpath("//button[contains( text(), 'Cancel')]")));
67          assertTrue(isVisible(By.xpath("//button[contains( text(), 'Save')]")));
68          assertTrue(isVisible(By.xpath("//button[contains( text(), 'Blanket Approve')]")));
69          assertTrue(isVisible(By.xpath("//button[contains( text(), 'Submit')]")));
70      }
71  
72      @Override
73      protected void assertRouteStatus(String status) throws InterruptedException {
74          super.assertRouteStatus(status);
75      }
76  
77      private void verify(String docId) throws InterruptedException {
78          waitAndClickLinkContainingText(docId);
79  
80          driver.switchTo().window((String) driver.getWindowHandles().toArray()[1]);
81  
82          waitIsVisible(By.xpath("//tr/th/label[contains(text(), '" + CONTEXT_LABEL + "')]"));
83          assertLabeledTextPresent(inputVerifyDetails);
84          screenshot();
85      }
86  
87      private void verifyInputs(String docId) throws InterruptedException {
88          waitAndClickLinkContainingText(docId);
89  
90          driver.switchTo().window((String) driver.getWindowHandles().toArray()[1]);
91  
92          waitIsVisible(By.xpath("//tr/th/label[contains(text(), '" + CONTEXT_LABEL + "')]"));
93          assertLabeledInputTextPresent(inputVerifyDetails);
94          screenshot();
95      }
96  
97      @Override
98      public void checkForDocError() {
99          checkForDocErrorKrad();
100     }
101 
102     @Override
103     protected void waitAndClickBlanketApproveKns() throws InterruptedException {
104         waitAndClickBlanketApprove();
105         waitAndClickConfirmBlanketApproveOk();
106         acceptAlertIfPresent();
107         waitForProgressLoading();
108     }
109 
110     @Override
111     protected void waitAndCancelConfirmation() throws InterruptedException {
112         waitAndClickCancel();
113         acceptAlertIfPresent();
114         waitAndClickConfirmCancelOk();
115     }
116 
117     @Override
118     protected void waitAndClickCancel() throws InterruptedException {
119         waitAndClickCancelByText();
120     }
121 
122     @Override
123     protected void waitAndCreateNew() {
124         // no-op as the create new link is on the portal page.
125     }
126 
127     @Override
128     protected String waitForDocId() throws InterruptedException {
129         checkForDocError();
130         String docId = waitForLabeledText("Document Number:");
131         jGrowl("Document Number is " + docId);
132         return docId;
133     }
134 
135     @Override
136     protected void waitAndClickSave() throws InterruptedException {
137         waitAndClickSaveByText();
138     }
139 
140     @Override
141     protected void waitAndClickSubmit() throws InterruptedException {
142         waitAndClickSubmitByText();
143     }
144 
145     @Override
146     protected void waitForSuccessfulSaveMessage() throws InterruptedException {
147         assertTrue(waitForElementVisibleBy(By.xpath("//div[@id='AgendaEditorView-Agenda-Page_messages']")).getText()
148                 .contains("Document was successfully saved."));
149     }
150 
151     @Override
152     protected void waitForSuccessfulSubmitMessage() throws InterruptedException {
153         waitAndClickConfirmSubmitOk();
154         checkForDocErrorKrad();
155         assertTrue(waitForElementVisibleBy(By.xpath("//div[@id='AgendaEditorView-Agenda-Page_messages']")).getText().contains("Document was successfully submitted."));
156     }
157 
158     @Override
159     protected void testCreateNewRequired() throws Exception {
160         selectFrameIframePortlet();
161         waitAndCreateNew();
162         waitAndClickSubmit();
163         String mainError = waitForElementVisibleBy(By.xpath("//div[@id='AgendaEditorView-Agenda-Page_messages']")).getText();
164         assertTrue(mainError + " does not contain Agenda: 3 errors", mainError.contains("Agenda: 3 errors"));
165         String detailError = waitForElementVisibleBy(By.xpath("//section[@data-parent='AgendaEditorView-Agenda-Page']/div/div")).getText();
166         assertTrue(detailError + " does not contain 3 errors", detailError.contains("3 errors"));
167         assertTrue(detailError + " does not contain Namespace: Required", detailError.contains("Namespace: Required"));
168         assertTrue(detailError + " does not contain Name: Required", detailError.contains("Name: Required"));
169         assertTrue(detailError + " does not contain Context: Required", detailError.contains("Context: Required"));
170 
171         // verify required fields divs have the uif-hasError class
172         isVisible(By.xpath("//select[@name='document.newMaintainableObject.dataObject.namespace']/../../div[@class='uif-inputField uif-hasError']"));
173         isVisible(By.xpath("//input[@name='document.newMaintainableObject.dataObject.agenda.name']/../../div[@class='uif-inputField uif-hasError']"));
174         isVisible(By.xpath("//input[@name='document.newMaintainableObject.dataObject.contextName']/../../div[@class='uif-inputField uif-hasError']"));
175     }
176 
177     @Override
178     protected String verifyDocInitiated() throws InterruptedException {
179         String docId = waitForDocId();
180         assertEquals("INITIATED", waitForLabeledText("Document Status:"));
181         assertEquals(getUserName(), waitForLabeledText(" Initiator Network Id:"));
182         return docId;
183     }
184 
185     @Override
186     protected void navigate() throws Exception {
187         useUi = true; // nav test will use UI components (lookups), bookmark types it in
188         waitForTitleToEqualKualiPortalIndex();
189         selectTopFrame();
190         waitAndClickByLinkText("Main Menu","");
191         waitForTitleToEqualKualiPortalIndex();
192         waitAndClickByLinkText("Create New Agenda", "");
193         waitForTitleToEqualKualiPortalIndex("");
194         selectFrameIframePortlet();
195         checkForIncidentReport("Create New Agenda", "");
196     }
197 
198     protected void createNewEnterDetails() throws InterruptedException {
199         selectFrameIframePortlet();
200         waitAndSelectLabeled(NAMESPACE_LABEL, inputVerifyDetails[1][1]);
201         inputDetails();
202 
203         if (useUi) {
204             waitAndClickLabeledQuickFinder(CONTEXT_LABEL);
205             waitForProgressLoading();
206             gotoIframeByXpath("//iframe");
207             waitAndClickSearchByText();
208             waitAndClickReturnValue(); // Context1
209             selectTopFrame();
210             gotoNestedFrame();
211         }
212     }
213 
214     @Override
215     protected void createNewLookupDetails() throws InterruptedException {
216         createNewEnterDetails();
217     }
218 
219     private void inputDetails() throws InterruptedException {
220         waitAndTypeLabeledInput(NAME_LABEL, inputVerifyDetails[0][1]);
221         if (!useUi) {
222             waitAndTypeLabeledInput(CONTEXT_LABEL, inputVerifyDetails[2][1]);
223         }
224     }
225 
226     @Test
227     public void testCreateNewCancelBookmark() throws Exception {
228         // Use the UI to populate the context so that the cancel confirmation popups are the same for both the
229         // nav and bookmark tests.
230         useUi = true;
231         testCreateNewCancel();
232         passed();
233     }
234 
235     @Test
236     public void testCreateNewCancelNav() throws Exception {
237         testCreateNewCancel();
238         passed();
239     }
240 
241     @Test
242     public void testCreateNewRequiredBookmark() throws Exception {
243         testCreateNewRequired();
244         passed();
245     }
246 
247     @Test
248     public void testCreateNewRequiredNav() throws Exception {
249         testCreateNewRequired();
250         passed();
251     }
252 
253     @Test
254     public void testCreateNewSaveBookmark() throws Exception {
255         verifyInputs(testCreateNewSave());
256         passed();
257     }
258 
259     @Test
260     public void testCreateNewSaveNav() throws Exception {
261         verifyInputs(testCreateNewSave());
262         passed();
263     }
264 
265     @Test
266     public void testCreateNewSaveSubmitBookmark() throws Exception {
267         verify(testCreateNewSaveSubmit());
268         passed();
269     }
270 
271     @Test
272     public void testCreateNewSaveSubmitNav() throws Exception {
273         verify(testCreateNewSaveSubmit());
274         passed();
275     }
276 
277     @Test
278     public void testCreateNewSubmitBookmark() throws Exception {
279         verify(testCreateNewSubmit());
280         passed();
281     }
282 
283     @Test
284     public void testCreateNewSubmitNav() throws Exception {
285         verify(testCreateNewSubmit());
286         passed();
287     }
288 
289     @Test
290     public void testBlanketAppBookmark() throws Exception {
291         verify(testBlanketApprove());
292         passed();
293     }
294 
295     @Test
296     public void testBlanketAppNav() throws Exception {
297         verify(testBlanketApprove());
298         passed();
299     }
300 }