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

(-)a/t/lib/Page/Members/Boraccount.pm (+164 lines)
Line 0 Link Here
1
package t::lib::Page::Members::Boraccount;
2
3
# Copyright 2015 Open Source Freedom Fighters
4
#
5
# This file is part of Koha.
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
use Modern::Perl;
21
use Scalar::Util qw(blessed);
22
use Test::More;
23
24
use base qw(t::lib::Page::Intra t::lib::Page::Members::Toolbar t::lib::Page::Members::LeftNavigation);
25
26
use t::lib::Page::Members::ApiKeys;
27
28
use Koha::Exception::BadParameter;
29
30
=head NAME t::lib::Page::Members::Boraccount
31
32
=head SYNOPSIS
33
34
boraccount.pl PageObject providing page functionality as a service!
35
36
=cut
37
38
=head new
39
40
    my $boraccount = t::lib::Page::Members::Boraccount->new({borrowernumber => "1"});
41
42
Instantiates a WebDriver and loads the members/boraccount.pl.
43
@PARAM1 HASHRef of optional and MANDATORY parameters
44
MANDATORY extra parameters:
45
    borrowernumber => loads the page to display Borrower matching the given borrowernumber
46
47
@RETURNS t::lib::Page::Members::Boraccount, ready for user actions!
48
=cut
49
50
sub new {
51
    my ($class, $params) = @_;
52
    unless (ref($params) eq 'HASH' || (blessed($params) && $params->isa('t::lib::Page') )) {
53
        $params = {};
54
    }
55
    $params->{resource} = '/cgi-bin/koha/members/boraccount.pl';
56
    $params->{type}     = 'staff';
57
58
    $params->{getParams} = [];
59
    #Handle MANDATORY parameters
60
    if ($params->{borrowernumber}) {
61
        push @{$params->{getParams}}, "borrowernumber=".$params->{borrowernumber};
62
    }
63
    else {
64
        Koha::Exception::BadParameter->throw(error => __PACKAGE__."->new():> Parameter 'borrowernumber' is missing.");
65
    }
66
67
    my $self = $class->SUPER::new($params);
68
69
    return $self;
70
}
71
72
################################################################################
73
=head UI Mapping helper subroutines
74
See. Selenium documentation best practices for UI element mapping to common language descriptions.
75
=cut
76
################################################################################
77
78
sub navigateToPayFinesTab {
79
    my ($self) = @_;
80
    my $d = $self->getDriver();
81
    $self->debugTakeSessionSnapshot();
82
83
    my $tab = $d->find_element("div.statictabs ul li a[href*='pay.pl?borrowernumber=']", 'css');
84
    $tab->click();
85
    ok($d->get_title() =~ m/Pay Fines for/, "Intra Navigate to Pay fines tab");
86
87
    $self->debugTakeSessionSnapshot();
88
89
    return t::lib::Page::Members::Pay->rebrandFromPageObject($self);
90
}
91
92
sub findFine {
93
    my ($self, $note) = @_;
94
    my $d = $self->getDriver();
95
    $self->debugTakeSessionSnapshot();
96
97
    my $payment_note = $d->find_element("//td[text() = \"".$note."\"]", "xpath");
98
99
    ok(1, "Intra Found payment with note ".$note);
100
101
    return $self;
102
}
103
104
sub isFinePaid {
105
    my ($self, $note, $noteColumnIndex, $amountOutstandingColumnIndex) = @_;
106
107
    return isFineAmountOutstanding($self, $note, "0.00", $noteColumnIndex, $amountOutstandingColumnIndex);
108
}
109
110
sub isFineAmount {
111
    my ($self, $note, $amount, $noteColumnIndex, $amountColumnIndex) = @_;
112
    my $d = $self->getDriver();
113
    $self->debugTakeSessionSnapshot();
114
115
    $noteColumnIndex = 3 if not defined $noteColumnIndex;
116
    $amountColumnIndex = 4 if not defined $amountColumnIndex;
117
118
    # If POS integration is enabled, add 1 to index (because of column "transaction id")
119
    if (C4::Context->preference("POSIntegration") ne "OFF") {
120
        $noteColumnIndex++;
121
        $amountColumnIndex++;
122
    }
123
124
    my $fine = $d->find_element("//tr[(td[".$noteColumnIndex."][text()=\"".$note."\"]) and (td[".$amountColumnIndex."][text()=\"".$amount."\"])]", "xpath");
125
126
    ok(1, "Intra Found payment with note ".$note." and amount ".$amount);
127
128
    return $self;
129
}
130
131
sub isFineAmountOutstanding {
132
    my ($self, $note, $amountOutstanding, $noteColumnIndex, $amountOutstandingColumnIndex) = @_;
133
    my $d = $self->getDriver();
134
    $self->debugTakeSessionSnapshot();
135
136
    $noteColumnIndex = 3 if not defined $noteColumnIndex;
137
    $amountOutstandingColumnIndex = 5 if not defined $amountOutstandingColumnIndex;
138
139
    # If POS integration is enabled, add 1 to index (because of column "transaction id")
140
    if (C4::Context->preference("POSIntegration") ne "OFF") {
141
        $noteColumnIndex++;
142
        $amountOutstandingColumnIndex++;
143
    }
144
145
    my $fine = $d->find_element("//tr[(td[".$noteColumnIndex."][text()=\"".$note."\"]) and (td[".$amountOutstandingColumnIndex."][text()=\"".$amountOutstanding."\"])]", "xpath");
146
147
    ok(1, "Intra Found payment with note ".$note." and amountoutstanding ".$amountOutstanding);
148
149
    return $self;
150
}
151
152
sub isTransactionComplete {
153
    my ($self, $transactionnumber) = @_;
154
    my $d = $self->getDriver();
155
    $self->debugTakeSessionSnapshot();
156
157
    my $transaction_columns = $d->find_element("//td[contains(\@class, 'transactionnumber') and text() = '".$transactionnumber."']", "xpath");
158
159
    ok(1, "Intra Found transaction, number ".$transactionnumber);
160
161
    return $self;
162
}
163
164
1; #Make the compiler happy!
(-)a/t/lib/Page/Members/Pay.pm (+106 lines)
Line 0 Link Here
1
package t::lib::Page::Members::Pay;
2
3
# Copyright 2015 Open Source Freedom Fighters
4
#
5
# This file is part of Koha.
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
use Modern::Perl;
21
use Scalar::Util qw(blessed);
22
use Test::More;
23
24
use base qw(t::lib::Page::Intra t::lib::Page::Members::Toolbar t::lib::Page::Members::LeftNavigation);
25
26
use t::lib::Page::Members::ApiKeys;
27
28
use Koha::Exception::BadParameter;
29
30
=head NAME t::lib::Page::Members::Pay
31
32
=head SYNOPSIS
33
34
pay.pl PageObject providing page functionality as a service!
35
36
=cut
37
38
=head new
39
40
    my $pay = t::lib::Page::Members::Pay->new({borrowernumber => "1"});
