View Javadoc

1   /*
2    * Copyright 2006-2013 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  
17  package edu.samplu.krad.demo.uif.library.fields;
18  
19  import edu.samplu.common.Failable;
20  import edu.samplu.common.ITUtil;
21  import edu.samplu.krad.demo.uif.library.DemoLibraryITBase;
22  import org.kuali.rice.krad.uif.UifConstants;
23  import org.openqa.selenium.By;
24  import org.openqa.selenium.WebElement;
25  
26  /**
27   * @author Kuali Rice Team (rice.collab@kuali.org)
28   */
29  public abstract class DemoLibraryDataFieldSmokeTestBase extends DemoLibraryITBase {
30      /**
31       * /kr-krad/kradsampleapp?viewId=ComponentLibraryHome
32       */
33      public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-DataField-View";
34  
35      @Override
36      public String getTestUrl() {
37          return ITUtil.KRAD_PORTAL;
38      }
39  
40      protected void testDataFieldDefault() throws Exception {
41          WebElement exampleDiv = navigateToExample("Demo-DataField-Example1");
42          WebElement field = exampleDiv.findElement(By.cssSelector("div[data-label='DataField 1']"));
43  
44          String fieldId = field.getAttribute("id");
45          String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
46  
47          assertIsVisible("#" + fieldId);
48          assertIsVisible("label[for='" + controlId + "']");
49  
50          WebElement label = field.findElement(By.cssSelector("label[for='" + controlId + "']"));
51          if(!label.getText().contains("DataField 1:")){
52              fail("Label text does not match");
53          }
54  
55          assertIsVisible("#" + controlId);
56  
57          assertTextPresent("1001", "#" + controlId, "DataField value not correct");
58      }
59  
60      protected void testDataFieldLabelTop() throws Exception {
61          WebElement exampleDiv = navigateToExample("Demo-DataField-Example2");
62          WebElement field = exampleDiv.findElement(By.cssSelector("div[data-label='DataField 1']"));
63  
64          String fieldId = field.getAttribute("id");
65          String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
66  
67          assertIsVisible("#" + fieldId);
68          assertIsVisible("label[for='" + controlId + "']");
69  
70          WebElement label = field.findElement(By.cssSelector("label[for='" + controlId + "']"));
71          if(!label.getText().contains("DataField 1:")){
72              fail("Label text does not match");
73          }
74  
75          WebElement labelspan = field.findElement(By.cssSelector("span[data-label_for='" + fieldId + "']"));
76          if(!labelspan.getAttribute("class").contains("uif-labelBlock")){
77              fail("Label span does not contain the appropriate class expected");
78          }
79  
80          assertIsVisible("#" + controlId);
81      }
82  
83      protected void testDataFieldExamples() throws Exception{
84          testDataFieldDefault();
85          testDataFieldLabelTop();
86      }
87  
88      public void testDataFieldNav(Failable failable) throws Exception{
89          navigateToLibraryDemo("Fields", "Data Field");
90          testDataFieldExamples();
91          passed();
92      }
93  
94      public void testDataFieldBookmark(Failable failable) throws Exception{
95          testDataFieldExamples();
96          passed();
97      }
98  }