package org.expressolivre.cte.pages.calendar; 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 Aug 10, 2011 at 1:49:11 PM * */ public class AppointmentCategoryPage extends Page { /** Botao para adicionar nova categoria. */ @FindBy(xpath = "//table[@id='tableDivAppbox']/tbody/tr/td/center/table[3]/tbody/tr/td[1]/form/input") private WebElement addCategory; @FindBy(name = "query") private WebElement searchText; @FindBy(name = "search") private WebElement searchCategory; /** * @param driver */ public AppointmentCategoryPage(WebDriver driver) { super(driver); // TODO Auto-generated constructor stub } /** * @param text */ public void setSearchText(String text) { this.searchText.clear(); this.searchText.sendKeys(text); } /** * */ public AppointmentCategoryPage startSearch() { this.searchCategory.click(); return PageFactory.initElements(driver, AppointmentCategoryPage.class); } /** * Vai para a tela de adicao de categorias. */ public AddAppointmentCategoryPage addCategory() { this.addCategory.submit(); return PageFactory.initElements(driver, AddAppointmentCategoryPage.class); } /** * Procura pelo nome da categoria na tabela que lista as categorias. * * @param name * Nome da categoria a procurar. * */ public Integer findCategory(String name) { String rowsPath = "//table[@id='tableDivAppbox']/tbody/tr/td/center/table[2]/tbody/tr"; int totalLinhas = super.getXPathCount(rowsPath); for (int i = 1; i <= totalLinhas; i++) { WebElement row = driver.findElement(By.xpath(rowsPath + "[" + i + "]/td[1]")); // Se achar a categoria retorna o id if (name.equals(row.getText())) { String catId = driver.findElement( By.xpath(rowsPath + "[" + i + "]/td[5]/a")) .getAttribute("href"); return Integer .parseInt(catId.substring(catId.lastIndexOf("=") + 1)); } } return null; } /** * @param name * @return Retorna a linha da tabela onde foi encontrada a categoria. */ public Integer getCategoryRow(String name) { String rowsPath = "//table[@id='tableDivAppbox']/tbody/tr/td/center/table[2]/tbody/tr"; int totalLinhas = super.getXPathCount(rowsPath); for (int i = 1; i <= totalLinhas; i++) { WebElement row = driver.findElement(By.xpath(rowsPath + "[" + i + "]/td[1]")); // Se achar a categoria retorna o id if (name.equals(row.getText())) { return i; } } return null; } /** * @param categoryId * @return */ public EditAppointmentCategoryPage editCategory(String name) { Integer row = getCategoryRow(name); String rowsPath = "//table[@id='tableDivAppbox']/tbody/tr/td/center/table[2]/tbody/tr"; driver.findElement(By.xpath(rowsPath + "[" + row + "]/td[5]/a")) .click(); return PageFactory.initElements(driver, EditAppointmentCategoryPage.class); } /** * @param categoryId * @return */ public RemoveAppointmentCategoryPage removeCategory(String name) { Integer row = getCategoryRow(name); String rowsPath = "//table[@id='tableDivAppbox']/tbody/tr/td/center/table[2]/tbody/tr"; driver.findElement(By.xpath(rowsPath + "[" + row + "]/td[6]/a")) .click(); return PageFactory.initElements(driver, RemoveAppointmentCategoryPage.class); } }