View Javadoc
1   /**
2    * Copyright 2005-2016 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 org.kuali.rice.krad.demo.uif.library.fields;
17  
18  import org.apache.commons.lang.StringUtils;
19  import org.junit.Test;
20  import org.kuali.rice.krad.demo.uif.library.LibraryBase;
21  import org.openqa.selenium.By;
22  import org.openqa.selenium.WebElement;
23  
24  /**
25   * @author Kuali Rice Team (rice.collab@kuali.org)
26   */
27  public abstract class LibraryFieldsKimLinkBase extends LibraryBase {
28      public static final String INQUIRY = "inquiry?";
29      public static final String HREF_ATTRIBUTE = "href";
30      public static final String ID_ATTRIBUTE = "id";
31      public static final String SEARCH_ICON_CLASSNAME = "icon-search";
32      public static final String UIF_LINK_CLASSNAME = "uif-link";
33      public static final String UIF_LINK_CSS_SELECTOR = ".uif-link";
34  
35      protected void waitAndClickQuickFinderButton(String message) throws InterruptedException {
36          jGrowl("Click Quickfinder button.");
37          waitAndClickByXpath("//button[contains(@class,'" + SEARCH_ICON_CLASSNAME + "')]", message);
38      }
39  
40      protected WebElement waitForExampleElementById(String sectionId) throws Exception {
41          waitForElementPresentById(sectionId);
42          waitForElementVisibleById(sectionId, "");
43          return findElement(By.id(sectionId));
44      }
45  
46      protected void verifyLinkIsInquiry(WebElement field) {
47          jGrowl("verifyLinkIsInquiry");
48          String href =  field.getAttribute(HREF_ATTRIBUTE);
49          if ( !StringUtils.contains(href, INQUIRY)) {
50              fail("Inquiry not found in link");
51          }
52      }
53  
54      protected void verifyKeyInInquiryHref(WebElement field, String keyParameter) {
55          jGrowl("verifyKeyInInquiryHref");
56          String href =  field.getAttribute(HREF_ATTRIBUTE);
57          if ( !StringUtils.contains(href,keyParameter)) {
58              fail("Inquiry key " + keyParameter + " not found in href");
59          }
60      }
61  
62      protected void verifyLinkText(WebElement field, String linkText) {
63          jGrowl("verifyLinkText");
64          String fieldText = field.getText();
65          if ( !StringUtils.contains(fieldText,linkText)) {
66              fail("Expected linkText not found. Expected " + linkText + " but found " + fieldText  );
67          }
68      }
69  
70      protected void verifyLinkIcon(WebElement field, String iconClassName) {
71          jGrowl("verifyLinkIcon");
72          String classNames = field.getAttribute("class");
73          if ( !StringUtils.contains(classNames,iconClassName)) {
74              fail("Expected icon class name not found. Expected "+ iconClassName + " but found " + classNames);
75          }
76      }
77  
78      protected void verifyLink(WebElement field, String onPageString)throws Exception {
79          jGrowl("verifyLink");
80          waitAndClickByLinkText(field.getText());
81  
82          gotoLightBox();
83          assertTextPresent(onPageString);
84          waitAndClickButtonByText("Close", "Unable to find Close button");
85          selectTopFrame();
86      }
87  
88      protected void verifyLinkDataItem(WebElement field, String inputFieldName, String inputFieldValue)throws Exception {
89          jGrowl("verifyLinkDataItem");
90          waitAndClickById(field.getAttribute(ID_ATTRIBUTE));
91          gotoLightBox();
92          WebElement inquiryPage = findElement(By.xpath(("//main[contains(@class,'uif-inquiryPage')]")));
93          WebElement inputField = findElement(By.xpath("//td/div[@data-label='"+inputFieldName+"']/span"),inquiryPage);
94          String fieldText = inputField.getText();
95          if ( !StringUtils.contains(fieldText,inputFieldValue)) {
96              fail("Expected value not found on field. Expected " + inputFieldValue + " but found " + fieldText);
97          }
98  
99          waitAndClickButtonByText("Close", "Unable to find Close button");
100         selectTopFrame();
101     }
102 }