001 /* 002 * Copyright 2005-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 package edu.samplu.krad.demo.uif.library; 017 018 import edu.samplu.common.Failable; 019 import org.junit.Test; 020 import org.kuali.rice.krad.uif.UifConstants; 021 import org.openqa.selenium.By; 022 import org.openqa.selenium.WebElement; 023 024 /** 025 * @author Kuali Rice Team (rice.collab@kuali.org) 026 */ 027 public class DemoLibraryDataFieldSmokeTest extends DemoLibraryBase { 028 029 /** 030 * /kr-krad/kradsampleapp?viewId=Demo-DataField-View&methodToCall=start 031 */ 032 public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-DataField-View&methodToCall=start"; 033 034 @Override 035 public String getBookmarkUrl() { 036 return BOOKMARK_URL; 037 } 038 039 @Override 040 protected void navigate() throws Exception { 041 navigateToLibraryDemo("Fields", "Data Field"); 042 } 043 044 protected void testDataFieldDefault() throws Exception { 045 WebElement exampleDiv = navigateToExample("Demo-DataField-Example1"); 046 WebElement field = exampleDiv.findElement(By.cssSelector("div[data-label='DataField 1']")); 047 048 String fieldId = field.getAttribute("id"); 049 String controlId = fieldId + UifConstants.IdSuffixes.CONTROL; 050 051 assertIsVisible("#" + fieldId); 052 assertIsVisible("label[for='" + controlId + "']"); 053 054 WebElement label = field.findElement(By.cssSelector("label[for='" + controlId + "']")); 055 if(!label.getText().contains("DataField 1:")){ 056 fail("Label text does not match"); 057 } 058 059 assertIsVisible("#" + controlId); 060 061 assertTextPresent("1001", "#" + controlId, "DataField value not correct"); 062 } 063 064 protected void testDataFieldLabelTop() throws Exception { 065 WebElement exampleDiv = navigateToExample("Demo-DataField-Example2"); 066 WebElement field = exampleDiv.findElement(By.cssSelector("div[data-label='DataField 1']")); 067 068 String fieldId = field.getAttribute("id"); 069 String controlId = fieldId + UifConstants.IdSuffixes.CONTROL; 070 071 assertIsVisible("#" + fieldId); 072 assertIsVisible("label[for='" + controlId + "']"); 073 074 WebElement label = field.findElement(By.cssSelector("label[for='" + controlId + "']")); 075 if(!label.getText().contains("DataField 1:")){ 076 fail("Label text does not match"); 077 } 078 079 WebElement labelspan = field.findElement(By.cssSelector("span[data-label_for='" + fieldId + "']")); 080 if(!labelspan.getAttribute("class").contains("uif-labelBlock")){ 081 fail("Label span does not contain the appropriate class expected"); 082 } 083 084 assertIsVisible("#" + controlId); 085 } 086 087 protected void testDataFieldExamples() throws Exception{ 088 testDataFieldDefault(); 089 testDataFieldLabelTop(); 090 } 091 092 public void testDataFieldNav(Failable failable) throws Exception{ 093 testDataFieldExamples(); 094 passed(); 095 } 096 097 public void testDataFieldBookmark(Failable failable) throws Exception{ 098 testDataFieldExamples(); 099 passed(); 100 } 101 102 @Test 103 public void testDataFieldBookmark() throws Exception { 104 testDataFieldBookmark(this); 105 } 106 107 @Test 108 public void testDataFieldNav() throws Exception { 109 testDataFieldNav(this); 110 } 111 }