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.library.controls;
017    
018    import org.junit.Test;
019    
020    import org.kuali.rice.testtools.selenium.Failable;
021    import org.kuali.rice.testtools.selenium.ITUtil;
022    import org.kuali.rice.testtools.selenium.SmokeTestBase;
023    import org.kuali.rice.testtools.selenium.WebDriverLegacyITBase;
024    
025    /**
026     * @author Kuali Rice Team (rice.collab@kuali.org)
027     */
028    public class DemoLibraryControlTextSmokeTest extends SmokeTestBase {
029    
030        /**
031         * /kr-krad/kradsampleapp?viewId=Demo-TextControl-View&methodToCall=start
032         */
033        public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-TextControl-View&methodToCall=start";
034    
035        /**
036         * //div[@id='Demo-TextControl-Example1']/div[@class='uif-verticalBoxLayout clearfix']/div/input[@type='text' and @name='inputField1']
037         */
038        private static final String DEFAULT_TXT_FIELD_XPATH = "//div[@id='Demo-TextControl-Example1']/div[@class='uif-verticalBoxLayout clearfix']/div/input[@type='text' and @name='inputField1']";
039        
040        /**
041         * //div[@id='Demo-TextControl-Example2']/div[@class='uif-verticalBoxLayout clearfix']/div/input[@type='text' and @name='inputField2']
042         */
043        private static final String SIZE_TXT_FIELD_XPATH = "//div[@id='Demo-TextControl-Example2']/div[@class='uif-verticalBoxLayout clearfix']/div/input[@type='text' and @name='inputField2']";
044        
045        /**
046         * //div[@id='Demo-TextControl-Example3']/div[@class='uif-verticalBoxLayout clearfix']/div/a[@title='Expand']
047         */
048        private static final String EXPAND_TXT_FIELD_XPATH = "//div[@id='Demo-TextControl-Example3']/div[@class='uif-verticalBoxLayout clearfix']/div/a[@title='Expand']";
049        
050        /**
051         * //div[@id='Demo-TextControl-Example4']/div[@class='uif-verticalBoxLayout clearfix']/div/input[@type='text' and @name='inputField4' and @disabled='disabled']
052         */
053        private static final String DISABLED_TXT_FIELD_XPATH = "//div[@id='Demo-TextControl-Example4']/div[@class='uif-verticalBoxLayout clearfix']/div/input[@type='text' and @name='inputField4' and @disabled='disabled']";
054        
055        /**
056         * //div[@id='Demo-TextControl-Example7']/div[@class='uif-verticalBoxLayout clearfix']/div/input[@type='text' and @name='inputField5' and @placeholder='watermark text ']
057         */
058        private static final String WATERMARK_TXT_FIELD_XPATH = "//div[@id='Demo-TextControl-Example7']/div[@class='uif-verticalBoxLayout clearfix']/div/input[@type='text' and @name='inputField5' and @placeholder='watermark text ']";
059    
060        /**
061         * //div[@id='Demo-TextControl-Example8']/div[@class='uif-verticalBoxLayout clearfix']/div/input[@type='text' and @name='inputField7' and @disabled='disabled']
062         */
063        private static final String DISABLE_ON_KEY_EVENT_TXT_FIELD_XPATH_BEFORE = "//div[@id='Demo-TextControl-Example8']/div[@class='uif-verticalBoxLayout clearfix']/div/input[@type='text' and @name='inputField7' and @disabled='disabled']";
064        
065        /**
066         * //div[@id='Demo-TextControl-Example8']/div[@class='uif-verticalBoxLayout clearfix']/div/input[@type='text' and @name='inputField7']
067         */
068        private static final String DISABLE_ON_KEY_EVENT_TXT_FIELD_XPATH_AFTER = "//div[@id='Demo-TextControl-Example8']/div[@class='uif-verticalBoxLayout clearfix']/div/input[@type='text' and @name='inputField7']";
069        
070        /**
071         * //div[@id='Demo-TextControl-Example9']/div[@class='uif-verticalBoxLayout clearfix']/div/input[@type='text' and @name='inputField9' and @disabled='disabled']
072         */
073        private static final String ENABLE_WHEN_CHANGED_TXT_FIELD_XPATH_BEFORE = "//div[@id='Demo-TextControl-Example9']/div[@class='uif-verticalBoxLayout clearfix']/div/input[@type='text' and @name='inputField9' and @disabled='disabled']";
074        
075        /**
076         * //div[@id='Demo-TextControl-Example9']/div[@class='uif-verticalBoxLayout clearfix']/div/input[@type='text' and @name='inputField9']
077         */
078        private static final String ENABLE_WHEN_CHANGED_TXT_FIELD_XPATH_AFTER = "//div[@id='Demo-TextControl-Example9']/div[@class='uif-verticalBoxLayout clearfix']/div/input[@type='text' and @name='inputField9']";
079        
080        /**
081         * //div[@id='Demo-TextControl-Example10']/div[@class='uif-verticalBoxLayout clearfix']/div/input[@type='text' and @name='inputField11' and @disabled='disabled']
082         */
083        private static final String DISABLE_WHEN_CHANGED_TXT_FIELD_XPATH_AFTER = "//div[@id='Demo-TextControl-Example10']/div[@class='uif-verticalBoxLayout clearfix']/div/input[@type='text' and @name='inputField11' and @disabled]";
084        
085        /**
086         * //div[@id='Demo-TextControl-Example10']/div[@class='uif-verticalBoxLayout clearfix']/div/input[@type='text' and @name='inputField11']
087         */
088        private static final String DISABLE_WHEN_CHANGED_TXT_FIELD_XPATH_BEFORE = "//div[@id='Demo-TextControl-Example10']/div[@class='uif-verticalBoxLayout clearfix']/div/input[@type='text' and @name='inputField11']";
089        
090        @Override
091        protected String getBookmarkUrl() {
092            return BOOKMARK_URL;
093        }
094    
095        @Override
096        protected void navigate() throws Exception {
097            waitAndClickById("Demo-LibraryLink", "");
098            waitAndClickByLinkText("Controls");
099            waitAndClickByLinkText("Text");
100        }
101    
102        protected void testLibraryControlTextDefault() throws Exception {
103            waitForElementPresentByXpath(DEFAULT_TXT_FIELD_XPATH);
104            waitAndTypeByXpath(DEFAULT_TXT_FIELD_XPATH,"HiText!");
105        }
106        
107        protected void testLibraryControlTextSize() throws Exception {
108            waitAndClickByLinkText("Size");
109            waitForElementPresentByXpath(SIZE_TXT_FIELD_XPATH);
110            waitAndTypeByXpath(SIZE_TXT_FIELD_XPATH,"HiTextHiTextHiTextHiTextHiTextHiTextHiTextHiTextHiTextHiText");
111        }
112        
113        protected void testLibraryControlTextExpand() throws Exception {
114            waitAndClickByLinkText("Text expand");
115            waitForElementPresentByXpath(EXPAND_TXT_FIELD_XPATH);
116        }
117        
118        protected void testLibraryControlTextDisabled() throws Exception {
119            waitAndClickByLinkText("Disabled");
120            waitForElementPresentByXpath(DISABLED_TXT_FIELD_XPATH);
121        }
122        
123        protected void testLibraryControlTextWatermarkText() throws Exception {
124            waitAndClickByLinkText("WatermarkText");
125            waitForElementPresentByXpath(WATERMARK_TXT_FIELD_XPATH);
126        }
127    
128        protected void testLibraryControlTextDisableOnKeyEvent() throws Exception {
129            waitAndClickByLinkText("Disable on Key event");
130            assertElementPresentByXpath(DISABLE_ON_KEY_EVENT_TXT_FIELD_XPATH_BEFORE);
131            waitAndTypeByName("inputField6","a");
132            assertElementPresentByXpath(DISABLE_ON_KEY_EVENT_TXT_FIELD_XPATH_AFTER);
133        }
134        
135        protected void testLibraryControlTextEnableWhenChanged() throws Exception {
136            waitAndClickByLinkText("Enable when changed");
137            assertElementPresentByXpath(ENABLE_WHEN_CHANGED_TXT_FIELD_XPATH_BEFORE);
138            waitAndTypeByName("inputField8","a");
139            waitAndClickByLinkText("Usage");
140            assertElementPresentByXpath(ENABLE_WHEN_CHANGED_TXT_FIELD_XPATH_AFTER);
141        }
142        
143        protected void testLibraryControlTextDisableWhenChanged() throws Exception {
144            waitAndClickByLinkText("Disable when changed");
145            assertElementPresentByXpath(DISABLE_WHEN_CHANGED_TXT_FIELD_XPATH_BEFORE);
146            waitAndTypeByName("inputField10","a");
147            waitAndClickByLinkText("Usage");
148            assertElementPresentByXpath(DISABLE_WHEN_CHANGED_TXT_FIELD_XPATH_AFTER);
149        }
150        
151        @Test
152        public void testControlTextBookmark() throws Exception {
153            testLibraryControlTextDefault();
154            testLibraryControlTextSize();
155            testLibraryControlTextExpand();
156            testLibraryControlTextDisabled();
157            testLibraryControlTextWatermarkText();
158            testLibraryControlTextDisableOnKeyEvent();
159            testLibraryControlTextEnableWhenChanged();
160            testLibraryControlTextDisableWhenChanged();
161            passed();
162        }
163    
164        @Test
165        public void testControlTextNav() throws Exception {
166            testLibraryControlTextDefault();
167            testLibraryControlTextSize();
168            testLibraryControlTextExpand();
169            testLibraryControlTextDisabled();
170            testLibraryControlTextWatermarkText();
171            testLibraryControlTextDisableOnKeyEvent();
172            testLibraryControlTextEnableWhenChanged();
173            testLibraryControlTextDisableWhenChanged();
174            passed();
175        }  
176    }