package org.expressolivre.cte.pages.calendar; import java.util.List; import org.expressolivre.cte.pages.common.Page; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.PageFactory; /** * @author L.F.Estivalet (Serpro) * * Created on Feb 8, 2011 at 9:19:20 AM * */ public class AppointmentPage extends Page { /** Mensagens de validacao do formulario. */ @FindBy(id = "formStatus") private WebElement formStatus; /** Tipo do evento. */ @FindBy(id = "cal[type]") private WebElement type; /** Titulo do evento. */ @FindBy(name = "cal[title]") private WebElement title; /** Descrição completa do evento. */ @FindBy(name = "cal[description]") private WebElement description; /** Categorias do evento. */ @FindBy(name = "categories[]") private WebElement categories; /** Localização do evento. */ @FindBy(name = "cal[location]") private WebElement location; /** Data inicial do evento. */ @FindBy(name = "start[str]") private WebElement startDate; /** Hora inicial do evento. */ @FindBy(id = "start_hour") private WebElement startHour; /** Minuto inicial do evento; */ @FindBy(id = "start_minute") private WebElement startMinute; /** Data final do evento. */ @FindBy(name = "end[str]") private WebElement endDate; /** Hora final do evento. */ @FindBy(id = "end_hour") private WebElement endHour; /** Minuto final do evento; */ @FindBy(id = "end_minute") private WebElement endMinute; /** Prioridade do evento. */ @FindBy(name = "cal[priority]") private WebElement priority; @FindBy(id = "combo_org") private WebElement organization; @FindBy(id = "cal_input_searchUser") private WebElement searchUser; @FindBy(id = "user_list_in") private WebElement userList; @FindBy(xpath = "//table[@id='editFormTable']/tbody/tr[12]/td[2]/table[1]/tbody/tr[2]/td[3]/button[1]") private WebElement addUser; @FindBy(id = "usuarioParticipa") private WebElement includeUser; /** Alarme dia. */ @FindBy(name = "cal[alarmdays]") private WebElement alarmDays; /** Alarme hora. */ @FindBy(name = "cal[alarmhours]") private WebElement alarmHours; /** Alarme minuto. */ @FindBy(name = "cal[alarmminutes]") private WebElement alarmMinutes; /** Tipo recursao. */ @FindBy(name = "cal[recur_type]") private WebElement recurType; @FindBy(name = "cal[rpt_use_end]") private WebElement rptUseEnd; @FindBy(name = "recur_enddate[str]") private WebElement recurEndDate; @FindBy(name = "cal[recur_interval]") private WebElement recurInterval; /** Observacao. */ @FindBy(name = "cal[#Observação]") private WebElement notes; /** Salvar. */ @FindBy(id = "submit_button") private WebElement save; public AppointmentPage(WebDriver driver) { super(driver); // TODO Auto-generated constructor stub } /** * @return Retorna o texto de validacao do formulario. */ public String getFormStatus() { return this.formStatus.getText(); } /** * @param type * the type to set */ public void setType(String type) { super.setComboValue(this.type, type); } /** * @param title * the title to set */ public void setTitle(String title) { this.title.clear(); this.title.sendKeys(title); } /** * @param description * the description to set */ public void setDescription(String description) { this.description.clear(); this.description.sendKeys(description); } /** * @param categories * the categories to set */ public void setCategories(String categories) { super.setComboValue(this.categories, categories); } /** * @param categories */ public void setCategories(String[] categories) { for (String cat : categories) { super.setComboValue(this.categories, cat); } } /** * @param location * the location to set */ public void setLocation(String location) { this.location.clear(); this.location.sendKeys(location); } /** * @param startDate * the start to set */ public void setStartDate(String startDate) { this.startDate.clear(); this.startDate.sendKeys(startDate); } /** * @param startHour * the startHour to set */ public void setStartHour(String startHour) { this.startHour.clear(); this.startHour.sendKeys(startHour); } /** * @param startMinute * the startMinute to set */ public void setStartMinute(String startMinute) { this.startMinute.clear(); this.startMinute.sendKeys(startMinute); } /** * @param endDate * the end to set */ public void setEndDate(String endDate) { this.endDate.clear(); this.endDate.sendKeys(endDate); } /** * @param endHour * the endHour to set */ public void setEndHour(String endHour) { this.endHour.clear(); this.endHour.sendKeys(endHour); } /** * @param endMinute * the endMinute to set */ public void setEndMinute(String endMinute) { this.endMinute.clear(); this.endMinute.sendKeys(endMinute); } /** * @param priority * the priority to set */ public void setPriority(String priority) { super.setComboValue(this.priority, priority); } /** * Inclui/Exclui usuario criador do compromisso. * * @param include * true para incluir usuario, false * para excluir. */ public void setIncludeUser(Boolean include) { if (include && !this.includeUser.isSelected()) { this.includeUser.click(); } if (!include && this.includeUser.isSelected()) { this.includeUser.click(); } } /** * @param notes * the notes to set */ public void setNotes(String notes) { this.notes.clear(); this.notes.sendKeys(notes); } /** * @param alarmDays * the alarmDays to set */ public void setAlarmDays(String alarmDays) { super.setComboValue(this.alarmDays, alarmDays); } /** * @param alarmHours * the alarmHours to set */ public void setAlarmHours(String alarmHours) { super.setComboValue(this.alarmHours, alarmHours); } /** * @param alarmMinutes * the alarmMinutes to set */ public void setAlarmMinutes(String alarmMinutes) { super.setComboValue(this.alarmMinutes, alarmMinutes); } /** * @param recurType * the recurType to set */ public void setRecurType(String recurType) { super.setComboValue(this.recurType, recurType); } public void setRptUseEnd(String finalDate) { super.waitForElement(By.name("cal[rpt_use_end]")); this.rptUseEnd.click(); this.recurEndDate.clear(); this.recurEndDate.sendKeys(finalDate); } /** * Valores para os dias da semana: * *
	 * 1 - Domingo
	 * 2 - Segunda
	 * 4 - Terça
	 * 8 - Quarta
	 * 16 - Quinta
	 * 32 - Sexta
	 * 64 - Sabado
	 * 
* * @param values */ public void setRecurDays(List values) { List elements = driver.findElements(By .name("cal[rpt_day][]")); for (WebElement e : elements) { if (values.contains(e.getValue())) { e.click(); } } } /** * Salva o compromisso. */ public void saveAppointment() { this.save.click(); } /** * Salva o compromisso, mas este ira causar um conflito. * * @return Pagina para resolver conflito de agenda. */ public AppointmentConflictPage saveConflictAppointment() { this.saveAppointment(); return PageFactory.initElements(driver, AppointmentConflictPage.class); } /** * Adiciona um anexo ao compromisso. * * @param num * Numero sequencial, 1 para o primeiro anexo, 2 para o segundo e * assim sucessivamente. * @param fileName * Caminho completo para o arquivo anexo. */ public void addAttachment(Integer num, String fileName) { driver.findElement( By.xpath("//table[@id='editFormTable']/tbody/tr[21]/td[2]/a")) .click(); WebElement attachment = driver.findElement(By.id("inputFile_" + num)); attachment.sendKeys(fileName); } /** * Procura por um usuario para adicionar ao compromisso. * * @param name * Nome do usuario a procurar. */ public void searchUser(String name) { this.searchUser.clear(); this.searchUser.sendKeys(name); // Espera pelo "Carregando..." aparecer. waitForElement(By.id("divProgressBar")); // Espera pelo "Carregando..." desaparecer. isNotDisplayed(this .waitFindElement(By.id("divProgressBar"), 5000, 1000)); } /** * Seleciona o nome do usuario na lista de usuarios retornados pela * pesquisa. * * @param name * Nome do usuario para selecionar. */ public void selectUser(String name) { super.setComboValue(this.userList, name); } /** * Adiciona usuario ao compromisso. */ public void addUser() { this.addUser.click(); } }