|
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 following functionality of the Tools module: |
| 21 |
#* Create patorn list |
| 22 |
#* Create patron club template |
| 23 |
#* Create patron club |
| 24 |
#* Create notice |
| 25 |
#* Create overdue notice and status trigger |
| 26 |
#* Create patron card batch |
| 27 |
#* Create patron card text layout |
| 28 |
#* Create patron card template |
| 29 |
#* Set holiday with calendar |
| 30 |
#* Create CSV profile |
| 31 |
#* View logs |
| 32 |
#* Create news item |
| 33 |
#* Create new quote |
| 34 |
|
| 35 |
#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 |
| 36 |
|
| 37 |
use Modern::Perl; |
| 38 |
|
| 39 |
use Time::HiRes qw(gettimeofday); |
| 40 |
use C4::Context; |
| 41 |
use C4::Biblio qw( AddBiblio ); # We shouldn't use it |
| 42 |
|
| 43 |
use Test::More tests => 1; |
| 44 |
use MARC::Record; |
| 45 |
use MARC::Field; |
| 46 |
|
| 47 |
my $dbh = C4::Context->dbh; |
| 48 |
my $login = 'koha'; |
| 49 |
my $password = 'koha'; |
| 50 |
my $base_url= 'http://'.C4::Context->preference("staffClientBaseURL")."/cgi-bin/koha/"; |
| 51 |
my $opac_url= C4::Context->preference("OPACBaseURL"); |
| 52 |
|
| 53 |
our $sample_data = { |
| 54 |
category => { |
| 55 |
categorycode => 'test_cat', |
| 56 |
description => 'test cat description', |
| 57 |
enrolmentperiod => '12', |
| 58 |
category_type => 'A' |
| 59 |
}, |
| 60 |
patron => { |
| 61 |
surname => 'test_patron_surname', |
| 62 |
cardnumber => '4242424242', |
| 63 |
userid => 'test_username', |
| 64 |
password => 'password', |
| 65 |
password2 => 'password' |
| 66 |
}, |
| 67 |
}; |
| 68 |
|
| 69 |
my $patronusername="test_username"; |
| 70 |
my $patronpassword="password"; |
| 71 |
|
| 72 |
our ( $borrowernumber, $start, $prev_time, $cleanup_needed ); |
| 73 |
|
| 74 |
SKIP: { |
| 75 |
eval { require Selenium::Remote::Driver; }; |
| 76 |
skip "Selenium::Remote::Driver is needed for selenium tests.", 20 if $@; |
| 77 |
|
| 78 |
$cleanup_needed = 1; |
| 79 |
|
| 80 |
open my $fh, '>>', '/tmp/output.txt'; |
| 81 |
|
| 82 |
my $driver = Selenium::Remote::Driver->new; |
| 83 |
$start = gettimeofday; |
| 84 |
$prev_time = $start; |
| 85 |
$driver->get($base_url."mainpage.pl"); |
| 86 |
like( $driver->get_title(), qr(Log in to Koha), ); |
| 87 |
auth( $driver, $login, $password ); |
| 88 |
time_diff("main"); |
| 89 |
|
| 90 |
#Navigate into the tools module |
| 91 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[1]/div[2]/div/ul/li[4]/a')->click; |
| 92 |
|
| 93 |
#Create a patron list |
| 94 |
$driver->pause(20000); |
| 95 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[1]/dl/dt[1]/a')->click; |
| 96 |
$driver->pause(20000); |
| 97 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[1]/div/a')->click; |
| 98 |
$driver->pause(20000); |
| 99 |
$driver->find_element_by_xpath('/html/body/div[4]/div/form/fieldset[1]/ol/li[1]/input')->send_keys("Test list"); |
| 100 |
$driver->find_element_by_xpath('/html/body/div[4]/div/form/fieldset[2]/input[2]')->click; |
| 101 |
$driver->pause(20000); |
| 102 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form[1]/fieldset/input')->send_keys("koha"); |
| 103 |
$driver->pause(20000); |
| 104 |
$driver->find_element_by_xpath('/html/body/ul[2]/li/a')->click; |
| 105 |
$driver->pause(20000); |
| 106 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form[1]/fieldset/fieldset/fieldset/a')->click; |
| 107 |
$driver->pause(20000); |
| 108 |
if ($driver->find_element('//td[text()="Test list"]')) { |
| 109 |
time_diff("Patron list successfully created and added patron to it"); |
| 110 |
} else { |
| 111 |
time_diff("Patron list not successfully created"); |
| 112 |
} |
| 113 |
|
| 114 |
#Create patron club template |
| 115 |
$driver->find_element_by_xpath('/html/body/div[3]/a[2]')->click; |
| 116 |
$driver->pause(20000); |
| 117 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[1]/dl/dt[2]/a')->click; |
| 118 |
$driver->pause(20000); |
| 119 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[1]/div/a')->click; |
| 120 |
$driver->pause(20000); |
| 121 |
$driver->find_element_by_xpath('/html/body/div[4]/div[1]/div/form/fieldset[1]/ol/li[1]/input')->send_keys("Test patron club template"); |
| 122 |
$driver->find_element_by_xpath('/html/body/div[4]/div[1]/div/form/fieldset[1]/ol/li[2]/input')->send_keys("This is the test template"); |
| 123 |
$driver->find_element_by_xpath('/html/body/div[4]/div[1]/div/form/fieldset[1]/ol/li[3]/input')->click; |
| 124 |
$driver->find_element_by_xpath('/html/body/div[4]/div[1]/div/form/fieldset[2]/fieldset/a')->click; |
| 125 |
$driver->pause(2000); |
| 126 |
$driver->find_element_by_xpath('/html/body/div[4]/div[1]/div/form/fieldset[2]/div/div/ol/li[1]/input')->send_keys("Test field"); |
| 127 |
$driver->find_element_by_xpath('/html/body/div[4]/div[1]/div/form/fieldset[4]/input[2]')->click; |
| 128 |
$driver->pause(2000); |
| 129 |
if ($driver->find_element('//td[text()="Test patron club template"]')) { |
| 130 |
time_diff("Test template successfully created"); |
| 131 |
} else { |
| 132 |
time_diff("Test template not successfully created"); |
| 133 |
} |
| 134 |
|
| 135 |
#Create patron club |
| 136 |
$driver->pause(20000); |
| 137 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[4]/div/button')->click; |
| 138 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[4]/div/ul/li[1]/a')->click; |
| 139 |
$driver->pause(20000); |
| 140 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/form/fieldset[1]/ol/li[1]/input')->send_keys("Centerville patron club"); |
| 141 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/form/fieldset[1]/ol/li[2]/input')->send_keys("Patron club for all patrons of Centerville library"); |
| 142 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/form/fieldset[1]/ol/li[5]/select')->click; |
| 143 |
$driver->find_element('//option[@value="CPL"]')->click; |
| 144 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/form/fieldset[2]/input')->click; |
| 145 |
$driver->pause(2000); |
| 146 |
if ($driver->find_element('//td[text()="Centerville patron club"]')) { |
| 147 |
time_diff("Patron club successfully created"); |
| 148 |
} else { |
| 149 |
time_diff("Patron club not successfully created"); |
| 150 |
} |
| 151 |
|
| 152 |
#Create notice |
| 153 |
$driver->find_element_by_xpath('/html/body/div[3]/a[2]')->click; |
| 154 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[1]/dl/dt[5]/a')->click; |
| 155 |
$driver->pause(2000); |
| 156 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/div/button')->click; |
| 157 |
$driver->pause(20000); |
| 158 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/fieldset/ol/li[3]/input')->send_keys("TEST_NOTICE"); |
| 159 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/fieldset/ol/li[4]/input')->send_keys("Test notice"); |
| 160 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div/div/h3[1]')->click; |
| 161 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div/div/fieldset[1]/ol/li[2]/input')->send_keys("Test title"); |
| 162 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div/div/fieldset[1]/ol/li[3]/table/tbody/tr/td[1]/select/option[2]')->click; |
| 163 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div/div/fieldset[1]/ol/li[3]/table/tbody/tr/td[2]/button')->click; |
| 164 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/div[1]/div/button[1]')->click; |
| 165 |
$driver->pause(20000); |
| 166 |
if ($driver->find_element('//td[text()="TEST_NOTICE"]')) { |
| 167 |
time_diff("Notice successfully created"); |
| 168 |
} else { |
| 169 |
time_diff("Notice not successfully created"); |
| 170 |
} |
| 171 |
|
| 172 |
#Create overdue notice and status trigger |
| 173 |
$driver->find_element_by_xpath('/html/body/div[3]/a[2]')->click; |
| 174 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[1]/dl/dt[6]/a')->click; |
| 175 |
$driver->pause(20000); |
| 176 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form[2]/div/div[1]/table/tbody/tr[1]/td[1]/input')->send_keys(12); |
| 177 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form[2]/div/div[1]/table/tbody/tr[1]/td[2]/select')->click; |
| 178 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form[2]/div/div[1]/table/tbody/tr[1]/td[2]/select/option[2]')->click; |
| 179 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form[2]/fieldset/input')->click; |
| 180 |
$driver->pause(20000); |
| 181 |
my $overdue_action = $driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form[2]/div[2]/div[1]/table/tbody/tr[1]/td[1]/input'); |
| 182 |
if ($overdue_action->get_attribute('value') == 12) { |
| 183 |
time_diff("Overdue action successfully added"); |
| 184 |
} else { |
| 185 |
time_diff("Overdue action not successfully added"); |
| 186 |
} |
| 187 |
|
| 188 |
# Patron card creator |
| 189 |
# Create patron card batch |
| 190 |
$driver->find_element_by_xpath('/html/body/div[3]/a[2]')->click; |
| 191 |
$driver->pause(20000); |
| 192 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[1]/dl/dt[7]/a')->click; |
| 193 |
$driver->pause(20000); |
| 194 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div/div[1]/div[1]/button')->click; |
| 195 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div/div[1]/div[1]/ul/li[1]/a')->click; |
| 196 |
$driver->pause(20000); |
| 197 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[2]/form/div/fieldset/ol/li/textarea')->send_keys(1); |
| 198 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[2]/div[2]/a[1]/i')->click; |
| 199 |
$driver->pause(20000); |
| 200 |
if ($driver->find_element('//td[text()=1]')) { |
| 201 |
time_diff("Patron batch successfully added"); |
| 202 |
} else { |
| 203 |
time_diff("Patron batch not successfully added"); |
| 204 |
} |
| 205 |
|
| 206 |
# Create patron card text layout |
| 207 |
$driver->get($base_url."/cgi-bin/koha/tools/tools-home.pl"); |
| 208 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[1]/dl/dt[7]/a')->click; |
| 209 |
$driver->pause(2000); |
| 210 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div/div[1]/div[1]/button')->click; |
| 211 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div/div[1]/div[1]/ul/li[3]/a')->click; |
| 212 |
$driver->pause(20000); |
| 213 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/div/div[1]/fieldset/ol/li[1]/fieldset/ol/li[1]/input')->send_keys("Test patron card text layout"); |
| 214 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/div/div[2]/fieldset/ol/li[1]/fieldset/ol/li/input')->click; |
| 215 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset/input[1]')->click; |
| 216 |
$driver->pause(20000); |
| 217 |
if ($driver->find_element('//td[text()="Test patron card text layout"]')) { |
| 218 |
time_diff("Patron card text layout successfully created"); |
| 219 |
} else { |
| 220 |
time_diff("Patron card text layout not successfully created"); |
| 221 |
} |
| 222 |
|
| 223 |
#Create patron card template |
| 224 |
$driver->find_element_by_xpath('/html/body/div[3]/a[3]')->click; |
| 225 |
$driver->pause(20000); |
| 226 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div/div[1]/div[1]/button')->click; |
| 227 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div/div[1]/div[1]/ul/li[4]/a')->click; |
| 228 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/div[1]/div[1]/fieldset/ol/li[2]/input')->clear(); |
| 229 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/div[1]/div[1]/fieldset/ol/li[2]/input')->send_keys("Test patron card template"); |
| 230 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/div[1]/div[1]/fieldset/ol/li[3]/textarea')->clear(); |
| 231 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/div[1]/div[1]/fieldset/ol/li[3]/textarea')->send_keys("This is a test patron card template"); |
| 232 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/div[2]/fieldset/input[1]')->click; |
| 233 |
$driver->pause(20000); |
| 234 |
if ($driver->find_element('//td[text()="Test patron card template"]')) { |
| 235 |
time_diff("Patron card template successfully created"); |
| 236 |
} else { |
| 237 |
time_diff("Patron card template not successfully created"); |
| 238 |
} |
| 239 |
|
| 240 |
#Set holidays with calendar |
| 241 |
$driver->find_element_by_xpath('/html/body/div[3]/a[2]')->click; |
| 242 |
$driver->pause(20000); |
| 243 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[2]/dl/dt[1]/a')->click; |
| 244 |
$driver->pause(2000); |
| 245 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div/div[1]/div[3]/div/table/tbody/tr[2]/td[2]/a')->click; |
| 246 |
$driver->find_element_by_xpath('/html/body/div[5]/div[2]/button[1]')->click; |
| 247 |
$driver->find_element_by_xpath('/html/body/div[5]/table/tbody/tr[2]/td[3]/a')->click; |
| 248 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div/div[1]/div[2]/form/fieldset/ol/li[4]/input')->send_keys("Test holiday"); |
| 249 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div/div[1]/div[2]/form/fieldset/fieldset/input')->click; |
| 250 |
$driver->pause(2000); |
| 251 |
if ($driver->find_element('//td[text()="Test holiday"]')) { |
| 252 |
time_diff("Unique holiday successfully created"); |
| 253 |
} else { |
| 254 |
time_diff("Unique holiday not successfully created"); |
| 255 |
} |
| 256 |
|
| 257 |
#Create CSV profile |
| 258 |
$driver->find_element_by_xpath('/html/body/div[3]/a[2]')->click; |
| 259 |
$driver->pause(2000); |
| 260 |
$driver->find_element_by_xpath('/html/body/div[3]/a[2]')->click; |
| 261 |
$driver->pause(2000); |
| 262 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div/a')->click; |
| 263 |
$driver->pause(2000); |
| 264 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[1]/input')->send_keys("Test CSV profile"); |
| 265 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[10]/textarea')->send_keys("Personal name=200|Entry element=210$a|300|009"); |
| 266 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[2]/input')->click; |
| 267 |
$driver->pause(20000); |
| 268 |
if ($driver->find_element('//td[text()="Test CSV profile"]')) { |
| 269 |
time_diff("CSV profile successfully added"); |
| 270 |
} else { |
| 271 |
time_diff("CSV profile not successfully added"); |
| 272 |
} |
| 273 |
|
| 274 |
#View logs |
| 275 |
$driver->find_element_by_xpath('/html/body/div[3]/a[2]')->click; |
| 276 |
$driver->pause(20000); |
| 277 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[2]/dl/dt[3]/a')->click; |
| 278 |
$driver->pause(2000); |
| 279 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[3]/input[1]')->click; |
| 280 |
$driver->pause(3000); |
| 281 |
if ($driver->find_element('//th[text()="Date"]')) { |
| 282 |
time_diff("Logs successfully displayed"); |
| 283 |
} else { |
| 284 |
time_diff("Logs not successfully displayed"); |
| 285 |
} |
| 286 |
|
| 287 |
#Create news item |
| 288 |
$driver->find_element_by_xpath('/html/body/div[3]/a[2]')->click; |
| 289 |
$driver->pause(2000); |
| 290 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[2]/dl/dt[4]/a')->click; |
| 291 |
$driver->pause(2000); |
| 292 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[1]/a')->click; |
| 293 |
$driver->pause(2000); |
| 294 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/fieldset[1]/ol/li[3]/input')->send_keys("Test news item"); |
| 295 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/fieldset[1]/ol/li[4]/input')->click; |
| 296 |
$driver->find_element_by_xpath('/html/body/div[5]/table/tbody/tr[2]/td[2]/a')->click; |
| 297 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/fieldset[2]/input')->click; |
| 298 |
$driver->pause(2000); |
| 299 |
if ($driver->find_element('//td[text()="Test news item"]')) { |
| 300 |
time_diff("News item successfully created"); |
| 301 |
} else { |
| 302 |
time_diff("News item not successfully created"); |
| 303 |
} |
| 304 |
|
| 305 |
#Add new quote |
| 306 |
$driver->find_element_by_xpath('/html/body/div[3]/a[2]')->click; |
| 307 |
$driver->pause(2000); |
| 308 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[2]/dl/dt[6]/a')->click; |
| 309 |
$driver->pause(2000); |
| 310 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[1]/div[1]/a')->click; |
| 311 |
$driver->pause(2000); |
| 312 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[3]/table/tbody/tr[2]/td[2]/input')->send_keys("Albert Einstein"); |
| 313 |
$driver->send_modifier('Enter', 'down'); |
| 314 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[3]/table/tbody/tr[2]/td[3]/input')->send_keys("Stay away from negative people. They have a problem for every solution"); |
| 315 |
$driver->send_modifier('Enter', 'down'); |
| 316 |
$driver->pause(2000); |
| 317 |
if ($driver->find_element('//td[text()="Albert Einstein"]')) { |
| 318 |
time_diff("New quote successfully added"); |
| 319 |
} else { |
| 320 |
time_diff("New quote not successfully added"); |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
close $fh; |
| 325 |
$driver->quit(); |
| 326 |
}; |
| 327 |
|
| 328 |
END { |
| 329 |
cleanup() if $cleanup_needed; |
| 330 |
}; |
| 331 |
|
| 332 |
sub auth { |
| 333 |
my ( $driver, $login, $password) = @_; |
| 334 |
fill_form( $driver, { userid => 'koha', password => 'koha' } ); |
| 335 |
my $login_button = $driver->find_element('//input[@id="submit"]'); |
| 336 |
$login_button->submit(); |
| 337 |
} |
| 338 |
|
| 339 |
sub patron_auth { |
| 340 |
my ( $driver,$patronusername, $patronpassword) = @_; |
| 341 |
fill_form( $driver, { userid => $patronusername, password => $patronpassword } ); |
| 342 |
my $login_button = $driver->find_element('//input[@id="submit"]'); |
| 343 |
$login_button->submit(); |
| 344 |
} |
| 345 |
|
| 346 |
sub patron_opac_auth { |
| 347 |
my ( $driver,$patronusername, $patronpassword) = @_; |
| 348 |
fill_form( $driver, { userid => $patronusername, password => $patronpassword } ); |
| 349 |
my $login_button = $driver->find_element('//input[@value="Log in"]'); |
| 350 |
$login_button->submit(); |
| 351 |
} |
| 352 |
|
| 353 |
sub fill_form { |
| 354 |
my ( $driver, $values ) = @_; |
| 355 |
while ( my ( $id, $value ) = each %$values ) { |
| 356 |
my $element = $driver->find_element('//*[@id="'.$id.'"]'); |
| 357 |
my $tag = $element->get_tag_name(); |
| 358 |
if ( $tag eq 'input' ) { |
| 359 |
$driver->find_element('//input[@id="'.$id.'"]')->send_keys($value); |
| 360 |
} elsif ( $tag eq 'select' ) { |
| 361 |
$driver->find_element('//select[@id="'.$id.'"]/option[@value="'.$value.'"]')->click; |
| 362 |
} |
| 363 |
} |
| 364 |
} |
| 365 |
|
| 366 |
sub cleanup { |
| 367 |
my $dbh = C4::Context->dbh; |
| 368 |
$dbh->do(q|DELETE FROM categories WHERE categorycode = ?|, {}, $sample_data->{category}{categorycode}); |
| 369 |
$dbh->do(q|DELETE FROM borrowers WHERE userid = ?|, {}, $sample_data->{patron}{userid}); |
| 370 |
} |
| 371 |
|
| 372 |
sub time_diff { |
| 373 |
my $lib = shift; |
| 374 |
my $now = gettimeofday; |
| 375 |
warn "CP $lib = " . sprintf("%.2f", $now - $prev_time ) . "\n"; |
| 376 |
$prev_time = $now; |
| 377 |
} |