41
42
Instantiates a WebDriver and loads the members/pay.pl.
43
@PARAM1 HASHRef of optional and MANDATORY parameters
44
MANDATORY extra parameters:
45
    borrowernumber => loads the page to display Borrower matching the given borrowernumber
46
47
@RETURNS t::lib::Page::Members::Pay, ready for user actions!
48
=cut
49
50
sub new {
51
    my ($class, $params) = @_;
52
    unless (ref($params) eq 'HASH' || (blessed($params) && $params->isa('t::lib::Page') )) {
53
        $params = {};
54
    }
55
    $params->{resource} = '/cgi-bin/koha/members/pay.pl';
56
    $params->{type}     = 'staff';
57
58
    $params->{getParams} = [];
59
    #Handle MANDATORY parameters
60
    if ($params->{borrowernumber}) {
61
        push @{$params->{getParams}}, "borrowernumber=".$params->{borrowernumber};
62
    }
63
    else {
64
        Koha::Exception::BadParameter->throw(error => __PACKAGE__."->new():> Parameter 'borrowernumber' is missing.");
65
    }
66
67
    my $self = $class->SUPER::new($params);
68
69
    return $self;
70
}
71
72
################################################################################
73
=head UI Mapping helper subroutines
74
See. Selenium documentation best practices for UI element mapping to common language descriptions.
75
=cut
76
################################################################################
77
78
sub PayAmount{
79
    my ($self) = @_;
80
    my $d = $self->getDriver();
81
    $self->debugTakeSessionSnapshot();
82
83
    my $tab = $d->find_element("input[id='paycollect'][type='submit']", 'css');
84
    $tab->click();
85
    ok($d->get_title() =~ m/Collect fine payment for/, "Intra Navigate to Paycollect (all fines)");
86
87
    $self->debugTakeSessionSnapshot();
88
89
    return t::lib::Page::Members::Paycollect->rebrandFromPageObject($self);
90
}
91
92
sub PaySelected {
93
    my ($self) = @_;
94
    my $d = $self->getDriver();
95
    $self->debugTakeSessionSnapshot();
96
97
    my $tab = $d->find_element("input[id='payselected'][type='submit']", 'css');
98
    $tab->click();
99
    ok($d->get_title() =~ m/Collect fine payment for/, "Intra Navigate to Paycollect (selected fines)");
100
101
    $self->debugTakeSessionSnapshot();
102
103
    return t::lib::Page::Members::Paycollect->rebrandFromPageObject($self);
104
}
105
106
1; #Make the compiler happy!
(-)a/t/lib/Page/Members/Paycollect.pm (-1 / +276 lines)
Line 0 Link Here
0
- 
1
package t::lib::Page::Members::Paycollect;
2
3
# Copyright 2015 Open Source Freedom Fighters
4
#
5
# This file is part of Koha.
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
use Modern::Perl;
21
use Scalar::Util qw(blessed);
22
use Test::More;
23
24
use base qw(t::lib::Page::Intra t::lib::Page::Members::Toolbar t::lib::Page::Members::LeftNavigation);
25
26
use t::lib::Page::Members::ApiKeys;
27
28
use Selenium::Remote::WDKeys;
29
30
use Koha::Exception::BadParameter;
31
32
=head NAME t::lib::Page::Members::Paycollect
33
34
=head SYNOPSIS
35
36
paycollect.pl PageObject providing page functionality as a service!
37
38
=cut
39
40
=head new
41
42
    my $paycollect = t::lib::Page::Members::Paycollect->new({borrowernumber => "1", selected => "1,2,3,4,5"});
