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_right']/tbody/tr/td/nobr/form/div/input[@id='']") |
---|
43 | private WebElement removeButton; |
---|
44 | |
---|
45 | @FindBy(xpath = "//table[@id='calendar_viewevent_button_right']/tbody/tr/td[2]/nobr/form/div/input[@id='']") |
---|
46 | private WebElement removeSeriesButton; |
---|
47 | |
---|
48 | @FindBy(xpath = "//table[@id='calendar_view_event']/tbody/tr[1]/td[2]") |
---|
49 | private WebElement title; |
---|
50 | |
---|
51 | public AppointmentViewPage(WebDriver driver) { |
---|
52 | super(driver); |
---|
53 | // TODO Auto-generated constructor stub |
---|
54 | } |
---|
55 | |
---|
56 | /** |
---|
57 | * Edita o compromisso previamente selecionado. |
---|
58 | * |
---|
59 | * @return Retorna pagina de edicao do compromisso. |
---|
60 | */ |
---|
61 | public AppointmentEditPage editAppointment() { |
---|
62 | this.editButton.click(); |
---|
63 | return PageFactory.initElements(driver, AppointmentEditPage.class); |
---|
64 | |
---|
65 | } |
---|
66 | |
---|
67 | /** |
---|
68 | * Edita a serie de compromissos previamente selecionado. |
---|
69 | * |
---|
70 | * @return Retorna pagina de edicao do compromisso. |
---|
71 | */ |
---|
72 | public AppointmentEditPage editAppointmentSeries() { |
---|
73 | this.editSeriesButton.click(); |
---|
74 | return PageFactory.initElements(driver, AppointmentEditPage.class); |
---|
75 | |
---|
76 | } |
---|
77 | |
---|
78 | /** |
---|
79 | * Remove um compromisso. |
---|
80 | */ |
---|
81 | public void removeAppointment() { |
---|
82 | this.removeButton.click(); |
---|
83 | this.removeAlert(); |
---|
84 | } |
---|
85 | |
---|
86 | /** |
---|
87 | * Remove a serie de compromissos. |
---|
88 | */ |
---|
89 | public void removeSeriesAppointment() { |
---|
90 | this.removeSeriesButton.click(); |
---|
91 | this.removeAlert(); |
---|
92 | } |
---|
93 | |
---|
94 | /** |
---|
95 | * Exibe alerta ao tentar remover um compromisso. |
---|
96 | */ |
---|
97 | private void removeAlert() { |
---|
98 | Alert alert = driver.switchTo().alert(); |
---|
99 | Assert.assertEquals( |
---|
100 | alert.getText(), |
---|
101 | "Tem certeza que deseja remover esta entrada?\nIsto irá remover esta entrada para todos usuários."); |
---|
102 | alert.accept(); |
---|
103 | } |
---|
104 | |
---|
105 | /** |
---|
106 | * @return the title |
---|
107 | */ |
---|
108 | public String getTitle() { |
---|
109 | return title.getText(); |
---|
110 | } |
---|
111 | |
---|
112 | /** |
---|
113 | * Percorre a tabela em busca da informacao desejada. |
---|
114 | * |
---|
115 | * @param label |
---|
116 | * Informa o label procurado. Ex: "Descrição". |
---|
117 | * @return Retorna o valor correspondente ao label encontrado. Se label nao |
---|
118 | * for encontrado retorna <code>null</code>. |
---|
119 | */ |
---|
120 | public String getAppointmentInfo(String label) { |
---|
121 | List<WebElement> rows = driver.findElements(By |
---|
122 | .xpath("//table[@id='calendar_view_event']/tbody/tr")); |
---|
123 | // Comeca a partir da linha 2 pois a linha eh sempre o titulo do |
---|
124 | // compromisso. |
---|
125 | for (int i = 2; i <= rows.size(); i++) { |
---|
126 | WebElement row = driver.findElement(By |
---|
127 | .xpath("//table[@id='calendar_view_event']/tbody/tr[" + i |
---|
128 | + "]/td[1]")); |
---|
129 | // Se o label for encontrado entao pega o valor encontrado na |
---|
130 | // segunda coluna da tabela. |
---|
131 | if (label.equals(row.getText())) { |
---|
132 | return driver.findElement( |
---|
133 | By.xpath("//table[@id='calendar_view_event']/tbody/tr[" |
---|
134 | + i + "]/td[2]")).getText(); |
---|
135 | } |
---|
136 | } |
---|
137 | return null; |
---|
138 | } |
---|
139 | } |
---|