1 | package org.expressolivre.cte.common; |
---|
2 | |
---|
3 | import java.util.Calendar; |
---|
4 | |
---|
5 | import org.expressolivre.cte.pages.calendar.AgendaPermissionPage; |
---|
6 | import org.expressolivre.cte.pages.calendar.AppointmentCategoryPage; |
---|
7 | import org.expressolivre.cte.pages.calendar.AppointmentPage; |
---|
8 | import org.expressolivre.cte.pages.calendar.CalendarPage; |
---|
9 | import org.expressolivre.cte.pages.calendar.CalendarTodayViewPage; |
---|
10 | import org.expressolivre.cte.pages.common.HomePage; |
---|
11 | import org.openqa.selenium.support.PageFactory; |
---|
12 | import org.testng.annotations.BeforeMethod; |
---|
13 | |
---|
14 | /** |
---|
15 | * @author L.F.Estivalet (Serpro) |
---|
16 | * |
---|
17 | * Created on Feb 8, 2011 at 9:16:54 AM |
---|
18 | * |
---|
19 | */ |
---|
20 | public class BaseCalendarTestCase extends BaseTestCase { |
---|
21 | |
---|
22 | /** |
---|
23 | * Instancia da pagina do calendario utilizada pelos demais testes da |
---|
24 | * agenda. |
---|
25 | */ |
---|
26 | protected CalendarPage cp; |
---|
27 | |
---|
28 | /** |
---|
29 | * Antes dos demais testes do modulo do calendario serem iniciados, este |
---|
30 | * teste eh executado. Ele faz o login no Expresso e vai direto para a |
---|
31 | * pagina incial. Depois clica-se no modulo Calendario para entao |
---|
32 | * inicializar componentes da pagina. |
---|
33 | */ |
---|
34 | @BeforeMethod |
---|
35 | public void init() { |
---|
36 | HomePage hp = PageFactory.initElements(driver, HomePage.class); |
---|
37 | hp.enterCalendar(); |
---|
38 | cp = PageFactory.initElements(driver, CalendarPage.class); |
---|
39 | } |
---|
40 | |
---|
41 | /** |
---|
42 | * Abre visao diaria da agenda. |
---|
43 | * |
---|
44 | * @return Pagina da visao diaria da agenda. |
---|
45 | */ |
---|
46 | public CalendarTodayViewPage openTodayView() { |
---|
47 | cp.openTodayView(); |
---|
48 | return PageFactory.initElements(driver, CalendarTodayViewPage.class); |
---|
49 | } |
---|
50 | |
---|
51 | /** |
---|
52 | * Abre o visao diaria para uma data especifica. |
---|
53 | * |
---|
54 | * @param data |
---|
55 | * Data no formato yyyyMMdd. |
---|
56 | * @return |
---|
57 | */ |
---|
58 | public CalendarTodayViewPage openTodayView(String date) { |
---|
59 | return cp.openTodayView(date); |
---|
60 | } |
---|
61 | |
---|
62 | /** |
---|
63 | * Cria um novo compromisso. |
---|
64 | * |
---|
65 | * @param date |
---|
66 | * Data do compromisso. |
---|
67 | * @return Pagina para adicionar informacoes do compromisso. |
---|
68 | */ |
---|
69 | public AppointmentPage newAppointment(String date) { |
---|
70 | cp.openAppointmentPage(date); |
---|
71 | return PageFactory.initElements(driver, AppointmentPage.class); |
---|
72 | } |
---|
73 | |
---|
74 | /** |
---|
75 | * @return |
---|
76 | */ |
---|
77 | public AppointmentCategoryPage openAppointmentCategoryPage() { |
---|
78 | driver.get(URL |
---|
79 | + "/index.php?menuaction=preferences.uicategories.index&cats_app=calendar&cats_level=True&global_cats=True"); |
---|
80 | return PageFactory.initElements(driver, AppointmentCategoryPage.class); |
---|
81 | } |
---|
82 | |
---|
83 | /** |
---|
84 | * @return |
---|
85 | */ |
---|
86 | public AgendaPermissionPage openAgendaPermissionPage() { |
---|
87 | driver.get(URL |
---|
88 | + "/index.php?menuaction=preferences.uiaclprefs.index&acl_app=calendar"); |
---|
89 | return PageFactory.initElements(driver, AgendaPermissionPage.class); |
---|
90 | } |
---|
91 | |
---|
92 | /** |
---|
93 | * @param cal |
---|
94 | * @return Nome do mes concatenado com o nome do ano. Exemplo: Agosto 2011 |
---|
95 | */ |
---|
96 | private String getMonthYearName(Calendar cal) { |
---|
97 | String[] monthName = { "Janeiro", "Fevereiro", "Março", "Abril", |
---|
98 | "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", |
---|
99 | "Novembro", "Dezembro" }; |
---|
100 | |
---|
101 | String month = monthName[cal.get(Calendar.MONTH)]; |
---|
102 | Integer year = cal.get(Calendar.YEAR); |
---|
103 | |
---|
104 | return month + " " + year; |
---|
105 | |
---|
106 | } |
---|
107 | |
---|
108 | /** |
---|
109 | * @return O nome por extenso do mes concatenado com o ano corrente. |
---|
110 | */ |
---|
111 | public String getCurrentMonthYearName() { |
---|
112 | return this.getMonthYearName(Calendar.getInstance()); |
---|
113 | } |
---|
114 | |
---|
115 | /** |
---|
116 | * @return O nome por extenso do mes anterior concatenado com o ano; |
---|
117 | */ |
---|
118 | public String getPreviousMonthYearName() { |
---|
119 | Calendar cal = Calendar.getInstance(); |
---|
120 | cal.add(Calendar.MONTH, -1); |
---|
121 | |
---|
122 | return this.getMonthYearName(cal); |
---|
123 | } |
---|
124 | |
---|
125 | public String getNextMonthYearName(Calendar cal) { |
---|
126 | cal.add(Calendar.MONTH, 1); |
---|
127 | |
---|
128 | return this.getMonthYearName(cal); |
---|
129 | } |
---|
130 | |
---|
131 | /** |
---|
132 | * @return |
---|
133 | */ |
---|
134 | public String getNextMonthYearName() { |
---|
135 | return getNextMonthYearName(Calendar.getInstance()); |
---|
136 | } |
---|
137 | |
---|
138 | } |
---|