43
44
Instantiates a WebDriver and loads the members/paycollect.pl.
45
@PARAM1 HASHRef of optional and MANDATORY parameters
46
MANDATORY extra parameters:
47
    borrowernumber => loads the page to display Borrower matching the given borrowernumber
48
49
@RETURNS t::lib::Page::Members::Paycollect, ready for user actions!
50
=cut
51
52
sub new {
53
    my ($class, $params) = @_;
54
    unless (ref($params) eq 'HASH' || (blessed($params) && $params->isa('t::lib::Page') )) {
55
        $params = {};
56
    }
57
    $params->{resource} = '/cgi-bin/koha/members/paycollect.pl';
58
    $params->{type}     = 'staff';
59
60
    $params->{getParams} = [];
61
    #Handle MANDATORY parameters
62
    if ($params->{borrowernumber}) {
63
        push @{$params->{getParams}}, "borrowernumber=".$params->{borrowernumber};
64
    }
65
    else {
66
        Koha::Exception::BadParameter->throw(error => __PACKAGE__."->new():> Parameter 'borrowernumber' is missing.");
67
    }
68
69
    if ($params->{selected}) {
70
        push @{$params->{getParams}}, "selected=".$params->{selected};
71
    }
72
73
    my $self = $class->SUPER::new($params);
74
75
    return $self;
76
}
77
78
################################################################################
79
=head UI Mapping helper subroutines
80
See. Selenium documentation best practices for UI element mapping to common language descriptions.
81
=cut
82
################################################################################
83
84
sub addNewCashRegister {
85
    my ($self, $cashregisternumber) = @_;
86
    my $d = $self->getDriver();
87
    $self->debugTakeSessionSnapshot();
88
89
    my $input = $d->find_element("input[id='office_new']", 'css');
90
    $input->clear();
91
    $input->send_keys($cashregisternumber);
92
    my $button = $d->find_element("button[id='new_office']", 'css');
93
    $button->click();
94
95
    my $ok = 1 if $d->find_element("button[id='office-".$cashregisternumber."']",'css');
96
    ok($ok, "Intra Added a new cash register '".$cashregisternumber."'");
97
98
    $self->debugTakeSessionSnapshot();
99
100
    return $self;
101
}
102
103
sub addNoteToSelected {
104
    my ($self, $note) = @_;
105
    my $d = $self->getDriver();
106
    $self->debugTakeSessionSnapshot();
107
108
    my $input = $d->find_element("textarea[id='selected_accts_notes']", 'css');
109
    $input->clear();
110
    $input->send_keys($note);
111
112
    $self->debugTakeSessionSnapshot();
113
114
    return $self;
115
}
116
117
sub confirmPayment {
118
    my ($self) = @_;
119
    my $d = $self->getDriver();
120
    $self->debugTakeSessionSnapshot();
121
122
    my $confirm = $d->find_element("input[name='submitbutton'][type='submit']",'css');
123
124
    $confirm->click();
125
126
    ok(1, "Intra Confirmed payment");
127
    $self->debugTakeSessionSnapshot();
128
129
    return t::lib::Page::Members::Paycollect->rebrandFromPageObject($self);
130
}
131
132
sub openAddNewCashRegister {
133
    my ($self) = @_;
134
    my $d = $self->getDriver();
135
    $self->debugTakeSessionSnapshot();
136
137
    my $link = $d->find_element("span[id='add_new_office'] a", 'css');
138
    $link->click();
139
    ok($d->find_element("input[id='office_new']",'css'), "Intra Opened input for adding a new cash register");
140
141
    $self->debugTakeSessionSnapshot();
142
143
    return $self;
144
}
145
146
sub paymentLoadingScreen {
147
    my ($self, $cashregisternumber) = @_;
148
    my $d = $self->getDriver();
149
    $self->debugTakeSessionSnapshot();
150
151
    my $ok = 1 if $d->find_element("button[id='recheck']",'css');
152
153
    ok($ok, "Intra Payment loading screen open");
154
155
    return $self;
156
}
157
158
sub selectCashRegister {
159
    my ($self, $cashregisternumber) = @_;
160
    my $d = $self->getDriver();
161
    $self->debugTakeSessionSnapshot();
162
163
    my $cashregister = $d->find_element("button[id='office-".$cashregisternumber."']",'css');
164
165
    $cashregister->click();
166
167
    my $ok = 1 if $d->find_element("button[id='office-".$cashregisternumber."'][class='office-button selected']",'css');
168
    ok($ok, "Intra Selected cash register '".$cashregisternumber."'");
169
    $self->debugTakeSessionSnapshot();
170
171
    return $self;
172
}
173
174
sub sendPaymentToPOS {
175
    my ($self) = @_;
176
    my $d = $self->getDriver();
177
    $self->debugTakeSessionSnapshot();
178
179
    my $confirm = $d->find_element("input[name='submitbutton'][type='submit']",'css');
180
181
    # $confirm->click() is broken. It doesn't move on until AJAX at next page is completed. Need to use
182
    # alternative method. Click submit with JavaScript and poll until loading screen is open.
183
    my $script = q{
184
        $("input[name='submitbutton'][type='submit']").click();
185
    };
186
    $d->execute_script($script);
187
188
    my $func = undef; # we only need to poll for success
189
    my $success = sub {
190
        eval {
191
            my $el = $d->find_element("button[id='recheck']",'css');
192
        };
193
        if ($@) {
194
            return 0;
195
        }
196
        return 1;
197
    };
198
199
    $self->poll($func, $success, 50, 100); # poll for max 5 seconds
200
201
    ok(1, "Intra Sent payment to cash register");
202
    $self->debugTakeSessionSnapshot();
203
204
    return t::lib::Page::Members::Paycollect->rebrandFromPageObject($self);
205
}
206
207
sub setAmount {
208
    my ($self, $amount) = @_;
209
    my $d = $self->getDriver();
210
    $self->debugTakeSessionSnapshot();
211
212
    my $input = $d->find_element("input[name='paid']", 'css');
213
    # Clear and send_keys did not work. Set values by JS
214
    my $script = qq(('#paid').val('$amount'););
215
    $d->execute_script('$'.$script);
216
217
    is($input->get_value(), $amount, "Intra Set payment amount to ".$amount);
218
    $self->debugTakeSessionSnapshot();
219
220
    return $self;
221
}
222
223
sub waitUntilPaymentIsAcceptedAtPOS {
224
    my ($self) = @_;
225
226
    return waitUntilPaymentIsCompletedAtPOS($self, "paid");
227
}
228
sub waitUntilPaymentIsCancelledAtPOS {
229
    my ($self) = @_;
230
231
    return waitUntilPaymentIsCompletedAtPOS($self, "cancelled");
232
}
233
sub waitUntilPaymentIsCompletedAtPOS {
234
    my ($self, $status) = @_;
235
    my $d = $self->getDriver();
236
    $self->debugTakeSessionSnapshot();
237
238
    my $recheck = $d->find_element("button[id='recheck']",'css');
239
240
    my $func = undef; # we only need to poll for success
241
    my $success = sub {
242
        eval {
243
            my $el = $d->find_element("span#status span.".$status."[style*='inline-block']",'css');
244
        };
245
        if ($@) {
246
            return 0;
247
        }
248
        return 1;
249
    };
250
251
    $self->poll($func, $success, 50, 100); # poll for max 5 seconds
252
253
    ok(1, "Payment is completed");
254
    $self->debugTakeSessionSnapshot();
255
256
    # Poll until "recheck" button is not found. This means we have been
257
    # redirected to Boraccount
258
    $func = undef; # we only need to poll for success
259
    $success = sub {
260
        eval {
261
            my $el = $d->find_element("button[id='recheck']",'css');
262
        };
263
        if ($@) {
264
            return 1;
265
        }
266
        return 0;
267
    };
268
269
    $self->poll($func, $success, 50, 100); # poll for max 5 seconds
270
271
    $self->debugTakeSessionSnapshot();
272
273
    return t::lib::Page::Members::Boraccount->rebrandFromPageObject($self);
274
}
275
276
1; #Make the compiler happy!

Return to bug 14536