001 /*
002 * Copyright 2006-2013 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 package edu.samplu.krad.demo.uif.library.fields;
018
019 import edu.samplu.common.Failable;
020 import edu.samplu.common.ITUtil;
021 import edu.samplu.krad.demo.uif.library.DemoLibraryITBase;
022 import org.kuali.rice.krad.uif.UifConstants;
023 import org.openqa.selenium.By;
024 import org.openqa.selenium.WebElement;
025
026 /**
027 * @author Kuali Rice Team (rice.collab@kuali.org)
028 */
029 public abstract class DemoLibraryDataFieldSmokeTestBase extends DemoLibraryITBase {
030 /**
031 * /kr-krad/kradsampleapp?viewId=ComponentLibraryHome
032 */
033 public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-DataField-View";
034
035 @Override
036 public String getTestUrl() {
037 return ITUtil.KRAD_PORTAL;
038 }
039
040 protected void testDataFieldDefault() throws Exception {
041 WebElement exampleDiv = navigateToExample("Demo-DataField-Example1");
042 WebElement field = exampleDiv.findElement(By.cssSelector("div[data-label='DataField 1']"));
043
044 String fieldId = field.getAttribute("id");
045 String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
046
047 assertIsVisible("#" + fieldId);
048 assertIsVisible("label[for='" + controlId + "']");
049
050 WebElement label = field.findElement(By.cssSelector("label[for='" + controlId + "']"));
051 if(!label.getText().contains("DataField 1:")){
052 fail("Label text does not match");
053 }
054
055 assertIsVisible("#" + controlId);
056
057 assertTextPresent("1001", "#" + controlId, "DataField value not correct");
058 }
059
060 protected void testDataFieldLabelTop() throws Exception {
061 WebElement exampleDiv = navigateToExample("Demo-DataField-Example2");
062 WebElement field = exampleDiv.findElement(By.cssSelector("div[data-label='DataField 1']"));
063
064 String fieldId = field.getAttribute("id");
065 String controlId = fieldId + UifConstants.IdSuffixes.CONTROL;
066
067 assertIsVisible("#" + fieldId);
068 assertIsVisible("label[for='" + controlId + "']");
069
070 WebElement label = field.findElement(By.cssSelector("label[for='" + controlId + "']"));
071 if(!label.getText().contains("DataField 1:")){
072 fail("Label text does not match");
073 }
074
075 WebElement labelspan = field.findElement(By.cssSelector("span[data-label_for='" + fieldId + "']"));
076 if(!labelspan.getAttribute("class").contains("uif-labelBlock")){
077 fail("Label span does not contain the appropriate class expected");
078 }
079
080 assertIsVisible("#" + controlId);
081 }
082
083 protected void testDataFieldExamples() throws Exception{
084 testDataFieldDefault();
085 testDataFieldLabelTop();
086 }
087
088 public void testDataFieldNav(Failable failable) throws Exception{
089 navigateToLibraryDemo("Fields", "Data Field");
090 testDataFieldExamples();
091 passed();
092 }
093
094 public void testDataFieldBookmark(Failable failable) throws Exception{
095 testDataFieldExamples();
096 passed();
097 }
098 }