Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Koha is free software; you can redistribute it and/or modify it |
6 |
# under the terms of the GNU General Public License as published by |
7 |
# the Free Software Foundation; either version 3 of the License, or |
8 |
# (at your option) any later version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but |
11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
# GNU General Public License for more details. |
14 |
# |
15 |
# You should have received a copy of the GNU General Public License |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
17 |
|
18 |
#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 |
19 |
|
20 |
# wget https://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.1.jar # Does not work with 3.4, did not test the ones between |
21 |
# sudo apt-get install xvfb firefox-esr |
22 |
# SELENIUM_PATH=/home/vagrant/selenium-server-standalone-2.53.1.jar |
23 |
# Xvfb :1 -screen 0 1024x768x24 2>&1 >/dev/null & |
24 |
# DISPLAY=:1 java -jar $SELENIUM_PATH |
25 |
# |
26 |
|
27 |
use Modern::Perl; |
28 |
|
29 |
use Time::HiRes qw(gettimeofday); |
30 |
use C4::Context; |
31 |
use C4::Biblio qw( AddBiblio ); # We shouldn't use it |
32 |
|
33 |
use Test::More tests => 1; |
34 |
use MARC::Record; |
35 |
use MARC::Field; |
36 |
|
37 |
my $dbh = C4::Context->dbh; |
38 |
my $login = 'koha'; |
39 |
my $password = 'koha'; |
40 |
my $base_url= 'http://'.C4::Context->preference("staffClientBaseURL")."/cgi-bin/koha/"; |
41 |
my $opac_url= C4::Context->preference("OPACBaseURL"); |
42 |
|
43 |
my $number_of_biblios_to_insert = 3; |
44 |
our $sample_data = { |
45 |
category => { |
46 |
categorycode => 'test_cat', |
47 |
description => 'test cat description', |
48 |
enrolmentperiod => '12', |
49 |
category_type => 'A' |
50 |
}, |
51 |
}; |
52 |
|
53 |
my $patronusername="test_username"; |
54 |
my $patronpassword="password"; |
55 |
|
56 |
our ( $borrowernumber, $start, $prev_time, $cleanup_needed ); |
57 |
|
58 |
SKIP: { |
59 |
eval { require Selenium::Remote::Driver; }; |
60 |
skip "Selenium::Remote::Driver is needed for selenium tests.", 20 if $@; |
61 |
|
62 |
$cleanup_needed = 1; |
63 |
|
64 |
open my $fh, '>>', '/tmp/output.txt'; |
65 |
|
66 |
# Go to the mainpage and log in as default user |
67 |
my $driver = Selenium::Remote::Driver->new; |
68 |
$start = gettimeofday; |
69 |
$prev_time = $start; |
70 |
$driver->get($base_url."mainpage.pl"); |
71 |
like( $driver->get_title(), qr(Log in to Koha), ); |
72 |
auth( $driver, $login, $password ); |
73 |
time_diff("main"); |
74 |
|
75 |
# Go to Cataloging page |
76 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[1]/div[1]/div/ul/li[5]/a')->click; |
77 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[1]/div[2]/button[1]')->click; |
78 |
$driver->pause(10000); |
79 |
|
80 |
#$driver->switch_to_window('/cgi-bin/koha/cataloguing/z3950_search.pl?frameworkcode='); |
81 |
my $handles = $driver->get_window_handles; |
82 |
$driver->switch_to_window($handles->[1]); |
83 |
warn $driver->get_title(); |
84 |
$driver->find_element_by_xpath('/html/body/div/div/form/div/div[1]/fieldset/ol/li[3]/input')->send_keys("The Iliad"); |
85 |
$driver->find_element_by_xpath('/html/body/div/div/form/div/div[1]/fieldset/ol/li[4]/input')->send_keys("Homer"); |
86 |
warn $driver->get_title(); |
87 |
$driver->find_element_by_xpath('/html/body/div/div/form/div/fieldset/input')->click; |
88 |
$driver->pause(20000); |
89 |
|
90 |
# Import the MARC result |
91 |
$driver->find_element_by_xpath('/html/body/div/div/div[1]/table/tbody/tr[1]/td[10]/a')->click; |
92 |
|
93 |
# Add Koha item type |
94 |
$driver->switch_to_window($handles->[0]); |
95 |
$driver->pause(20000); |
96 |
|
97 |
warn $driver->get_title(); |
98 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div[3]/div[1]/div[3]/div[2]/input')->click; |
99 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div[3]/ul/li[10]/a')->click; |
100 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div[3]/div[10]/div[2]/div[3]/div')->click; |
101 |
$driver->find_element_by_xpath('/html/body/div[6]/ul/li[1]/div')->click; |
102 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div[1]/div[1]/button[2]')->click; |
103 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div[1]/div[1]/ul/li[2]/a')->click; |
104 |
|
105 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/div/form[2]/button')->click; |
106 |
# Add item |
107 |
warn $driver->get_title(); |
108 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[2]/div[2]/div/form/fieldset[2]/span[1]/input[1]')->click; |
109 |
$driver->find_element('//table[@id="itemst"]'); |
110 |
|
111 |
close $fh; |
112 |
$driver->quit(); |
113 |
}; |
114 |
|
115 |
END { |
116 |
cleanup() if $cleanup_needed; |
117 |
}; |
118 |
|
119 |
sub auth { |
120 |
my ( $driver, $login, $password) = @_; |
121 |
fill_form( $driver, { userid => 'koha', password => 'koha' } ); |
122 |
my $login_button = $driver->find_element('//input[@id="submit"]'); |
123 |
$login_button->submit(); |
124 |
} |
125 |
|
126 |
sub fill_form { |
127 |
my ( $driver, $values ) = @_; |
128 |
while ( my ( $id, $value ) = each %$values ) { |
129 |
my $element = $driver->find_element('//*[@id="'.$id.'"]'); |
130 |
my $tag = $element->get_tag_name(); |
131 |
if ( $tag eq 'input' ) { |
132 |
$driver->find_element('//input[@id="'.$id.'"]')->send_keys($value); |
133 |
} elsif ( $tag eq 'select' ) { |
134 |
$driver->find_element('//select[@id="'.$id.'"]/option[@value="'.$value.'"]')->click; |
135 |
} |
136 |
} |
137 |
} |
138 |
|
139 |
sub cleanup { |
140 |
my $dbh = C4::Context->dbh; |
141 |
$dbh->do(q|DELETE FROM categories WHERE categorycode = ?|, {}, $sample_data->{category}{categorycode}); |
142 |
$dbh->do(q|DELETE FROM borrowers WHERE userid = ?|, {}, $sample_data->{patron}{userid}); |
143 |
for my $i ( 1 .. $number_of_biblios_to_insert ) { |
144 |
$dbh->do(qq|DELETE FROM biblio WHERE title = "test biblio $i"|); |
145 |
}; |
146 |
|
147 |
$dbh->do(q|DELETE FROM issues where borrowernumber=?|, {}, $borrowernumber); |
148 |
$dbh->do(q|DELETE FROM old_issues where borrowernumber=?|, {}, $borrowernumber); |
149 |
for my $i ( 1 .. $number_of_biblios_to_insert ) { |
150 |
$dbh->do(qq|DELETE items, biblio FROM biblio INNER JOIN items ON biblio.biblionumber = items.biblionumber WHERE biblio.title = "test biblio$i"|); |
151 |
}; |
152 |
} |
153 |
|
154 |
sub time_diff { |
155 |
my $lib = shift; |
156 |
my $now = gettimeofday; |
157 |
warn "CP $lib = " . sprintf("%.2f", $now - $prev_time ) . "\n"; |
158 |
$prev_time = $now; |
159 |
} |