1 | package org.expressolivre.cte.pages.calendar; |
---|
2 | |
---|
3 | import java.util.List; |
---|
4 | |
---|
5 | import org.expressolivre.cte.pages.common.Page; |
---|
6 | import org.openqa.selenium.Alert; |
---|
7 | import org.openqa.selenium.By; |
---|
8 | import org.openqa.selenium.WebDriver; |
---|
9 | import org.openqa.selenium.WebElement; |
---|
10 | import org.openqa.selenium.support.FindBy; |
---|
11 | import org.openqa.selenium.support.PageFactory; |
---|
12 | import org.testng.Assert; |
---|
13 | |
---|
14 | /** |
---|
15 | * @author L.F.Estivalet (Serpro) |
---|
16 | * |
---|
17 | * Created on Jul 25, 2011 at 2:25:28 PM |
---|
18 | * |
---|
19 | */ |
---|
20 | public class AppointmentViewPage extends Page { |
---|
21 | |
---|
22 | public static final String DESCRIPTION = "Descrição:"; |
---|
23 | public static final String LOCAL = "Localização:"; |
---|
24 | public static final String START = "InÃcio Data/hora:"; |
---|
25 | public static final String END = "Data/Hora de término:"; |
---|
26 | public static final String PRIORITY = "Prioridade:"; |
---|
27 | public static final String ACCESS = "Acesso:"; |
---|
28 | public static final String PARTICIPANTS = "Participantes:"; |
---|
29 | public static final String CREATED_BY = "Criado por:"; |
---|
30 | public static final String UPDATED = "Atualizado:"; |
---|
31 | public static final String LAST_UPDATED_BY = "Ãltima alteração realizada por:"; |
---|
32 | public static final String ATTACHMENTS = "Anexos:"; |
---|
33 | |
---|
34 | /** Botao para editar um compromisso. */ |
---|
35 | @FindBy(xpath = "//table[@id='calendar_viewevent_button_left']/tbody/tr/td[1]/nobr/form/div/input[@id='']") |
---|
36 | private WebElement editButton; |
---|
37 | |
---|
38 | /** Botao para editar serie de compromissos. */ |
---|
39 | @FindBy(xpath = "//table[@id='calendar_viewevent_button_left']/tbody/tr/td[2]/nobr/form/div/input[@id='']") |
---|
40 | private WebElement editSeriesButton; |
---|
41 | |
---|
42 | @FindBy(xpath = "//table[@id='calendar_viewevent_button_left']/tbody/tr/td[2]/nobr/form/div/input[@id='']") |
---|
43 | private WebElement readyButton; |
---|
44 | |
---|
45 | @FindBy(xpath = "//table[@id='calendar_viewevent_button_right']/tbody/tr/td/nobr/form/div/input[@id='']") |
---|
46 | private WebElement removeButton; |
---|
47 | |
---|
48 | @FindBy(xpath = "//table[@id='calendar_viewevent_button_right']/tbody/tr/td[2]/nobr/form/div/input[@id='']") |
---|
49 | private WebElement removeSeriesButton; |
---|
50 | |
---|
51 | @FindBy(xpath = "//table[@id='calendar_view_event']/tbody/tr[1]/td[2]") |
---|
52 | private WebElement title; |
---|
53 | |
---|
54 | public AppointmentViewPage(WebDriver driver) { |
---|
55 | super(driver); |
---|
56 | // TODO Auto-generated constructor stub |
---|
57 | } |
---|
58 | |
---|
59 | /** |
---|
60 | * Edita o compromisso previamente selecionado. |
---|
61 | * |
---|
62 | * @return Retorna pagina de edicao do compromisso. |
---|
63 | */ |
---|
64 | public AppointmentEditPage editAppointment() { |
---|
65 | this.editButton.click(); |
---|
66 | return PageFactory.initElements(driver, AppointmentEditPage.class); |
---|
67 | |
---|
68 | } |
---|
69 | |
---|
70 | /** |
---|
71 | * Edita a serie de compromissos previamente selecionado. |
---|
72 | * |
---|
73 | * @return Retorna pagina de edicao do compromisso. |
---|
74 | */ |
---|
75 | public AppointmentEditPage editAppointmentSeries() { |
---|
76 | this.editSeriesButton.click(); |
---|
77 | return PageFactory.initElements(driver, AppointmentEditPage.class); |
---|
78 | |
---|
79 | } |
---|
80 | |
---|
81 | /** |
---|
82 | * Remove um compromisso. |
---|
83 | */ |
---|
84 | public void removeAppointment() { |
---|
85 | this.removeButton.click(); |
---|
86 | this.removeAlert(); |
---|
87 | } |
---|
88 | |
---|
89 | /** |
---|
90 | * |
---|
91 | */ |
---|
92 | public void ready() { |
---|
93 | this.readyButton.click(); |
---|
94 | } |
---|
95 | |
---|
96 | /** |
---|
97 | * Remove a serie de compromissos. |
---|
98 | */ |
---|
99 | public void removeSeriesAppointment() { |
---|
100 | this.removeSeriesButton.click(); |
---|
101 | this.removeAlert(); |
---|
102 | } |
---|
103 | |
---|
104 | /** |
---|
105 | * Exibe alerta ao tentar remover um compromisso. |
---|
106 | */ |
---|
107 | private void removeAlert() { |
---|
108 | Alert alert = driver.switchTo().alert(); |
---|
109 | Assert.assertEquals( |
---|
110 | alert.getText(), |
---|
111 | "Tem certeza que deseja remover esta entrada?\nIsto irá remover esta entrada para todos usuários."); |
---|
112 | alert.accept(); |
---|
113 | } |
---|
114 | |
---|
115 | /** |
---|
116 | * @return the title |
---|
117 | */ |
---|
118 | public String getTitle() { |
---|
119 | return title.getText(); |
---|
120 | } |
---|
121 | |
---|
122 | /** |
---|
123 | * Percorre a tabela em busca da informacao desejada. |
---|
124 | * |
---|
125 | * @param label |
---|
126 | * Informa o label procurado. Ex: "Descrição". |
---|
127 | * @return Retorna o valor correspondente ao label encontrado. Se label nao |
---|
128 | * for encontrado retorna <code>null</code>. |
---|
129 | */ |
---|
130 | public String getAppointmentInfo(String label) { |
---|
131 | List<WebElement> rows = driver.findElements(By |
---|
132 | .xpath("//table[@id='calendar_view_event']/tbody/tr")); |
---|
133 | // Comeca a partir da linha 2 pois a linha eh sempre o titulo do |
---|
134 | // compromisso. |
---|
135 | for (int i = 2; i <= rows.size(); i++) { |
---|
136 | WebElement row = driver.findElement(By |
---|
137 | .xpath("//table[@id='calendar_view_event']/tbody/tr[" + i |
---|
138 | + "]/td[1]")); |
---|
139 | // Se o label for encontrado entao pega o valor encontrado na |
---|
140 | // segunda coluna da tabela. |
---|
141 | if (label.equals(row.getText())) { |
---|
142 | return driver.findElement( |
---|
143 | By.xpath("//table[@id='calendar_view_event']/tbody/tr[" |
---|
144 | + i + "]/td[2]")).getText(); |
---|
145 | } |
---|
146 | } |
---|
147 | return null; |
---|
148 | } |
---|
149 | } |
---|