package org.expressolivre.cte.pages.calendar; import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; /** * @author L.F.Estivalet (Serpro) * * Created on Feb 9, 2011 at 9:58:16 AM * */ public class CalendarTodayViewPage extends CalendarPage { public CalendarTodayViewPage(WebDriver driver) { super(driver); // TODO Auto-generated constructor stub } /** * Procura o "id" do compromisso baseado no titulo do mesmo. * * @param title * Titulo do compromisso. * @return "id" do compromisso. */ public String getAppointmentId(String title) { String source = driver.getPageSource(); int i = source.indexOf("\"title\":\"" + title); int j = source.indexOf("\"id\":", i); return source.substring(j + 5, source.indexOf(",", j)); } /** * Verifica se o horario do compromisso aparece na lista. * * @param startTime * @return */ public boolean isStartTimePresent(String startTime) { // Lista todos os horarios. boolean foundTime = false; List hours = driver.findElements(By .className("dhx_scale_hour")); for (WebElement h : hours) { if (h.getText().equals(startTime)) { foundTime = true; break; } } return foundTime; } /** * Procura o compromisso pelo titulo. * * @param title * @return */ public WebElement findAppointment(String title) { List elements = driver.findElements(By .className("dhx_title")); for (WebElement e : elements) { if (title.equals(e.getText())) { return e; } } return null; } /** * Verifica se o compromisso contido no elemento e eh do tipo individual. * * @param e * @return */ public boolean isSingle(WebElement e) { // Recupera o icone referente ao compromisso WebElement image = e.findElement(By.xpath("img")); return image.getAttribute("src").contains("single.png"); } /** * Verifica se o compromisso contido no elemento e eh do tipo restrito. * * @param e * @return */ public boolean isRestrict(WebElement e) { // Recupera o icone referente ao compromisso List images = e.findElements(By.xpath("img")); boolean restrictAppointment = false; for (WebElement ele : images) { if (ele.getAttribute("src").contains("private.png")) { return true; } } return restrictAppointment; } }