1 | package org.expressolivre.cte.pages.calendar; |
---|
2 | |
---|
3 | import org.expressolivre.cte.pages.common.Page; |
---|
4 | import org.openqa.selenium.By; |
---|
5 | import org.openqa.selenium.WebDriver; |
---|
6 | import org.openqa.selenium.WebElement; |
---|
7 | import org.openqa.selenium.support.FindBy; |
---|
8 | import org.openqa.selenium.support.PageFactory; |
---|
9 | |
---|
10 | /** |
---|
11 | * @author L.F.Estivalet (Serpro) |
---|
12 | * |
---|
13 | * Created on Aug 10, 2011 at 1:49:11 PM |
---|
14 | * |
---|
15 | */ |
---|
16 | public class AppointmentCategoryPage extends Page { |
---|
17 | |
---|
18 | /** Botao para adicionar nova categoria. */ |
---|
19 | @FindBy(xpath = "//table[@id='tableDivAppbox']/tbody/tr/td/center/table[3]/tbody/tr/td[1]/form/input") |
---|
20 | private WebElement addCategory; |
---|
21 | |
---|
22 | @FindBy(name = "query") |
---|
23 | private WebElement searchText; |
---|
24 | |
---|
25 | @FindBy(name = "search") |
---|
26 | private WebElement searchCategory; |
---|
27 | |
---|
28 | /** |
---|
29 | * @param driver |
---|
30 | */ |
---|
31 | public AppointmentCategoryPage(WebDriver driver) { |
---|
32 | super(driver); |
---|
33 | // TODO Auto-generated constructor stub |
---|
34 | } |
---|
35 | |
---|
36 | /** |
---|
37 | * @param text |
---|
38 | */ |
---|
39 | public void setSearchText(String text) { |
---|
40 | this.searchText.clear(); |
---|
41 | this.searchText.sendKeys(text); |
---|
42 | } |
---|
43 | |
---|
44 | /** |
---|
45 | * |
---|
46 | */ |
---|
47 | public AppointmentCategoryPage startSearch() { |
---|
48 | this.searchCategory.click(); |
---|
49 | return PageFactory.initElements(driver, AppointmentCategoryPage.class); |
---|
50 | } |
---|
51 | |
---|
52 | /** |
---|
53 | * Vai para a tela de adicao de categorias. |
---|
54 | */ |
---|
55 | public AddAppointmentCategoryPage addCategory() { |
---|
56 | this.addCategory.submit(); |
---|
57 | return PageFactory.initElements(driver, |
---|
58 | AddAppointmentCategoryPage.class); |
---|
59 | } |
---|
60 | |
---|
61 | /** |
---|
62 | * Procura pelo nome da categoria na tabela que lista as categorias. |
---|
63 | * |
---|
64 | * @param name |
---|
65 | * Nome da categoria a procurar. |
---|
66 | * |
---|
67 | */ |
---|
68 | public Integer findCategory(String name) { |
---|
69 | String rowsPath = "//table[@id='tableDivAppbox']/tbody/tr/td/center/table[2]/tbody/tr"; |
---|
70 | int totalLinhas = super.getXPathCount(rowsPath); |
---|
71 | for (int i = 1; i <= totalLinhas; i++) { |
---|
72 | WebElement row = driver.findElement(By.xpath(rowsPath + "[" + i |
---|
73 | + "]/td[1]")); |
---|
74 | // Se achar a categoria retorna o id |
---|
75 | if (name.equals(row.getText())) { |
---|
76 | String catId = driver.findElement( |
---|
77 | By.xpath(rowsPath + "[" + i + "]/td[5]/a")) |
---|
78 | .getAttribute("href"); |
---|
79 | return Integer |
---|
80 | .parseInt(catId.substring(catId.lastIndexOf("=") + 1)); |
---|
81 | } |
---|
82 | |
---|
83 | } |
---|
84 | return null; |
---|
85 | } |
---|
86 | |
---|
87 | /** |
---|
88 | * @param name |
---|
89 | * @return Retorna a linha da tabela onde foi encontrada a categoria. |
---|
90 | */ |
---|
91 | public Integer getCategoryRow(String name) { |
---|
92 | String rowsPath = "//table[@id='tableDivAppbox']/tbody/tr/td/center/table[2]/tbody/tr"; |
---|
93 | int totalLinhas = super.getXPathCount(rowsPath); |
---|
94 | for (int i = 1; i <= totalLinhas; i++) { |
---|
95 | WebElement row = driver.findElement(By.xpath(rowsPath + "[" + i |
---|
96 | + "]/td[1]")); |
---|
97 | // Se achar a categoria retorna o id |
---|
98 | if (name.equals(row.getText())) { |
---|
99 | return i; |
---|
100 | } |
---|
101 | |
---|
102 | } |
---|
103 | return null; |
---|
104 | } |
---|
105 | |
---|
106 | /** |
---|
107 | * @param categoryId |
---|
108 | * @return |
---|
109 | */ |
---|
110 | public EditAppointmentCategoryPage editCategory(String name) { |
---|
111 | Integer row = getCategoryRow(name); |
---|
112 | String rowsPath = "//table[@id='tableDivAppbox']/tbody/tr/td/center/table[2]/tbody/tr"; |
---|
113 | driver.findElement(By.xpath(rowsPath + "[" + row + "]/td[5]/a")) |
---|
114 | .click(); |
---|
115 | return PageFactory.initElements(driver, |
---|
116 | EditAppointmentCategoryPage.class); |
---|
117 | } |
---|
118 | |
---|
119 | /** |
---|
120 | * @param categoryId |
---|
121 | * @return |
---|
122 | */ |
---|
123 | public RemoveAppointmentCategoryPage removeCategory(String name) { |
---|
124 | Integer row = getCategoryRow(name); |
---|
125 | String rowsPath = "//table[@id='tableDivAppbox']/tbody/tr/td/center/table[2]/tbody/tr"; |
---|
126 | driver.findElement(By.xpath(rowsPath + "[" + row + "]/td[6]/a")) |
---|
127 | .click(); |
---|
128 | return PageFactory.initElements(driver, |
---|
129 | RemoveAppointmentCategoryPage.class); |
---|
130 | } |
---|
131 | |
---|
132 | } |
---|