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 */
016package edu.samplu.krad.demo.uif.library;
017
018import com.thoughtworks.selenium.SeleneseTestBase;
019import org.junit.Test;
020import org.openqa.selenium.By;
021
022import static org.junit.Assert.assertTrue;
023
024/**
025 * @author Kuali Rice Team (rice.collab@kuali.org)
026 */
027public class DemoLibraryElementsActionSmokeTest extends DemoLibraryBase {
028
029    /**
030     * /kr-krad/kradsampleapp?viewId=Demo-Action-View&methodToCall=start
031     */
032    public static final String BOOKMARK_URL = "/kr-krad/kradsampleapp?viewId=Demo-Action-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        waitAndClickById("Demo-LibraryLink", "");
042        waitAndClickByLinkText("Elements");
043        waitAndClickByLinkText("Action");
044    }
045
046    protected void testActionDefault() throws Exception {
047        waitForElementPresentByClassName("uif-headerText-span");
048        assertTextPresent("Default");
049        SeleneseTestBase.assertTrue(getTextByClassName("uif-instructionalMessage").contains(
050                "Action with action script"));
051        assertElementPresentByLinkText("Action Link");
052    }
053
054    protected void testActionPresubmit() throws Exception {
055        waitAndClickByLinkText("Presubmit");
056        waitForElementPresentByClassName("uif-headerText-span");
057        assertTextPresent("Presubmit");
058        assertTextPresent("ActionLinkField with presubmit script");
059        assertElementPresentByLinkText("Pre submit returning true Link");
060        assertElementPresentByLinkText("Pre submit returning false Link");
061
062        waitAndClickByLinkText("Pre submit returning true Link");
063        assertTrue(driver.switchTo().alert().getText().contains("Pre submit call was invoked, returning true"));
064        driver.switchTo().alert().accept();
065
066        waitAndClickByLinkText("Pre submit returning false Link");
067        assertTrue(driver.switchTo().alert().getText().contains("Pre submit call was invoked, returning false"));
068        driver.switchTo().alert().accept();
069    }
070
071    protected void testActionSuccessCallback() throws Exception {
072        waitAndClickByLinkText("Success Callback");
073        waitForElementPresentByClassName("uif-headerText-span");
074        assertTextPresent("Action Field with a success callback script");
075        assertElementPresentByLinkText("Action Link success callback");
076
077        waitAndClickByLinkText("Action Link success callback");
078        assertTrue(driver.switchTo().alert().getText().contains("Refresh called successfully"));
079        driver.switchTo().alert().accept();
080    }
081
082    protected void testActionValidation() throws Exception {
083        waitForElementPresentByClassName("uif-page"); // make sure the page is there before we use the driver
084        driver.findElement(By.className("uif-page")).findElement(By.linkText("Validation")).click();
085
086        waitForElementPresentByClassName("uif-headerText-span");
087        assertTextPresent("Action Field with client side validation");
088        assertTextPresent("InputField 1");
089        assertIsNotVisibleByXpath("//a[contains(text(),'Required')]");
090
091        waitAndClickByLinkText("Action Link with clientside validation");
092        assertIsVisibleByXpath("//a[contains(text(),'Required')]", "");
093
094        waitAndTypeByName("inputField1", "some text");
095        waitAndClickByLinkText("Action Link with clientside validation");
096        assertIsNotVisibleByXpath("//a[contains(text(),'Required')]");
097    }
098
099    protected void testActionImages() throws Exception {
100        waitAndClickByLinkText("Images");
101        waitForElementPresentByClassName("uif-headerText-span");
102        assertTextPresent("Images");
103        assertTextPresent("Action Field with images");
104
105        driver.findElement(By.partialLinkText("Action Link with left image")).findElement(By.className(
106                "leftActionImage"));
107        driver.findElement(By.partialLinkText("Action Link with right image")).findElement(By.className(
108                "rightActionImage"));
109    }
110
111    protected void testActionButton() throws Exception {
112        waitAndClickByLinkText("Buttons");
113        waitForElementPresentByClassName("prettyprint");
114        assertTextPresent("Buttons");
115        assertTextPresent("Action Field buttons");
116
117        waitAndClickButtonByText("button");
118        assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
119        driver.switchTo().alert().accept();
120
121        waitAndClickButtonByText("Image BOTTOM");
122        assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
123        driver.switchTo().alert().accept();
124
125        waitAndClickById("ST-DemoButtonImageTop");
126        assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
127        driver.switchTo().alert().accept();
128
129        driver.findElement(By.xpath("//span[contains(text(),'Image LEFT')]"));
130        driver.findElement(By.id("ST-DemoButtonImageLeft")).click();
131        assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
132        driver.switchTo().alert().accept();
133
134        driver.findElement(By.id("ST-DemoButtonImageRight")).click();
135        assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
136        driver.switchTo().alert().accept();
137
138        driver.findElement(By.id("ST-DemoButtonImageOnly")).click();
139        assertTrue(driver.switchTo().alert().getText().contains("You clicked a button"));
140        driver.switchTo().alert().accept();
141
142        driver.findElement(By.xpath("//button[contains(text(),'Disabled Button') and @disabled]/preceding-sibling::button/img"));
143        driver.findElement(By.xpath("//button/img[contains(@alt,'Image Only button')]"));
144
145        driver.findElement(By.xpath("//button[contains(text(),'Disabled Button') and @disabled]"));
146    }
147
148    private void testAllActionTabs() throws Exception {
149        testActionDefault();
150        testActionPresubmit();
151        testActionSuccessCallback();
152        testActionValidation();
153        testActionImages();
154        testActionButton();
155    }
156
157    @Test
158    public void testActionButtonBookmark() throws Exception {
159        testActionButton();
160        passed();
161    }
162
163    @Test
164    public void testActionButtonNav() throws Exception {
165        testActionButton();
166        passed();
167    }
168
169    @Test
170    public void testActionBookmark() throws Exception {
171        testAllActionTabs();
172        passed();
173    }
174
175    @Test
176    public void testActionNav() throws Exception {
177        testAllActionTabs();
178        passed();
179    }
180}