1
1
from django .contrib .staticfiles .testing import LiveServerTestCase
2
2
3
3
from django .db import IntegrityError
4
- from selenium .webdriver .support .ui import Select
4
+
5
+ from pom .locators .administratorReportPageLocators import *
6
+ from pom .pages .administratorReportPage import AdministratorReportPage
7
+ from pom .pages .authenticationPage import AuthenticationPage
5
8
6
9
from shift .utils import (
7
10
create_admin ,
@@ -24,19 +27,18 @@ class Report(LiveServerTestCase):
24
27
25
28
@classmethod
26
29
def setUpClass (cls ):
27
- cls .homepage = '/'
28
- cls .authentication_page = '/authentication/login/'
29
- cls .report_page = '/administrator/report/'
30
- cls .report_shift_summary_path = '//div[2]/div[4]'
31
-
32
30
cls .driver = webdriver .Firefox ()
33
31
cls .driver .implicitly_wait (5 )
34
32
cls .driver .maximize_window ()
33
+ cls .authentication_page = AuthenticationPage (cls .driver )
34
+ cls .report_page = AdministratorReportPage (cls .driver )
35
+ cls .elements = AdministratorReportPageLocators ()
35
36
super (Report , cls ).setUpClass ()
36
37
37
38
def setUp (self ):
38
39
create_admin ()
39
40
self .login_admin ()
41
+ self .report_page .go_to_admin_report ()
40
42
41
43
def tearDown (self ):
42
44
pass
@@ -47,56 +49,17 @@ def tearDownClass(cls):
47
49
super (Report , cls ).tearDownClass ()
48
50
49
51
def login_admin (self ):
50
- self .login ('admin' , 'admin' )
51
-
52
- def login (self , username , password ):
53
- self .driver .get (self .live_server_url + self .authentication_page )
54
- self .driver .find_element_by_id ('id_login' ).send_keys (username )
55
- self .driver .find_element_by_id ('id_password' ).send_keys (password )
56
- self .driver .find_element_by_xpath ('//form[1]' ).submit ()
57
-
58
- def logout (self ):
59
- self .driver .find_element_by_link_text ('Log Out' ).click ()
60
-
61
- def go_to_admin_report (self ):
62
- self .driver .find_element_by_link_text ('Report' ).click ()
63
-
64
- def fill_report_form (self , info ):
65
- self .driver .find_element_by_xpath (
66
- '//input[@name = "first_name"]' ).clear ()
67
- self .driver .find_element_by_xpath (
68
- '//input[@name = "last_name"]' ).clear ()
69
- [select1 , select2 , select3 ] = self .get_event_job_organization_selectors ()
70
-
71
- self .driver .find_element_by_xpath (
72
- '//input[@name = "first_name"]' ).send_keys (info [0 ])
73
- self .driver .find_element_by_xpath (
74
- '//input[@name = "last_name"]' ).send_keys (info [1 ])
75
-
76
- """select1.select_by_visible_text(info[2])
77
- select2.select_by_visible_text(info[3])
78
- select3.select_by_visible_text(info[4])"""
79
-
80
- self .driver .find_element_by_xpath ('//form[1]' ).submit ()
81
-
82
- def get_event_job_organization_selectors (self ):
83
- select1 = Select (self .driver .find_element_by_xpath ('//select[@name = "event_name"]' ))
84
- select2 = Select (self .driver .find_element_by_xpath ('//select[@name = "job_name"]' ))
85
- select3 = Select (self .driver .find_element_by_xpath ('//select[@name = "organization"]' ))
86
- return (select1 , select2 , select3 )
52
+ self .authentication_page .server_url = self .live_server_url
53
+ self .authentication_page .login ({ 'username' : 'admin' , 'password' : 'admin' })
87
54
88
55
def verify_shift_details (self , total_shifts , hours ):
89
- total_no_of_shifts = self .driver .find_element_by_xpath (
90
- self .report_shift_summary_path ).text .split (' ' )[10 ].strip ('\n Total' )
91
-
92
- total_no_of_hours = self .driver .find_element_by_xpath (
93
- self .report_shift_summary_path ).text .split (' ' )[- 1 ].strip ('\n ' )
94
-
56
+ total_no_of_shifts = self .report_page .get_shift_summary ().split (' ' )[10 ].strip ('\n Total' )
57
+ total_no_of_hours = self .report_page .get_shift_summary ().split (' ' )[- 1 ].strip ('\n ' )
95
58
self .assertEqual (total_no_of_shifts , total_shifts )
96
59
self .assertEqual (total_no_of_hours , hours )
97
60
98
61
#Failing test case which has been documented
99
- #Test commented out to prevent travis build failure
62
+ #Test commented out to prevent travis build failure - bug #327
100
63
101
64
"""def test_null_values_with_dataset(self):
102
65
# register dataset
@@ -120,28 +83,28 @@ def verify_shift_details(self, total_shifts, hours):
120
83
121
84
logged_shift = log_hours_with_details(volunteer, created_shift, "09:00", "12:00")
122
85
86
+ report_page = self.report_page
87
+
123
88
# check admin report with null fields, should return the above shift
124
- self.driver.get(self.live_server_url + self.report_page)
125
- self.fill_report_form(['','','','',''])
89
+ report_page.fill_report_form(['','','','',''])
126
90
self.verify_shift_details('1','3.0')
127
91
128
- self.assertEqual(self.driver.find_element_by_xpath (
129
- '//table//tbody//tr[1]//td[1]' ).text, created_event.name)
130
- self.assertEqual(self.driver.find_element_by_xpath (
131
- '//table//tbody//tr[1]//td[6]' ).text, 'Aug. 21, 2016')
132
- self.assertEqual(self.driver.find_element_by_xpath (
133
- '//table//tbody//tr[1]//td[7]' ).text, '9 a.m.')
134
- self.assertEqual(self.driver.find_element_by_xpath (
135
- '//table//tbody//tr[1]//td[8]' ).text, '12 p.m.')
136
- self.assertEqual(self.driver.find_element_by_xpath (
137
- '//table//tbody//tr[1]//td[9]' ).text, '3.0')"""
92
+ self.assertEqual(report_page.element_by_xpath (
93
+ self.elements.NAME ).text, created_event.name)
94
+ self.assertEqual(report_page.element_by_xpath (
95
+ self.elements.DATE ).text, 'Aug. 21, 2016')
96
+ self.assertEqual(report_page.element_by_xpath (
97
+ self.elements.START_TIME ).text, '9 a.m.')
98
+ self.assertEqual(report_page.element_by_xpath (
99
+ self.elements.END_TIME ).text, '12 p.m.')
100
+ self.assertEqual(report_page.element_by_xpath (
101
+ self.elements.HOURS ).text, '3.0')"""
138
102
139
103
def test_null_values_with_empty_dataset (self ):
140
104
# should return no entries
141
- self .go_to_admin_report ()
142
- self .fill_report_form (['' ,'' ,'' ,'' ,'' ])
143
- self .assertEqual (self .driver .find_element_by_class_name (
144
- 'alert-danger' ).text , 'Your criteria did not return any results.' )
105
+ report_page = self .report_page
106
+ report_page .fill_report_form (['' ,'' ,'' ,'' ,'' ])
107
+ self .assertEqual (report_page .get_alert_box_text (),report_page .no_results_message )
145
108
146
109
def test_only_logged_shifts_are_reported (self ):
147
110
# register dataset
@@ -165,47 +128,45 @@ def test_only_logged_shifts_are_reported(self):
165
128
# shift is assigned to volunteer-one, but hours have not been logged
166
129
volunteer_shift = register_volunteer_for_shift_utility (created_shift , volunteer )
167
130
131
+ report_page = self .report_page
168
132
# check admin report with null fields, should not return the above shift
169
- self .driver .get (self .live_server_url + self .report_page )
170
- self .fill_report_form (['' ,'' ,'' ,'' ,'' ])
171
- self .assertEqual (self .driver .find_element_by_class_name (
172
- 'alert-danger' ).text , 'Your criteria did not return any results.' )
133
+ report_page .fill_report_form (['' ,'' ,'' ,'' ,'' ])
134
+ self .assertEqual (report_page .get_alert_box_text (),report_page .no_results_message )
173
135
174
- #Failing test case which has been documented
136
+ #Failing test case which has been documented - bug #327
175
137
#Test commented out to prevent travis build failure
176
138
177
139
"""def test_check_intersection_of_fields(self):
178
140
179
141
self.create_dataset()
180
142
181
- self.login_admin()
182
- self.go_to_admin_report()
143
+ report_page = self.report_page
183
144
184
145
search_parameters_1 = ['tom','','','','']
185
- self .fill_report_form(search_parameters_1)
146
+ report_page .fill_report_form(search_parameters_1)
186
147
187
148
self.verify_shift_details('2','2.0')
188
149
189
150
search_parameters_2 = ['','','','','org-one']
190
- self .fill_report_form(search_parameters_2)
151
+ report_page .fill_report_form(search_parameters_2)
191
152
192
153
self.verify_shift_details('3','3.0')
193
154
194
155
search_parameters_3 = ['','','event-four','Two','']
195
- self .fill_report_form(search_parameters_3)
156
+ report_page .fill_report_form(search_parameters_3)
196
157
197
158
# 1 shift of 1:30 hrs
198
159
self.verify_shift_details('1','1.5')
199
160
200
161
search_parameters_4 = ['','','one','','']
201
- self .fill_report_form(search_parameters_4)
162
+ report_page .fill_report_form(search_parameters_4)
202
163
203
164
# 3 shifts of 0:30 hrs, 1:00 hrs, 1:00 hrs
204
165
self.verify_shift_details('3','2.5')
205
166
206
167
# check case-insensitive
207
168
search_parameters_5 = ['','sherlock','two','','']
208
- self .fill_report_form(search_parameters_5)
169
+ report_page .fill_report_form(search_parameters_5)
209
170
210
171
self.verify_shift_details('1','2.0')
211
172
0 commit comments