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 goes through the cataloging workflow starting on the intranets home page and then using z39.50 targets to add a MARC record. After that items are added to the MARC record |
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 => 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 |
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 |
}; |
49 |
|
50 |
my $patronusername="test_username"; |
51 |
my $patronpassword="password"; |
52 |
|
53 |
our ( $borrowernumber, $start, $prev_time, $cleanup_needed ); |
54 |
|
55 |
SKIP: { |
56 |
eval { require Selenium::Remote::Driver; }; |
57 |
skip "Selenium::Remote::Driver is needed for selenium tests.", 20 if $@; |
58 |
|
59 |
$cleanup_needed = 1; |
60 |
|
61 |
open my $fh, '>>', '/tmp/output.txt'; |
62 |
|
63 |
# Go to the mainpage and log in as default user |
64 |
my $driver = Selenium::Remote::Driver->new; |
65 |
$start = gettimeofday; |
66 |
$prev_time = $start; |
67 |
$driver->get($base_url."mainpage.pl"); |
68 |
like( $driver->get_title(), qr(Log in to Koha), ); |
69 |
auth( $driver, $login, $password ); |
70 |
time_diff("main"); |
71 |
|
72 |
# Go to Cataloging page |
73 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[1]/div[1]/div/ul/li[5]/a')->click; |
74 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[1]/div[2]/button[1]')->click; |
75 |
$driver->pause(10000); |
76 |
|
77 |
my $handles = $driver->get_window_handles; |
78 |
$driver->switch_to_window($handles->[1]); |
79 |
warn $driver->get_title(); |
80 |
$driver->find_element_by_xpath('/html/body/div/div/form/div/div[1]/fieldset/ol/li[3]/input')->send_keys("The Iliad"); |
81 |
$driver->find_element_by_xpath('/html/body/div/div/form/div/div[1]/fieldset/ol/li[4]/input')->send_keys("Homer"); |
82 |
warn $driver->get_title(); |
83 |
$driver->find_element_by_xpath('/html/body/div/div/form/div/fieldset/input')->click; |
84 |
$driver->pause(20000); |
85 |
|
86 |
# Import the MARC result |
87 |
$driver->find_element_by_xpath('/html/body/div/div/div[1]/table/tbody/tr[1]/td[10]/a')->click; |
88 |
|
89 |
# Add Koha item type |
90 |
$driver->switch_to_window($handles->[0]); |
91 |
$driver->pause(20000); |
92 |
|
93 |
warn $driver->get_title(); |
94 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div[3]/div[1]/div[3]/div[2]/input')->click; |
95 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div[3]/ul/li[10]/a')->click; |
96 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div[3]/div[10]/div[2]/div[3]/div')->click; |
97 |
$driver->find_element_by_xpath('/html/body/div[6]/ul/li[1]/div')->click; |
98 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div[1]/div[1]/button[2]')->click; |
99 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div[1]/div[1]/ul/li[2]/a')->click; |
100 |
|
101 |
$driver->pause(20000); |
102 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/div/form[2]/button')->click; |
103 |
|
104 |
# Add item |
105 |
warn $driver->get_title(); |
106 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[2]/div[2]/div/form/fieldset[2]/span[1]/input[1]')->click; |
107 |
if ($driver->find_element('//table[@id="itemst"]') ) { |
108 |
time_diff("Item added"); |
109 |
} else { |
110 |
time_diff("Item not added"); |
111 |
} |
112 |
|
113 |
close $fh; |
114 |
$driver->quit(); |
115 |
}; |
116 |
|
117 |
END { |
118 |
cleanup() if $cleanup_needed; |
119 |
}; |
120 |
|
121 |
sub auth { |
122 |
my ( $driver, $login, $password) = @_; |
123 |
fill_form( $driver, { userid => 'koha', password => 'koha' } ); |
124 |
my $login_button = $driver->find_element('//input[@id="submit"]'); |
125 |
$login_button->submit(); |
126 |
} |
127 |
|
128 |
sub fill_form { |
129 |
my ( $driver, $values ) = @_; |
130 |
while ( my ( $id, $value ) = each %$values ) { |
131 |
my $element = $driver->find_element('//*[@id="'.$id.'"]'); |
132 |
my $tag = $element->get_tag_name(); |
133 |
if ( $tag eq 'input' ) { |
134 |
$driver->find_element('//input[@id="'.$id.'"]')->send_keys($value); |
135 |
} elsif ( $tag eq 'select' ) { |
136 |
$driver->find_element('//select[@id="'.$id.'"]/option[@value="'.$value.'"]')->click; |
137 |
} |
138 |
} |
139 |
} |
140 |
|
141 |
sub cleanup { |
142 |
my $dbh = C4::Context->dbh; |
143 |
$dbh->do(q|DELETE FROM categories WHERE categorycode = ?|, {}, $sample_data->{category}{categorycode}); |
144 |
$dbh->do(q|DELETE FROM borrowers WHERE userid = ?|, {}, $sample_data->{patron}{userid}); |
145 |
for my $i ( 1 .. $number_of_biblios_to_insert ) { |
146 |
$dbh->do(qq|DELETE FROM biblio WHERE title = "test biblio $i"|); |
147 |
}; |
148 |
|
149 |
$dbh->do(q|DELETE FROM issues where borrowernumber=?|, {}, $borrowernumber); |
150 |
$dbh->do(q|DELETE FROM old_issues where borrowernumber=?|, {}, $borrowernumber); |
151 |
for my $i ( 1 .. $number_of_biblios_to_insert ) { |
152 |
$dbh->do(qq|DELETE items, biblio FROM biblio INNER JOIN items ON biblio.biblionumber = items.biblionumber WHERE biblio.title = "test biblio$i"|); |
153 |
}; |
154 |
} |
155 |
|
156 |
sub time_diff { |
157 |
my $lib = shift; |
158 |
my $now = gettimeofday; |
159 |
warn "CP $lib = " . sprintf("%.2f", $now - $prev_time ) . "\n"; |
160 |
$prev_time = $now; |
161 |
} |