1 /**
2 * Copyright 2005-2014 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.testtools.selenium;
17
18 import org.kuali.rice.testtools.common.JiraAwareFailable;
19 import org.openqa.selenium.WebDriver;
20
21 /**
22 * All asserts call {@see JiraAwareFailable#jiraAwareFail} on failure.
23 *
24 * @author Kuali Rice Team (rice.collab@kuali.org)
25 */
26
27 public class JiraAwareWebDriverUtils {
28
29 /**
30 * If booleanToAssertFalse is true call {@see JiraAwareFailable#jiraAwareFail}.
31 *
32 * @param booleanToAssertFalse to assert is false
33 * @param failable to call jiraAwareFail on if booleanToAssertFalse is true
34 */
35 public static void assertFalse(boolean booleanToAssertFalse, JiraAwareFailable failable) {
36 if (booleanToAssertFalse) {
37 failable.jiraAwareFail("expected false, but was true");
38 }
39 }
40
41 /**
42 * If booleanToAssertFalse is true call {@see jiraAwareFail}.
43 *
44 * @param message to include if booleanToAssertFalse is true
45 * @param booleanToAssertFalse
46 */
47 public static void assertFalse(String message, boolean booleanToAssertFalse, JiraAwareFailable failable) {
48 if (booleanToAssertFalse) {
49 failable.jiraAwareFail(message + " expected false, but was true");
50 }
51 }
52
53 /**
54 * If booleanToAssertTrue is false call {@see jiraAwareFail}.
55 *
56 * @param booleanToAssertTrue
57 */
58 public static void assertTrue(boolean booleanToAssertTrue, JiraAwareFailable failable) {
59 if (!booleanToAssertTrue) {
60 failable.jiraAwareFail("expected true, but was false");
61 }
62 }
63
64 /**
65 * If booleanToAssertTrue is false call {@see jiraAwareFail} with the given message.
66 *
67 * @param message to include if booleanToAssertTrue is false
68 * @param booleanToAssertTrue
69 * @param failable
70 */
71 public static void assertTrue(String message, boolean booleanToAssertTrue, JiraAwareFailable failable) {
72 if (!booleanToAssertTrue) {
73 failable.jiraAwareFail(message + " expected true, but was false");
74 }
75 }
76
77 /**
78 * <p>
79 * Fail if the button defined by the buttonText is enabled.
80 * </p>
81 *
82 * @param driver to get the button from
83 * @param buttonText to identify the button
84 * @param failable to fail on if button identified by buttonText is enabled.
85 */
86 public static void assertButtonDisabledByText(WebDriver driver, String buttonText, JiraAwareFailable failable) {
87 WebDriverUtils.jGrowl(driver, "Assert", false, "Assert " + buttonText + " button is disabled");
88 if (WebDriverUtils.findButtonByText(driver, buttonText).isEnabled()) {
89 failable.jiraAwareFail(buttonText + " button is not disabled");
90 }
91 }
92
93 /**
94 * <p>
95 * Fail if the button defined by the buttonText is disabled.
96 * </p>
97 *
98 * @param driver to get the button from
99 * @param buttonText to identify the button
100 * @param failable to fail on if button identified by buttonText is disabled.
101 */
102 public static void assertButtonEnabledByText(WebDriver driver, String buttonText, JiraAwareFailable failable) {
103 WebDriverUtils.jGrowl(driver, "Assert", false, "Assert " + buttonText + " button is enabled");
104 if (!WebDriverUtils.findButtonByText(driver, buttonText).isEnabled()) {
105 failable.jiraAwareFail(buttonText + " button is not enabled");
106 }
107 }
108 }