|
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 will test the functionality of placing a reserve, and renewing an item from the OPAC |
| 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 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 => 3; |
| 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 |
my $number_of_biblios_to_insert = 3; |
| 41 |
our $sample_data = { |
| 42 |
category => { |
| 43 |
categorycode => 'test_cat', |
| 44 |
description => 'test cat description', |
| 45 |
enrolmentperiod => '12', |
| 46 |
category_type => 'A' |
| 47 |
}, |
| 48 |
patron => { |
| 49 |
surname => 'test_patron_surname', |
| 50 |
cardnumber => '4242424242', |
| 51 |
userid => 'test_username', |
| 52 |
password => 'password', |
| 53 |
password2 => 'password' |
| 54 |
}, |
| 55 |
}; |
| 56 |
|
| 57 |
my $patronusername="test_username"; |
| 58 |
my $patronpassword="password"; |
| 59 |
|
| 60 |
our ( $borrowernumber, $start, $prev_time, $cleanup_needed ); |
| 61 |
|
| 62 |
SKIP: { |
| 63 |
eval { require Selenium::Remote::Driver; }; |
| 64 |
skip "Selenium::Remote::Driver is needed for selenium tests.", 20 if $@; |
| 65 |
|
| 66 |
$cleanup_needed = 1; |
| 67 |
|
| 68 |
open my $fh, '>>', '/tmp/output.txt'; |
| 69 |
|
| 70 |
# Go to the mainpage and log in as default user |
| 71 |
my $driver = Selenium::Remote::Driver->new; |
| 72 |
$start = gettimeofday; |
| 73 |
$prev_time = $start; |
| 74 |
$driver->get($base_url."mainpage.pl"); |
| 75 |
like( $driver->get_title(), qr(Log in to Koha), ); |
| 76 |
auth( $driver, $login, $password ); |
| 77 |
time_diff("main"); |
| 78 |
|
| 79 |
# Go to Cataloging page |
| 80 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[1]/div[1]/div/ul/li[5]/a')->click; |
| 81 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[1]/div[2]/button[1]')->click; |
| 82 |
$driver->pause(10000); |
| 83 |
|
| 84 |
my $handles = $driver->get_window_handles; |
| 85 |
$driver->switch_to_window($handles->[1]); |
| 86 |
warn $driver->get_title(); |
| 87 |
$driver->find_element_by_xpath('/html/body/div/div/form/div/div[1]/fieldset/ol/li[3]/input')->send_keys("Wind in the Willows"); |
| 88 |
warn $driver->get_title(); |
| 89 |
$driver->find_element_by_xpath('/html/body/div/div/form/div/fieldset/input')->click; |
| 90 |
$driver->pause(20000); |
| 91 |
|
| 92 |
# Import the MARC result |
| 93 |
$driver->find_element_by_xpath('/html/body/div/div/div[1]/table/tbody/tr[1]/td[10]/a')->click; |
| 94 |
|
| 95 |
# Add Koha item type |
| 96 |
$driver->switch_to_window($handles->[0]); |
| 97 |
$driver->pause(20000); |
| 98 |
|
| 99 |
warn $driver->get_title(); |
| 100 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div[3]/div[1]/div[3]/div[2]/input')->click; |
| 101 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div[3]/ul/li[10]/a')->click; |
| 102 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div[3]/div[10]/div[2]/div[3]/div')->click; |
| 103 |
$driver->find_element_by_xpath('/html/body/div[6]/ul/li[1]/div')->click; |
| 104 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div[1]/div[1]/button[2]')->click; |
| 105 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div[1]/div[1]/ul/li[2]/a')->click; |
| 106 |
|
| 107 |
|
| 108 |
# Add item |
| 109 |
warn $driver->get_title(); |
| 110 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[2]/div[2]/div/form/fieldset[1]/ol/li[23]/div/input[1]')->send_keys("TEST12345"); |
| 111 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[2]/div[2]/div/form/fieldset[2]/span[1]/input[1]')->click; |
| 112 |
$driver->find_element('//table[@id="itemst"]'); |
| 113 |
|
| 114 |
# Load OPAC |
| 115 |
$driver->get($opac_url); |
| 116 |
like( $driver->get_title(), qr(Koha online catalog), ); |
| 117 |
$driver->find_element_by_xpath('/html/body/div/div[2]/div/div/div/div[1]/form/div/input')->send_keys('Wind in the willows'); |
| 118 |
$driver->find_element_by_xpath('/html/body/div/div[2]/div/div/div/div[1]/form/div/button')->click; |
| 119 |
$driver->pause(20000); |
| 120 |
$driver->find_element_by_xpath('/html/body/div/div[4]/div/div[1]/div[2]/div/ul/li[1]/a')->click; |
| 121 |
$driver->pause(20000); |
| 122 |
$driver->find_element('//input[@value="Confirm hold"]')->click; |
| 123 |
if ($driver->find_element_by_xpath('//table[@id="holdst"]') ){ |
| 124 |
time_diff("Hold successfully placed"); |
| 125 |
} else { |
| 126 |
time_diff("Hold not successfully placed"); |
| 127 |
} |
| 128 |
|
| 129 |
#Check the item out in the intranet |
| 130 |
$driver->get($base_url."mainpage.pl"); |
| 131 |
$driver->find_element_by_xpath('/html/body/div[2]/div/div[1]/form/div/input[1]')->send_keys('koha'); |
| 132 |
$driver->find_element_by_xpath('/html/body/div[2]/div/div[1]/form/div/input[2]')->click; |
| 133 |
|
| 134 |
#select the patron and checkout the item |
| 135 |
$driver->find_element_by_xpath('/html/body/div[4]/div[1]/div/div/fieldset/div/table/tbody/tr[2]/td[1]/a')->click; |
| 136 |
warn $driver->get_title(); |
| 137 |
$driver->find_element('//input[@id="barcode"]')->send_keys("TEST12345"); |
| 138 |
$driver->find_element_by_xpath('/html/body/div[4]/div[1]/div[1]/div/div[3]/div[1]/form/fieldset/button')->click; |
| 139 |
|
| 140 |
#Renew the item in the OPAC |
| 141 |
$driver->get($opac_url); |
| 142 |
like( $driver->get_title(), qr(Koha online catalog), ); |
| 143 |
warn $driver->get_title(); |
| 144 |
$driver->find_element_by_xpath('/html/body/div[1]/div[1]/div/div/div/ul/li[3]/a')->click; |
| 145 |
$driver->find_element_by_xpath('/html/body/div[1]/div[1]/div/div/div/ul/li[3]/ul/li[3]/a')->click; |
| 146 |
$driver->find_element_by_xpath('/html/body/div/div[4]/div/div/div[1]/div/div[2]/div/ul/li[1]/a')->click; |
| 147 |
warn $driver->get_title(); |
| 148 |
$driver->find_element_by_xpath('/html/body/div/div[4]/div/div/div[2]/div/div[2]/div[2]/form[2]/input[4]')->click; |
| 149 |
if ($driver->find_element_by_xpath('/html/body/div/div[4]/div/div/div[2]/div/div[2]/div[2]/form[1]/div/table/tbody/tr/td[6]/span[1]')) { |
| 150 |
time_diff("Item has been renewed"); |
| 151 |
} else { |
| 152 |
time_diff("Item has not been successfully renewed"); |
| 153 |
} |
| 154 |
|
| 155 |
close $fh; |
| 156 |
$driver->quit(); |
| 157 |
}; |
| 158 |
|
| 159 |
END { |
| 160 |
cleanup() if $cleanup_needed; |
| 161 |
}; |
| 162 |
|
| 163 |
sub auth { |
| 164 |
my ( $driver, $login, $password) = @_; |
| 165 |
fill_form( $driver, { userid => 'koha', password => 'koha' } ); |
| 166 |
my $login_button = $driver->find_element('//input[@id="submit"]'); |
| 167 |
$login_button->submit(); |
| 168 |
} |
| 169 |
|
| 170 |
sub fill_form { |
| 171 |
my ( $driver, $values ) = @_; |
| 172 |
while ( my ( $id, $value ) = each %$values ) { |
| 173 |
my $element = $driver->find_element('//*[@id="'.$id.'"]'); |
| 174 |
my $tag = $element->get_tag_name(); |
| 175 |
if ( $tag eq 'input' ) { |
| 176 |
$driver->find_element('//input[@id="'.$id.'"]')->send_keys($value); |
| 177 |
} elsif ( $tag eq 'select' ) { |
| 178 |
$driver->find_element('//select[@id="'.$id.'"]/option[@value="'.$value.'"]')->click; |
| 179 |
} |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
sub cleanup { |
| 184 |
my $dbh = C4::Context->dbh; |
| 185 |
$dbh->do(q|DELETE FROM categories WHERE categorycode = ?|, {}, $sample_data->{category}{categorycode}); |
| 186 |
$dbh->do(q|DELETE FROM borrowers WHERE userid = ?|, {}, $sample_data->{patron}{userid}); |
| 187 |
for my $i ( 1 .. $number_of_biblios_to_insert ) { |
| 188 |
$dbh->do(qq|DELETE FROM biblio WHERE title = "test biblio $i"|); |
| 189 |
}; |
| 190 |
|
| 191 |
$dbh->do(q|DELETE FROM issues where borrowernumber=?|, {}, $borrowernumber); |
| 192 |
$dbh->do(q|DELETE FROM old_issues where borrowernumber=?|, {}, $borrowernumber); |
| 193 |
for my $i ( 1 .. $number_of_biblios_to_insert ) { |
| 194 |
$dbh->do(qq|DELETE items, biblio FROM biblio INNER JOIN items ON biblio.biblionumber = items.biblionumber WHERE biblio.title = "test biblio$i"|); |
| 195 |
}; |
| 196 |
} |
| 197 |
|
| 198 |
sub time_diff { |
| 199 |
my $lib = shift; |
| 200 |
my $now = gettimeofday; |
| 201 |
warn "CP $lib = " . sprintf("%.2f", $now - $prev_time ) . "\n"; |
| 202 |
$prev_time = $now; |
| 203 |
} |