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 process of the initial Acquisition module setup including creating a currency, budget and fund. |
21 |
|
22 |
# Note: Additional setup of the Acquisition module including the setup of a vendor and creating a basket is performed by a different Selenium test |
23 |
|
24 |
#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 |
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 |
patron => { |
52 |
surname => 'test_patron_surname', |
53 |
cardnumber => '4242424242', |
54 |
userid => 'test_username', |
55 |
password => 'password', |
56 |
password2 => 'password' |
57 |
}, |
58 |
}; |
59 |
|
60 |
my $patronusername="test_username"; |
61 |
my $patronpassword="password"; |
62 |
|
63 |
our ( $borrowernumber, $start, $prev_time, $cleanup_needed ); |
64 |
|
65 |
SKIP: { |
66 |
eval { require Selenium::Remote::Driver; }; |
67 |
skip "Selenium::Remote::Driver is needed for selenium tests.", 20 if $@; |
68 |
|
69 |
$cleanup_needed = 1; |
70 |
|
71 |
open my $fh, '>>', '/tmp/output.txt'; |
72 |
|
73 |
# Go to the mainpage and log in as default user |
74 |
my $driver = Selenium::Remote::Driver->new; |
75 |
$start = gettimeofday; |
76 |
$prev_time = $start; |
77 |
$driver->get($base_url."mainpage.pl"); |
78 |
like( $driver->get_title(), qr(Log in to Koha), ); |
79 |
auth( $driver, $login, $password ); |
80 |
time_diff("main"); |
81 |
|
82 |
#Create a currency |
83 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[1]/div[2]/div/ul/li[2]/a')->click; |
84 |
$driver->pause(20000); |
85 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[2]/div/div/ul[2]/li[4]/a')->click; |
86 |
$driver->pause(20000); |
87 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[1]/a')->click; |
88 |
$driver->pause(20000); |
89 |
$driver->find_element('//input[@id="currency_code"]')->send_keys("USD"); |
90 |
$driver->find_element('//input[@id="rate"]')->send_keys("1"); |
91 |
$driver->find_element('//input[@id="symbol"]')->send_keys('$'); |
92 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[6]/input')->click; |
93 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[2]/input')->click; |
94 |
time_diff("Added currency"); |
95 |
|
96 |
#Create budget |
97 |
$driver->pause(20000); |
98 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[2]/div/div/ul[5]/li[2]/a')->click; |
99 |
$driver->pause(20000); |
100 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[1]/div/a')->click; |
101 |
$driver->pause(20000); |
102 |
$driver->find_element('//input[@id="from"]')->send_keys("07/25/2017"); |
103 |
$driver->find_element('//input[@id="budget_period_total"]')->clear(); |
104 |
$driver->find_element('//input[@id="budget_period_total"]')->send_keys(100); |
105 |
$driver->find_element('//input[@id="to"]')->send_keys("07/30/2017"); |
106 |
$driver->find_element('//input[@id="budget_period_description"]')->send_keys("Test budget2"); |
107 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[5]/input')->click; |
108 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[2]/input')->click; |
109 |
time_diff("Added budget"); |
110 |
|
111 |
#Create fund |
112 |
$driver->pause(20000); |
113 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[2]/div[1]/div/table/tbody/tr[1]/td[6]/div/a')->click; |
114 |
$driver->pause(100); |
115 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[2]/div[1]/div/table/tbody/tr[1]/td[6]/div/ul/li[5]/a')->click; |
116 |
$driver->pause(20000); |
117 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[1]/input')->send_keys("Test"); |
118 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[2]/input')->send_keys("Test fund"); |
119 |
$driver->find_element('//input[@id="budget_amount"]')->clear(); |
120 |
$driver->find_element('//input[@id="budget_amount"]')->send_keys("50"); |
121 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[2]/input[1]')->click; |
122 |
time_diff("Added fund"); |
123 |
|
124 |
close $fh; |
125 |
$driver->quit(); |
126 |
}; |
127 |
|
128 |
END { |
129 |
cleanup() if $cleanup_needed; |
130 |
}; |
131 |
|
132 |
sub auth { |
133 |
my ( $driver, $login, $password) = @_; |
134 |
fill_form( $driver, { userid => 'koha', password => 'koha' } ); |
135 |
my $login_button = $driver->find_element('//input[@id="submit"]'); |
136 |
$login_button->submit(); |
137 |
} |
138 |
|
139 |
sub fill_form { |
140 |
my ( $driver, $values ) = @_; |
141 |
while ( my ( $id, $value ) = each %$values ) { |
142 |
my $element = $driver->find_element('//*[@id="'.$id.'"]'); |
143 |
my $tag = $element->get_tag_name(); |
144 |
if ( $tag eq 'input' ) { |
145 |
$driver->find_element('//input[@id="'.$id.'"]')->send_keys($value); |
146 |
} elsif ( $tag eq 'select' ) { |
147 |
$driver->find_element('//select[@id="'.$id.'"]/option[@value="'.$value.'"]')->click; |
148 |
} |
149 |
} |
150 |
} |
151 |
|
152 |
sub cleanup { |
153 |
my $dbh = C4::Context->dbh; |
154 |
$dbh->do(q|DELETE FROM categories WHERE categorycode = ?|, {}, $sample_data->{category}{categorycode}); |
155 |
$dbh->do(q|DELETE FROM borrowers WHERE userid = ?|, {}, $sample_data->{patron}{userid}); |
156 |
for my $i ( 1 .. $number_of_biblios_to_insert ) { |
157 |
$dbh->do(qq|DELETE FROM biblio WHERE title = "test biblio $i"|); |
158 |
}; |
159 |
|
160 |
$dbh->do(q|DELETE FROM issues where borrowernumber=?|, {}, $borrowernumber); |
161 |
$dbh->do(q|DELETE FROM old_issues where borrowernumber=?|, {}, $borrowernumber); |
162 |
for my $i ( 1 .. $number_of_biblios_to_insert ) { |
163 |
$dbh->do(qq|DELETE items, biblio FROM biblio INNER JOIN items ON biblio.biblionumber = items.biblionumber WHERE biblio.title = "test biblio$i"|); |
164 |
}; |
165 |
} |
166 |
|
167 |
sub time_diff { |
168 |
my $lib = shift; |
169 |
my $now = gettimeofday; |
170 |
warn "CP $lib = " . sprintf("%.2f", $now - $prev_time ) . "\n"; |
171 |
$prev_time = $now; |
172 |
} |