001/** 002 * Copyright 2005-2016 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 org.kuali.rice.testtools.selenium; 017 018import org.kuali.rice.testtools.common.JiraAwareFailable; 019import org.openqa.selenium.WebDriver; 020 021/** 022 * All asserts call {@see JiraAwareFailable#jiraAwareFail} on failure. 023 * 024 * @author Kuali Rice Team (rice.collab@kuali.org) 025 */ 026 027public class JiraAwareWebDriverUtils { 028 029 /** 030 * If booleanToAssertFalse is true call {@see JiraAwareFailable#jiraAwareFail}. 031 * 032 * @param booleanToAssertFalse to assert is false 033 * @param failable to call jiraAwareFail on if booleanToAssertFalse is true 034 */ 035 public static void assertFalse(boolean booleanToAssertFalse, JiraAwareFailable failable) { 036 if (booleanToAssertFalse) { 037 failable.jiraAwareFail("expected false, but was true"); 038 } 039 } 040 041 /** 042 * If booleanToAssertFalse is true call {@see jiraAwareFail}. 043 * 044 * @param message to include if booleanToAssertFalse is true 045 * @param booleanToAssertFalse 046 */ 047 public static void assertFalse(String message, boolean booleanToAssertFalse, JiraAwareFailable failable) { 048 if (booleanToAssertFalse) { 049 failable.jiraAwareFail(message + " expected false, but was true"); 050 } 051 } 052 053 /** 054 * If booleanToAssertTrue is false call {@see jiraAwareFail}. 055 * 056 * @param booleanToAssertTrue 057 */ 058 public static void assertTrue(boolean booleanToAssertTrue, JiraAwareFailable failable) { 059 if (!booleanToAssertTrue) { 060 failable.jiraAwareFail("expected true, but was false"); 061 } 062 } 063 064 /** 065 * If booleanToAssertTrue is false call {@see jiraAwareFail} with the given message. 066 * 067 * @param message to include if booleanToAssertTrue is false 068 * @param booleanToAssertTrue 069 * @param failable 070 */ 071 public static void assertTrue(String message, boolean booleanToAssertTrue, JiraAwareFailable failable) { 072 if (!booleanToAssertTrue) { 073 failable.jiraAwareFail(message + " expected true, but was false"); 074 } 075 } 076 077 /** 078 * <p> 079 * Fail if the button defined by the buttonText is enabled. 080 * </p> 081 * 082 * @param driver to get the button from 083 * @param buttonText to identify the button 084 * @param failable to fail on if button identified by buttonText is enabled. 085 */ 086 public static void assertButtonDisabledByText(WebDriver driver, String buttonText, JiraAwareFailable failable) { 087 WebDriverUtils.jGrowl(driver, "Assert", false, "Assert " + buttonText + " button is disabled"); 088 if (WebDriverUtils.findButtonByText(driver, buttonText).isEnabled()) { 089 failable.jiraAwareFail(buttonText + " button is not disabled"); 090 } 091 } 092 093 /** 094 * <p> 095 * Fail if the button defined by the buttonText is disabled. 096 * </p> 097 * 098 * @param driver to get the button from 099 * @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}