001/* 002 * (C) Copyright 2014 Nuxeo SA (http://nuxeo.com/) and contributors. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * <a href="mailto:grenard@nuxeo.com">Guillaume</a> 016 */ 017package org.nuxeo.functionaltests; 018 019import org.openqa.selenium.By; 020import org.openqa.selenium.NoSuchElementException; 021import org.openqa.selenium.WebElement; 022 023/** 024 * Helper class providing assert methods on WebElement conditions. 025 * 026 * @since 5.9.2 027 */ 028public class Assert { 029 030 /** 031 * Returns true if corresponding element is found in the test page. 032 * 033 * @since 5.7 034 */ 035 public static boolean hasElement(By by) { 036 boolean present; 037 try { 038 AbstractTest.driver.findElement(by); 039 present = true; 040 } catch (NoSuchElementException e) { 041 present = false; 042 } 043 return present; 044 } 045 046 /** 047 * Returns true if {@code text} is present in the element retrieved with the given method. 048 * 049 * @since 5.7.3 050 */ 051 public static boolean isTextPresent(By by, String text) { 052 return isTextPresent(AbstractTest.driver.findElement(by), text); 053 } 054 055 /** 056 * Returns true if {@code text} is present in the given element. 057 * 058 * @since 5.7.3 059 */ 060 public static boolean isTextPresent(WebElement element, String text) { 061 return element.getText().contains(text); 062 } 063 064}