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

(-)a/t/db_dependent/selenium/installkoha.t (-1 / +228 lines)
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 is to test the Koha web installer and onboarding tool. Before running the test make sure you have restarted memcached and have dropped and recreated the Koha database.
21
22
# Note: When running the test database errors will be displayed initially however just ignore those errors and the test output will be displayed below it
23
24
# Note: The staffClientBaseURL has been set manually to localhost:8080 and the OPACBaseURL to localhost:80. If you do not usually access the intranet with port 8081 and the opac with port 8080 then you will need to change the addresses in this test accordingly
25
26
use Modern::Perl;
27
28
use Time::HiRes qw(gettimeofday);
29
use C4::Context;
30
use C4::Biblio qw( AddBiblio ); # We shouldn't use it
31
32
use Test::More tests => 1;
33
use MARC::Record;
34
use MARC::Field;
35
36
my $dbh = C4::Context->dbh;
37
my $login = 'koha_kohadev';
38
my $password = 'password';
39
40
our $sample_data = {
41
    category => {
42
        categorycode    => 'test_cat',
43
        description     => 'test cat description',
44
        enrolmentperiod => '12',
45
        category_type   => 'A'
46
    },
47
    patron => {
48
        surname    => 'test_patron_surname',
49
        cardnumber => '4242424242',
50
        userid     => 'test_username',
51
        password   => 'password',
52
        password2  => 'password'
53
    },
54
};
55
56
my $patronusername="test_username";
57
my $patronpassword="password";
58
59
our ( $borrowernumber, $start, $prev_time, $cleanup_needed );
60
61
SKIP: {
62
    eval { require Selenium::Remote::Driver; };
63
    skip "Selenium::Remote::Driver is needed for selenium tests.", 20 if $@;
64
65
    $cleanup_needed = 1;
66
67
    open my $fh, '>>', '/tmp/output.txt';
68
69
    my $driver = Selenium::Remote::Driver->new;
70
    $start = gettimeofday;
71
    $prev_time = $start;
72
    $driver->get("http://localhost:8080/cgi-bin/koha/mainpage.pl");
73
    auth( $driver, $login, $password );
74
    time_diff("main");
75
76
    #Select a language
77
    $driver->find_element_by_xpath('/html/body/div/div/div/form/div/select')->click();
78
    $driver->find_element('//option[@value="en"]')->click();
79
    $driver->find_element_by_xpath('/html/body/div/div/div/form/p/input')->click();
80
    time_diff("Selected english language");
81
82
    $driver->maximize_window();
83
    $driver->pause(50000);
84
    warn $driver->get_title();
85
86
    #Check perl dependencies
87
    $driver->pause(20000);
88
    $driver->find_element_by_xpath('/html/body/div/div/div/form/p/input')->click();
89
    time_diff("Continued through checking perl dependencies");
90
91
    #Check database settings
92
    $driver->find_element_by_xpath('/html/body/div/div/div/form/p/input')->click();
93
    $driver->find_element_by_xpath('/html/body/div/div/div/form/p/input')->click();
94
    time_diff("Continued through checking database settings");
95
96
    #Setup database
97
    $driver->find_element_by_xpath('/html/body/div/div/div/form/p/input')->click();
98
    $driver->find_element_by_xpath('/html/body/div/div/div/form/p/input')->click();
99
    time_diff("Database set up");
100
101
    #Install basic configs
102
    $driver->find_element_by_xpath('/html/body/div/div/div/p[2]/a')->click();
103
    time_diff("Basic configs installed");
104
105
    $driver->maximize_window();
106
    $driver->pause(50000);
107
108
    #Select MARC flavour
109
    warn $driver->get_title();
110
    $driver->find_element('//input[@value="Continue to the next step"]')->click;
111
    time_diff("MARC21 installed");
112
113
    #Install default settings 
114
    $driver->find_element_by_xpath('/html/body/div/div/div/form/p[2]/input')->click();
115
    $driver->pause(20000);
116
    $driver->find_element_by_xpath('/html/body/div/div/div/form/p[2]/input')->click();
117
    time_diff("Default settings installed");
118
119
    #Start onboarding tool
120
#$driver->pause(20000);
121
    warn $driver->get_title();
122
    $driver->find_element_by_xpath('/html/body/div/div/div/p/a')->click();
123
    time_diff("Start onboarding tool");
124
125
    #Onboarding tool create a library
126
    $driver->pause(50000);
127
    warn $driver->get_title();
128
    $driver->find_element_by_xpath('/html/body/div/div/div/form/fieldset/ol/li[1]/input')->send_keys("Test");
129
    $driver->find_element_by_xpath('/html/body/div/div/div/form/fieldset/ol/li[2]/input')->send_keys("Test library");
130
    $driver->find_element_by_xpath('/html/body/div/div/div/form/fieldset/input[3]')->click();
131
    time_diff("Library created");
132
133
    #Onboarding tool create a patron category
134
    $driver->find_element_by_xpath('/html/body/div[1]/div/div/form/fieldset/ol/li[1]/input')->send_keys("PAT");
135
    $driver->find_element_by_xpath('/html/body/div[1]/div/div/form/fieldset/ol/li[2]/input')->send_keys("Test patron category");
136
    $driver->find_element_by_xpath('/html/body/div[1]/div/div/form/fieldset/ol/li[6]/fieldset/ol/li[3]/input')->send_keys('07/29/2020');
137
    $driver->find_element_by_xpath('/html/body/div[1]/div/div/form/fieldset/input[3]')->click;
138
    time_diff("Patron category created");
139
140
    $driver->set_window_size(1000, 1000);
141
    $driver->maximize_window();
142
143
    #Onboarding tool Create Koha adminstrator patron
144
    $driver->pause(50000);
145
    warn $driver->get_title();
146
    $driver->find_element_by_xpath('/html/body/div/div/div/form/fieldset/ol[1]/li[1]/input')->send_keys("Smith");
147
    $driver->find_element_by_xpath('/html/body/div/div/div/form/fieldset/ol[1]/li[2]/input')->send_keys("Mary");
148
149
    $driver->pause(50000);
150
    warn $driver->get_title();
151
    $driver->find_element_by_xpath('/html/body/div/div/div/form/fieldset/ol[2]/li[1]/input')->send_keys("10203");
152
    $driver->find_element_by_xpath('/html/body/div/div/div/form/fieldset/ol[4]/li[1]/input')->send_keys("Mary");
153
    $driver->find_element_by_xpath('/html/body/div/div/div/form/fieldset/ol[4]/li[2]/input')->send_keys("password");
154
    $driver->find_element_by_xpath('/html/body/div/div/div/form/fieldset/ol[4]/li[3]/input')->send_keys("password");
155
    $driver->find_element_by_xpath('/html/body/div/div/div/form/input')->click();
156
    time_diff("Create administrator patron");
157
158
    #Onboarding tool Create item type
159
    $driver->find_element_by_xpath('/html/body/div/div/div/form/fieldset/ol/li[1]/input')->send_keys("BOOK");
160
    $driver->find_element_by_xpath('/html/body/div/div/div/form/fieldset/ol/li[2]/input')->send_keys("Non-electronic book");
161
    $driver->find_element_by_xpath('/html/body/div/div/div/form/fieldset/input[3]')->click();
162
    time_diff("Item type created");
163
164
    #Onboarding to Create circulation rule
165
    $driver->find_element_by_xpath('/html/body/div/div/div/form/input')->click();
166
    $driver->find_element_by_xpath('/html/body/div/div/div/a')->click();
167
    time_diff("Circulation rule created");
168
169
    #Login to Koha
170
    $driver->find_element_by_xpath('/html/body/div/div/div/form/p[1]/input')->send_keys("Mary");
171
    $driver->find_element_by_xpath('/html/body/div/div/div/form/p[2]/input')->send_keys("password");
172
    $driver->find_element_by_xpath('/html/body/div/div/div/form/p[4]/input')->click();
173
    like( $driver->get_title(), qr(Koha staff client), );
174
175
    close $fh;
176
    $driver->quit();
177
};
178
179
END {
180
    cleanup() if $cleanup_needed;
181
};
182
183
sub auth {
184
    my ( $driver, $login, $password) = @_;
185
    fill_form( $driver, { userid => 'koha_kohadev', password => 'password' } );
186
    my $login_button = $driver->find_element_by_xpath('/html/body/div/div/div/form/fieldset/input');
187
    $login_button->submit();
188
}
189
190
sub patron_auth {
191
    my ( $driver,$patronusername, $patronpassword) = @_;
192
    fill_form( $driver, { userid => $patronusername, password => $patronpassword } );
193
    my $login_button = $driver->find_element('//input[@id="submit"]');
194
    $login_button->submit();
195
}
196
197
sub patron_opac_auth {
198
    my ( $driver,$patronusername, $patronpassword) = @_;
199
    fill_form( $driver, { userid => $patronusername, password => $patronpassword } );
200
    my $login_button = $driver->find_element('//input[@value="Log in"]');
201
    $login_button->submit();
202
}
203
204
sub fill_form {
205
    my ( $driver, $values ) = @_;
206
    while ( my ( $id, $value ) = each %$values ) {
207
        my $element = $driver->find_element('//*[@id="'.$id.'"]');
208
        my $tag = $element->get_tag_name();
209
        if ( $tag eq 'input' ) {
210
            $driver->find_element('//input[@id="'.$id.'"]')->send_keys($value);
211
        } elsif ( $tag eq 'select' ) {
212
            $driver->find_element('//select[@id="'.$id.'"]/option[@value="'.$value.'"]')->click;
213
        }
214
    }
215
}
216
217
sub cleanup {
218
    my $dbh = C4::Context->dbh;
219
    $dbh->do(q|DELETE FROM categories WHERE categorycode = ?|, {}, $sample_data->{category}{categorycode});
220
    $dbh->do(q|DELETE FROM borrowers WHERE userid = ?|, {}, $sample_data->{patron}{userid});
221
}
222
223
sub time_diff {
224
    my $lib = shift;
225
    my $now = gettimeofday;
226
    warn "CP $lib = " . sprintf("%.2f", $now - $prev_time ) . "\n";
227
    $prev_time = $now;
228
}

Return to bug 19185