Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Copyright (C) 2017 Catalyst IT |
6 |
# |
7 |
# Koha is free software; you can redistribute it and/or modify it |
8 |
# under the terms of the GNU General Public License as published by |
9 |
# the Free Software Foundation; either version 3 of the License, or |
10 |
# (at your option) any later version. |
11 |
# |
12 |
# Koha is distributed in the hope that it will be useful, but |
13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
# GNU General Public License for more details. |
16 |
# |
17 |
# You should have received a copy of the GNU General Public License |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
20 |
#This selenium test tests the Koha Administration module functionality including adding circ rules, item types and modifying frameworks |
21 |
|
22 |
#Note: If you are testing this on kohadevbox with selenium installed in kohadevbox then you need to set the staffClientBaseURL to localhost:8080 and the OPACBaseURL to http://localhost:80 |
23 |
|
24 |
use Modern::Perl; |
25 |
|
26 |
use Time::HiRes qw(gettimeofday); |
27 |
use C4::Context; |
28 |
use C4::Biblio qw( AddBiblio ); # We shouldn't use it |
29 |
|
30 |
use Test::More tests => 1; |
31 |
use MARC::Record; |
32 |
use MARC::Field; |
33 |
|
34 |
my $dbh = C4::Context->dbh; |
35 |
my $login = 'koha'; |
36 |
my $password = 'koha'; |
37 |
my $base_url= 'http://'.C4::Context->preference("staffClientBaseURL")."/cgi-bin/koha/"; |
38 |
my $opac_url= C4::Context->preference("OPACBaseURL"); |
39 |
|
40 |
our $sample_data = { |
41 |
category => { |
42 |
categorycode => 'test_cat', |
43 |
description => 'test cat description', |
44 |
enrolmentperiod => '12', |
45 |
category_type => 'A' |
46 |
}, |
47 |
patron => { |
48 |
surname => 'test_patron_surname', |
49 |
cardnumber => '4242424242', |
50 |
userid => 'test_username', |
51 |
password => 'password', |
52 |
password2 => 'password' |
53 |
}, |
54 |
}; |
55 |
|
56 |
my $patronusername="test_username"; |
57 |
my $patronpassword="password"; |
58 |
|
59 |
our ( $borrowernumber, $start, $prev_time, $cleanup_needed ); |
60 |
|
61 |
SKIP: { |
62 |
eval { require Selenium::Remote::Driver; }; |
63 |
skip "Selenium::Remote::Driver is needed for selenium tests.", 20 if $@; |
64 |
|
65 |
$cleanup_needed = 1; |
66 |
|
67 |
open my $fh, '>>', '/tmp/output.txt'; |
68 |
|
69 |
my $driver = Selenium::Remote::Driver->new; |
70 |
$start = gettimeofday; |
71 |
$prev_time = $start; |
72 |
$driver->get($base_url."mainpage.pl"); |
73 |
like( $driver->get_title(), qr(Log in to Koha), ); |
74 |
auth( $driver, $login, $password ); |
75 |
time_diff("main"); |
76 |
|
77 |
# Navigate to the Administration area and create an item type |
78 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[1]/div[2]/div/ul/li[5]/a')->click; |
79 |
$driver->pause(20000); |
80 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[2]/div[1]/dl[1]/dt[2]/a')->click; |
81 |
$driver->pause(20000); |
82 |
$driver->find_element('//a[@id="newitemtype"]')->click; |
83 |
$driver->pause(20000); |
84 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol[1]/li[1]/input')->send_keys("DVD"); |
85 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol[1]/li[2]/input')->send_keys("Digital Optical Disc"); |
86 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[2]/input')->click; |
87 |
if ( $driver->find_element('//a[@href="/cgi-bin/koha/admin/itemtypes.pl?op=add_form&itemtype=DVD"]')) { |
88 |
time_diff("Item type successfully added"); |
89 |
} else { |
90 |
time_diff("Item type not added successfully"); |
91 |
} |
92 |
|
93 |
# Add circulation/fine rules |
94 |
$driver->pause(20000); |
95 |
$driver->find_element_by_xpath('/html/body/div[3]/a[2]')->click; |
96 |
$driver->pause(20000); |
97 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[2]/div[1]/dl[2]/dt[2]/a')->click; |
98 |
$driver->pause(20000); |
99 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[2]/form[3]/table/tbody/tr[2]/td[3]/input')->send_keys("5"); |
100 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[2]/form[3]/table/tbody/tr[2]/td[4]/input')->send_keys("4"); |
101 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[2]/form[3]/table/tbody/tr[2]/td[16]/input')->send_keys("4"); |
102 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[2]/form[3]/table/tbody/tr[2]/td[17]/input')->send_keys("10"); |
103 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[2]/form[3]/table/tbody/tr[2]/td[22]/input')->send_keys("4"); |
104 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[2]/form[3]/table/tbody/tr[2]/td[23]/input')->send_keys("4"); |
105 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[2]/form[3]/table/tbody/tr[2]/td[28]/button[1]')->click; |
106 |
time_diff("Circulation rule added"); |
107 |
|
108 |
# Modify frameworks |
109 |
$driver->pause(20000); |
110 |
$driver->find_element_by_xpath('/html/body/div[3]/a[2]')->click; |
111 |
$driver->pause(20000); |
112 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[2]/div[2]/dl[1]/dt[1]/a')->click; |
113 |
$driver->pause(20000); |
114 |
warn $driver->get_title(); |
115 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[2]/table/tbody/tr[5]/td[3]/div/a')->click; |
116 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[2]/table/tbody/tr[5]/td[3]/div/ul/li[1]/a')->click; |
117 |
$driver->pause(20000); |
118 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[2]/table/tbody/tr[3]/td[6]/div/a')->click; |
119 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[2]/table/tbody/tr[3]/td[6]/div/ul/li[3]/a')->click; |
120 |
$driver->pause(20000); |
121 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div/form[1]/button')->click; |
122 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div/form/button')->click; |
123 |
$driver->pause(20000); |
124 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[1]/a')->click; |
125 |
$driver->pause(20000); |
126 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[1]/input')->send_keys("092"); |
127 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[2]/input')->send_keys("Local Dewey"); |
128 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[3]/input')->send_keys("Local Dewey"); |
129 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[2]/input')->click; |
130 |
$driver->pause(20000); |
131 |
time_diff("Added subfield to framework"); |
132 |
|
133 |
#Add library |
134 |
$driver->get_title(); |
135 |
$driver->find_element_by_xpath('/html/body/div[2]/h1/a')->click; |
136 |
$driver->pause(20000); |
137 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[1]/div[2]/div/ul/li[5]/a')->click; |
138 |
$driver->pause(20000); |
139 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[2]/div[1]/dl[1]/dt[1]/a')->click; |
140 |
$driver->pause(20000); |
141 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[1]/a[1]')->click; |
142 |
$driver->pause(20000); |
143 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[1]/input')->send_keys("Test"); |
144 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[2]/input')->send_keys("Test library"); |
145 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[3]/input')->click; |
146 |
$driver->pause(20000); |
147 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[3]/div[1]/div[2]/label/select')->click; |
148 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[3]/div[1]/div[2]/label/select/option[3]')->click; |
149 |
if ($driver->find_element('//td[text()="Test library"]')) { |
150 |
time_diff("Library successfully added"); |
151 |
} else { |
152 |
time_diff("Library not successfully added"); |
153 |
} |
154 |
|
155 |
|
156 |
#Add authorised values |
157 |
$driver->find_element_by_xpath('/html/body/div[3]/a[2]')->click; |
158 |
$driver->pause(20000); |
159 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[2]/div[1]/dl[1]/dt[3]/a')->click; |
160 |
$driver->pause(20000); |
161 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/select')->click; |
162 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/select/option[7]')->click; |
163 |
$driver->pause(20000); |
164 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[1]/a[1]')->click; |
165 |
$driver->pause(20000); |
166 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[2]/input')->send_keys("HBK"); |
167 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[3]/input')->send_keys("Hardback"); |
168 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[4]/input')->send_keys("Hardcover"); |
169 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[2]/input[2]')->click; |
170 |
if ($driver->find_element('//td[text()="HBK"]')) { |
171 |
time_diff("Authorised value successfully added"); |
172 |
} else { |
173 |
time_diff("Authorised value not successfully added"); |
174 |
} |
175 |
|
176 |
#Patron category |
177 |
$driver->find_element_by_xpath('/html/body/div[3]/a[2]')->click; |
178 |
$driver->pause(20000); |
179 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[2]/div[1]/dl[2]/dt[1]/a')->click; |
180 |
$driver->pause(20000); |
181 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[1]/a')->click; |
182 |
$driver->pause(20000); |
183 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[1]/input')->send_keys("AD"); |
184 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[2]/input')->send_keys("Adult"); |
185 |
$driver->find_element_by_xpath("/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[3]/fieldset/ol/li[1]/input")->send_keys(12); |
186 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[10]/select')->click; |
187 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[10]/select/option[6]')->click; |
188 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[2]/input')->click; |
189 |
$driver->pause(20000); |
190 |
if ($driver->find_element('//td[text()="AD"]')) { |
191 |
time_diff("Patron category successfully added"); |
192 |
} else { |
193 |
time_diff("Patron category not successfully added"); |
194 |
} |
195 |
|
196 |
#Add patron attribute type |
197 |
$driver->find_element_by_xpath('/html/body/div[3]/a[2]')->click; |
198 |
$driver->pause(20000); |
199 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[2]/div[1]/dl[2]/dt[3]/a')->click; |
200 |
$driver->pause(20000); |
201 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[2]/a')->click; |
202 |
$driver->pause(20000); |
203 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[1]/input')->send_keys("DL"); |
204 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[2]/input')->send_keys("Driver's License"); |
205 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[11]/select')->click; |
206 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[11]/select/option[2]')->click; |
207 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[2]/input')->click; |
208 |
$driver->pause(20000); |
209 |
warn $driver->get_title(); |
210 |
if ($driver->find_element('//td[text()="DL"]')) { |
211 |
time_diff("Patron attribute type successfully added"); |
212 |
} else { |
213 |
time_diff("Patron attribute type not successfully added"); |
214 |
} |
215 |
|
216 |
#Add Z39.50 target server |
217 |
$driver->find_element_by_xpath('/html/body/div[3]/a[2]')->click; |
218 |
$driver->pause(20000); |
219 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[2]/div[2]/dl[3]/dt[1]/a')->click; |
220 |
$driver->pause(20000); |
221 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[1]/a[1]')->click; |
222 |
$driver->pause(20000); |
223 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[1]/input')->send_keys("University of London"); |
224 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[2]/input')->send_keys("consull.ull.ac.uk"); |
225 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[3]/input')->send_keys(210); |
226 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[4]/input')->send_keys("INNOPAC"); |
227 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[9]/select')->click; |
228 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[9]/select/option[4]')->click; |
229 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[2]/input')->click; |
230 |
$driver->pause(20000); |
231 |
if ($driver->find_element('//td[text()="consull.ull.ac.uk:210"]')) { |
232 |
time_diff("Z39.50 target successfully added"); |
233 |
} else { |
234 |
time_diff("Z39.50 target not successfully added"); |
235 |
} |
236 |
|
237 |
#Add item circulation alerts |
238 |
$driver->find_element_by_xpath('/html/body/div[3]/a[2]')->click; |
239 |
$driver->pause(20000); |
240 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[2]/div[1]/dl[2]/dt[6]/a')->click; |
241 |
$driver->pause(20000); |
242 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[2]/div[1]/table/tbody/tr[1]/td[1]')->click; |
243 |
time_diff("Added item circulation alert"); |
244 |
|
245 |
#Add city |
246 |
$driver->find_element_by_xpath('/html/body/div[3]/a[2]')->click; |
247 |
$driver->pause(20000); |
248 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[2]/div[1]/dl[2]/dt[7]/a')->click; |
249 |
$driver->pause(20000); |
250 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[1]/a')->click; |
251 |
$driver->pause(20000); |
252 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[1]/input')->send_keys("Wellington"); |
253 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[3]/input')->send_keys(6011); |
254 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[4]/input')->send_keys("New Zealand"); |
255 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[2]/input')->click; |
256 |
$driver->pause(20000); |
257 |
if ($driver->find_element('//td[text()="Wellington"]')) { |
258 |
time_diff("City successfully added"); |
259 |
} else { |
260 |
time_diff("City not successfully added"); |
261 |
} |
262 |
|
263 |
close $fh; |
264 |
$driver->quit(); |
265 |
}; |
266 |
|
267 |
END { |
268 |
cleanup() if $cleanup_needed; |
269 |
}; |
270 |
|
271 |
sub auth { |
272 |
my ( $driver, $login, $password) = @_; |
273 |
fill_form( $driver, { userid => 'koha', password => 'koha' } ); |
274 |
my $login_button = $driver->find_element('//input[@id="submit"]'); |
275 |
$login_button->submit(); |
276 |
} |
277 |
|
278 |
sub patron_auth { |
279 |
my ( $driver,$patronusername, $patronpassword) = @_; |
280 |
fill_form( $driver, { userid => $patronusername, password => $patronpassword } ); |
281 |
my $login_button = $driver->find_element('//input[@id="submit"]'); |
282 |
$login_button->submit(); |
283 |
} |
284 |
|
285 |
sub patron_opac_auth { |
286 |
my ( $driver,$patronusername, $patronpassword) = @_; |
287 |
fill_form( $driver, { userid => $patronusername, password => $patronpassword } ); |
288 |
my $login_button = $driver->find_element('//input[@value="Log in"]'); |
289 |
$login_button->submit(); |
290 |
} |
291 |
|
292 |
sub fill_form { |
293 |
my ( $driver, $values ) = @_; |
294 |
while ( my ( $id, $value ) = each %$values ) { |
295 |
my $element = $driver->find_element('//*[@id="'.$id.'"]'); |
296 |
my $tag = $element->get_tag_name(); |
297 |
if ( $tag eq 'input' ) { |
298 |
$driver->find_element('//input[@id="'.$id.'"]')->send_keys($value); |
299 |
} elsif ( $tag eq 'select' ) { |
300 |
$driver->find_element('//select[@id="'.$id.'"]/option[@value="'.$value.'"]')->click; |
301 |
} |
302 |
} |
303 |
} |
304 |
|
305 |
sub cleanup { |
306 |
my $dbh = C4::Context->dbh; |
307 |
$dbh->do(q|DELETE FROM categories WHERE categorycode = ?|, {}, $sample_data->{category}{categorycode}); |
308 |
$dbh->do(q|DELETE FROM borrowers WHERE userid = ?|, {}, $sample_data->{patron}{userid}); |
309 |
} |
310 |
|
311 |
sub time_diff { |
312 |
my $lib = shift; |
313 |
my $now = gettimeofday; |
314 |
warn "CP $lib = " . sprintf("%.2f", $now - $prev_time ) . "\n"; |
315 |
$prev_time = $now; |
316 |
} |