View | Details | Raw Unified | Return to bug 18974
Collapse All | Expand All

(-)a/t/db_dependent/selenium/acquisitionsetup.t (-1 / +171 lines)
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
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
# Remove the rentalcharge:
27
# % UPDATE itemtypes SET rentalcharge = 0;
28
#
29
# Then you can execute the test file.
30
#
31
# If you get:
32
# Wide character in print at /usr/local/share/perl/5.20.2/Test2/Formatter/TAP.pm line 105.
33
# #                   'Koha › Patrons › Add patron test_patron_surname (Adult)'
34
# #     doesn't match '(?^u:Patron details for test_patron_surname)'
35
#
36
# Ignore and retry (FIXME LATER...)
37
38
use Modern::Perl;
39
40
use Time::HiRes qw(gettimeofday);
41
use C4::Context;
42
use C4::Biblio qw( AddBiblio ); # We shouldn't use it
43
44
use Test::More tests => 1;
45
use MARC::Record;
46
use MARC::Field;
47
48
my $dbh = C4::Context->dbh;
49
my $login = 'koha';
50
my $password = 'koha';
51
my $base_url= 'http://'.C4::Context->preference("staffClientBaseURL")."/cgi-bin/koha/";
52
my $opac_url= C4::Context->preference("OPACBaseURL");
53
54
my $number_of_biblios_to_insert = 3;
55
our $sample_data = {
56
    category => {
57
        categorycode    => 'test_cat',
58
        description     => 'test cat description',
59
        enrolmentperiod => '12',
60
        category_type   => 'A'
61
    },
62
    patron => {
63
        surname    => 'test_patron_surname',
64
        cardnumber => '4242424242',
65
        userid     => 'test_username',
66
        password   => 'password',
67
        password2  => 'password'
68
    },
69
};
70
71
my $patronusername="test_username";
72
my $patronpassword="password";
73
74
our ( $borrowernumber, $start, $prev_time, $cleanup_needed );
75
76
SKIP: {
77
    eval { require Selenium::Remote::Driver; };
78
    skip "Selenium::Remote::Driver is needed for selenium tests.", 20 if $@;
79
80
    $cleanup_needed = 1;
81
82
    open my $fh, '>>', '/tmp/output.txt';
83
84
# Go to the mainpage and log in as default user
85
    my $driver = Selenium::Remote::Driver->new;
86
    $start = gettimeofday;
87
    $prev_time = $start;
88
    $driver->get($base_url."mainpage.pl");
89
    like( $driver->get_title(), qr(Log in to Koha), );
90
    auth( $driver, $login, $password );
91
    time_diff("main");
92
93
#Create a currency
94
    $driver->get($base_url.'admin/currency.pl?op=add_form');
95
    $driver->find_element('//input[@id="currency_code"]')->send_keys("USD");
96
    $driver->find_element('//input[@id="rate"]')->send_keys("1");
97
    $driver->find_element('//input[@id="symbol"]')->send_keys('$');
98
    $driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[6]/input')->click;
99
    $driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[2]/input')->click;
100
    time_diff("Added currency");
101
102
#Create budget
103
    $driver->get($base_url.'admin/aqbudgetperiods.pl?op=add_form');
104
    $driver->find_element('//input[@id="from"]')->send_keys("07/25/2017");
105
    $driver->find_element('//input[@id="budget_period_total"]')->clear();
106
    $driver->find_element('//input[@id="budget_period_total"]')->send_keys(100);
107
    $driver->find_element('//input[@id="to"]')->send_keys("07/30/2017");
108
    $driver->find_element('//input[@id="budget_period_description"]')->send_keys("Test budget2");
109
    $driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[5]/input')->click;
110
    $driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[2]/input')->click;
111
    time_diff("Added budget");
112
113
#Create fund 
114
115
    $driver->get($base_url.'admin/aqbudgets.pl?op=add_form&budget_period_id=1');
116
    $driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[1]/input')->send_keys("Test");
117
    $driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[1]/ol/li[2]/input')->send_keys("Test fund");
118
    $driver->find_element('//input[@id="budget_amount"]')->clear();
119
    $driver->find_element('//input[@id="budget_amount"]')->send_keys("50");
120
    $driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/form/fieldset[2]/input[1]')->click;
121
    time_diff("Added fund");
122
123
    close $fh;
124
    $driver->quit();
125
};
126
127
END {
128
    cleanup() if $cleanup_needed;
129
};
130
131
sub auth {
132
    my ( $driver, $login, $password) = @_;
133
    fill_form( $driver, { userid => 'koha', password => 'koha' } );
134
    my $login_button = $driver->find_element('//input[@id="submit"]');
135
    $login_button->submit();
136
}
137
138
sub fill_form {
139
    my ( $driver, $values ) = @_;
140
    while ( my ( $id, $value ) = each %$values ) {
141
        my $element = $driver->find_element('//*[@id="'.$id.'"]');
142
        my $tag = $element->get_tag_name();
143
        if ( $tag eq 'input' ) {
144
            $driver->find_element('//input[@id="'.$id.'"]')->send_keys($value);
145
        } elsif ( $tag eq 'select' ) {
146
            $driver->find_element('//select[@id="'.$id.'"]/option[@value="'.$value.'"]')->click;
147
        }
148
    }
149
}
150
151
sub cleanup {
152
    my $dbh = C4::Context->dbh;
153
    $dbh->do(q|DELETE FROM categories WHERE categorycode = ?|, {}, $sample_data->{category}{categorycode});
154
    $dbh->do(q|DELETE FROM borrowers WHERE userid = ?|, {}, $sample_data->{patron}{userid});
155
    for my $i ( 1 .. $number_of_biblios_to_insert ) {
156
        $dbh->do(qq|DELETE FROM biblio WHERE title = "test biblio $i"|);
157
    };
158
159
    $dbh->do(q|DELETE FROM issues where borrowernumber=?|, {}, $borrowernumber);
160
    $dbh->do(q|DELETE FROM old_issues where borrowernumber=?|, {}, $borrowernumber);
161
    for my $i ( 1 .. $number_of_biblios_to_insert ) {
162
        $dbh->do(qq|DELETE items, biblio FROM biblio INNER JOIN items ON biblio.biblionumber = items.biblionumber WHERE biblio.title = "test biblio$i"|);
163
    };
164
}
165
166
sub time_diff {
167
    my $lib = shift;
168
    my $now = gettimeofday;
169
    warn "CP $lib = " . sprintf("%.2f", $now - $prev_time ) . "\n";
170
    $prev_time = $now;
171
}

Return to bug 18974