Bugzilla – Attachment 47254 Details for
Bug 14536
PageObject-pattern base implementation
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 14536 (follow-up) - New PageObjects for handling Fines
Bug-14536-follow-up---New-PageObjects-for-handling.patch (text/plain), 18.07 KB, created by
Lari Taskula
on 2016-01-25 13:52:47 UTC
(
hide
)
Description:
Bug 14536 (follow-up) - New PageObjects for handling Fines
Filename:
MIME Type:
Creator:
Lari Taskula
Created:
2016-01-25 13:52:47 UTC
Size:
18.07 KB
patch
obsolete
>From d2720503a904ca25d7b8ab1e55bc9dee9ce53203 Mon Sep 17 00:00:00 2001 >From: Lari Taskula <larit@student.uef.fi> >Date: Tue, 15 Dec 2015 09:00:23 +0000 >Subject: [PATCH] Bug 14536 (follow-up) - New PageObjects for handling Fines > >--- > t/lib/Page/Members/Boraccount.pm | 164 +++++++++++++++++++++++ > t/lib/Page/Members/Pay.pm | 106 +++++++++++++++ > t/lib/Page/Members/Paycollect.pm | 276 +++++++++++++++++++++++++++++++++++++++ > 3 files changed, 546 insertions(+) > create mode 100644 t/lib/Page/Members/Boraccount.pm > create mode 100644 t/lib/Page/Members/Pay.pm > create mode 100644 t/lib/Page/Members/Paycollect.pm > >diff --git a/t/lib/Page/Members/Boraccount.pm b/t/lib/Page/Members/Boraccount.pm >new file mode 100644 >index 0000000..f777436 >--- /dev/null >+++ b/t/lib/Page/Members/Boraccount.pm >@@ -0,0 +1,164 @@ >+package t::lib::Page::Members::Boraccount; >+ >+# Copyright 2015 Open Source Freedom Fighters >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+use Scalar::Util qw(blessed); >+use Test::More; >+ >+use base qw(t::lib::Page::Intra t::lib::Page::Members::Toolbar t::lib::Page::Members::LeftNavigation); >+ >+use t::lib::Page::Members::ApiKeys; >+ >+use Koha::Exception::BadParameter; >+ >+=head NAME t::lib::Page::Members::Boraccount >+ >+=head SYNOPSIS >+ >+boraccount.pl PageObject providing page functionality as a service! >+ >+=cut >+ >+=head new >+ >+ my $boraccount = t::lib::Page::Members::Boraccount->new({borrowernumber => "1"}); >+ >+Instantiates a WebDriver and loads the members/boraccount.pl. >+@PARAM1 HASHRef of optional and MANDATORY parameters >+MANDATORY extra parameters: >+ borrowernumber => loads the page to display Borrower matching the given borrowernumber >+ >+@RETURNS t::lib::Page::Members::Boraccount, ready for user actions! >+=cut >+ >+sub new { >+ my ($class, $params) = @_; >+ unless (ref($params) eq 'HASH' || (blessed($params) && $params->isa('t::lib::Page') )) { >+ $params = {}; >+ } >+ $params->{resource} = '/cgi-bin/koha/members/boraccount.pl'; >+ $params->{type} = 'staff'; >+ >+ $params->{getParams} = []; >+ #Handle MANDATORY parameters >+ if ($params->{borrowernumber}) { >+ push @{$params->{getParams}}, "borrowernumber=".$params->{borrowernumber}; >+ } >+ else { >+ Koha::Exception::BadParameter->throw(error => __PACKAGE__."->new():> Parameter 'borrowernumber' is missing."); >+ } >+ >+ my $self = $class->SUPER::new($params); >+ >+ return $self; >+} >+ >+################################################################################ >+=head UI Mapping helper subroutines >+See. Selenium documentation best practices for UI element mapping to common language descriptions. >+=cut >+################################################################################ >+ >+sub navigateToPayFinesTab { >+ my ($self) = @_; >+ my $d = $self->getDriver(); >+ $self->debugTakeSessionSnapshot(); >+ >+ my $tab = $d->find_element("div.statictabs ul li a[href*='pay.pl?borrowernumber=']", 'css'); >+ $tab->click(); >+ ok($d->get_title() =~ m/Pay Fines for/, "Intra Navigate to Pay fines tab"); >+ >+ $self->debugTakeSessionSnapshot(); >+ >+ return t::lib::Page::Members::Pay->rebrandFromPageObject($self); >+} >+ >+sub findFine { >+ my ($self, $note) = @_; >+ my $d = $self->getDriver(); >+ $self->debugTakeSessionSnapshot(); >+ >+ my $payment_note = $d->find_element("//td[text() = \"".$note."\"]", "xpath"); >+ >+ ok(1, "Intra Found payment with note ".$note); >+ >+ return $self; >+} >+ >+sub isFinePaid { >+ my ($self, $note, $noteColumnIndex, $amountOutstandingColumnIndex) = @_; >+ >+ return isFineAmountOutstanding($self, $note, "0.00", $noteColumnIndex, $amountOutstandingColumnIndex); >+} >+ >+sub isFineAmount { >+ my ($self, $note, $amount, $noteColumnIndex, $amountColumnIndex) = @_; >+ my $d = $self->getDriver(); >+ $self->debugTakeSessionSnapshot(); >+ >+ $noteColumnIndex = 3 if not defined $noteColumnIndex; >+ $amountColumnIndex = 4 if not defined $amountColumnIndex; >+ >+ # If POS integration is enabled, add 1 to index (because of column "transaction id") >+ if (C4::Context->preference("POSIntegration") ne "OFF") { >+ $noteColumnIndex++; >+ $amountColumnIndex++; >+ } >+ >+ my $fine = $d->find_element("//tr[(td[".$noteColumnIndex."][text()=\"".$note."\"]) and (td[".$amountColumnIndex."][text()=\"".$amount."\"])]", "xpath"); >+ >+ ok(1, "Intra Found payment with note ".$note." and amount ".$amount); >+ >+ return $self; >+} >+ >+sub isFineAmountOutstanding { >+ my ($self, $note, $amountOutstanding, $noteColumnIndex, $amountOutstandingColumnIndex) = @_; >+ my $d = $self->getDriver(); >+ $self->debugTakeSessionSnapshot(); >+ >+ $noteColumnIndex = 3 if not defined $noteColumnIndex; >+ $amountOutstandingColumnIndex = 5 if not defined $amountOutstandingColumnIndex; >+ >+ # If POS integration is enabled, add 1 to index (because of column "transaction id") >+ if (C4::Context->preference("POSIntegration") ne "OFF") { >+ $noteColumnIndex++; >+ $amountOutstandingColumnIndex++; >+ } >+ >+ my $fine = $d->find_element("//tr[(td[".$noteColumnIndex."][text()=\"".$note."\"]) and (td[".$amountOutstandingColumnIndex."][text()=\"".$amountOutstanding."\"])]", "xpath"); >+ >+ ok(1, "Intra Found payment with note ".$note." and amountoutstanding ".$amountOutstanding); >+ >+ return $self; >+} >+ >+sub isTransactionComplete { >+ my ($self, $transactionnumber) = @_; >+ my $d = $self->getDriver(); >+ $self->debugTakeSessionSnapshot(); >+ >+ my $transaction_columns = $d->find_element("//td[contains(\@class, 'transactionnumber') and text() = '".$transactionnumber."']", "xpath"); >+ >+ ok(1, "Intra Found transaction, number ".$transactionnumber); >+ >+ return $self; >+} >+ >+1; #Make the compiler happy! >diff --git a/t/lib/Page/Members/Pay.pm b/t/lib/Page/Members/Pay.pm >new file mode 100644 >index 0000000..581d882 >--- /dev/null >+++ b/t/lib/Page/Members/Pay.pm >@@ -0,0 +1,106 @@ >+package t::lib::Page::Members::Pay; >+ >+# Copyright 2015 Open Source Freedom Fighters >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+use Scalar::Util qw(blessed); >+use Test::More; >+ >+use base qw(t::lib::Page::Intra t::lib::Page::Members::Toolbar t::lib::Page::Members::LeftNavigation); >+ >+use t::lib::Page::Members::ApiKeys; >+ >+use Koha::Exception::BadParameter; >+ >+=head NAME t::lib::Page::Members::Pay >+ >+=head SYNOPSIS >+ >+pay.pl PageObject providing page functionality as a service! >+ >+=cut >+ >+=head new >+ >+ my $pay = t::lib::Page::Members::Pay->new({borrowernumber => "1"}); >+ >+Instantiates a WebDriver and loads the members/pay.pl. >+@PARAM1 HASHRef of optional and MANDATORY parameters >+MANDATORY extra parameters: >+ borrowernumber => loads the page to display Borrower matching the given borrowernumber >+ >+@RETURNS t::lib::Page::Members::Pay, ready for user actions! >+=cut >+ >+sub new { >+ my ($class, $params) = @_; >+ unless (ref($params) eq 'HASH' || (blessed($params) && $params->isa('t::lib::Page') )) { >+ $params = {}; >+ } >+ $params->{resource} = '/cgi-bin/koha/members/pay.pl'; >+ $params->{type} = 'staff'; >+ >+ $params->{getParams} = []; >+ #Handle MANDATORY parameters >+ if ($params->{borrowernumber}) { >+ push @{$params->{getParams}}, "borrowernumber=".$params->{borrowernumber}; >+ } >+ else { >+ Koha::Exception::BadParameter->throw(error => __PACKAGE__."->new():> Parameter 'borrowernumber' is missing."); >+ } >+ >+ my $self = $class->SUPER::new($params); >+ >+ return $self; >+} >+ >+################################################################################ >+=head UI Mapping helper subroutines >+See. Selenium documentation best practices for UI element mapping to common language descriptions. >+=cut >+################################################################################ >+ >+sub PayAmount{ >+ my ($self) = @_; >+ my $d = $self->getDriver(); >+ $self->debugTakeSessionSnapshot(); >+ >+ my $tab = $d->find_element("input[id='paycollect'][type='submit']", 'css'); >+ $tab->click(); >+ ok($d->get_title() =~ m/Collect fine payment for/, "Intra Navigate to Paycollect (all fines)"); >+ >+ $self->debugTakeSessionSnapshot(); >+ >+ return t::lib::Page::Members::Paycollect->rebrandFromPageObject($self); >+} >+ >+sub PaySelected { >+ my ($self) = @_; >+ my $d = $self->getDriver(); >+ $self->debugTakeSessionSnapshot(); >+ >+ my $tab = $d->find_element("input[id='payselected'][type='submit']", 'css'); >+ $tab->click(); >+ ok($d->get_title() =~ m/Collect fine payment for/, "Intra Navigate to Paycollect (selected fines)"); >+ >+ $self->debugTakeSessionSnapshot(); >+ >+ return t::lib::Page::Members::Paycollect->rebrandFromPageObject($self); >+} >+ >+1; #Make the compiler happy! >diff --git a/t/lib/Page/Members/Paycollect.pm b/t/lib/Page/Members/Paycollect.pm >new file mode 100644 >index 0000000..3ea1287 >--- /dev/null >+++ b/t/lib/Page/Members/Paycollect.pm >@@ -0,0 +1,276 @@ >+package t::lib::Page::Members::Paycollect; >+ >+# Copyright 2015 Open Source Freedom Fighters >+# >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+use Scalar::Util qw(blessed); >+use Test::More; >+ >+use base qw(t::lib::Page::Intra t::lib::Page::Members::Toolbar t::lib::Page::Members::LeftNavigation); >+ >+use t::lib::Page::Members::ApiKeys; >+ >+use Selenium::Remote::WDKeys; >+ >+use Koha::Exception::BadParameter; >+ >+=head NAME t::lib::Page::Members::Paycollect >+ >+=head SYNOPSIS >+ >+paycollect.pl PageObject providing page functionality as a service! >+ >+=cut >+ >+=head new >+ >+ my $paycollect = t::lib::Page::Members::Paycollect->new({borrowernumber => "1", selected => "1,2,3,4,5"}); >+ >+Instantiates a WebDriver and loads the members/paycollect.pl. >+@PARAM1 HASHRef of optional and MANDATORY parameters >+MANDATORY extra parameters: >+ borrowernumber => loads the page to display Borrower matching the given borrowernumber >+ >+@RETURNS t::lib::Page::Members::Paycollect, ready for user actions! >+=cut >+ >+sub new { >+ my ($class, $params) = @_; >+ unless (ref($params) eq 'HASH' || (blessed($params) && $params->isa('t::lib::Page') )) { >+ $params = {}; >+ } >+ $params->{resource} = '/cgi-bin/koha/members/paycollect.pl'; >+ $params->{type} = 'staff'; >+ >+ $params->{getParams} = []; >+ #Handle MANDATORY parameters >+ if ($params->{borrowernumber}) { >+ push @{$params->{getParams}}, "borrowernumber=".$params->{borrowernumber}; >+ } >+ else { >+ Koha::Exception::BadParameter->throw(error => __PACKAGE__."->new():> Parameter 'borrowernumber' is missing."); >+ } >+ >+ if ($params->{selected}) { >+ push @{$params->{getParams}}, "selected=".$params->{selected}; >+ } >+ >+ my $self = $class->SUPER::new($params); >+ >+ return $self; >+} >+ >+################################################################################ >+=head UI Mapping helper subroutines >+See. Selenium documentation best practices for UI element mapping to common language descriptions. >+=cut >+################################################################################ >+ >+sub addNewCashRegister { >+ my ($self, $cashregisternumber) = @_; >+ my $d = $self->getDriver(); >+ $self->debugTakeSessionSnapshot(); >+ >+ my $input = $d->find_element("input[id='office_new']", 'css'); >+ $input->clear(); >+ $input->send_keys($cashregisternumber); >+ my $button = $d->find_element("button[id='new_office']", 'css'); >+ $button->click(); >+ >+ my $ok = 1 if $d->find_element("button[id='office-".$cashregisternumber."']",'css'); >+ ok($ok, "Intra Added a new cash register '".$cashregisternumber."'"); >+ >+ $self->debugTakeSessionSnapshot(); >+ >+ return $self; >+} >+ >+sub addNoteToSelected { >+ my ($self, $note) = @_; >+ my $d = $self->getDriver(); >+ $self->debugTakeSessionSnapshot(); >+ >+ my $input = $d->find_element("textarea[id='selected_accts_notes']", 'css'); >+ $input->clear(); >+ $input->send_keys($note); >+ >+ $self->debugTakeSessionSnapshot(); >+ >+ return $self; >+} >+ >+sub confirmPayment { >+ my ($self) = @_; >+ my $d = $self->getDriver(); >+ $self->debugTakeSessionSnapshot(); >+ >+ my $confirm = $d->find_element("input[name='submitbutton'][type='submit']",'css'); >+ >+ $confirm->click(); >+ >+ ok(1, "Intra Confirmed payment"); >+ $self->debugTakeSessionSnapshot(); >+ >+ return t::lib::Page::Members::Paycollect->rebrandFromPageObject($self); >+} >+ >+sub openAddNewCashRegister { >+ my ($self) = @_; >+ my $d = $self->getDriver(); >+ $self->debugTakeSessionSnapshot(); >+ >+ my $link = $d->find_element("span[id='add_new_office'] a", 'css'); >+ $link->click(); >+ ok($d->find_element("input[id='office_new']",'css'), "Intra Opened input for adding a new cash register"); >+ >+ $self->debugTakeSessionSnapshot(); >+ >+ return $self; >+} >+ >+sub paymentLoadingScreen { >+ my ($self, $cashregisternumber) = @_; >+ my $d = $self->getDriver(); >+ $self->debugTakeSessionSnapshot(); >+ >+ my $ok = 1 if $d->find_element("button[id='recheck']",'css'); >+ >+ ok($ok, "Intra Payment loading screen open"); >+ >+ return $self; >+} >+ >+sub selectCashRegister { >+ my ($self, $cashregisternumber) = @_; >+ my $d = $self->getDriver(); >+ $self->debugTakeSessionSnapshot(); >+ >+ my $cashregister = $d->find_element("button[id='office-".$cashregisternumber."']",'css'); >+ >+ $cashregister->click(); >+ >+ my $ok = 1 if $d->find_element("button[id='office-".$cashregisternumber."'][class='office-button selected']",'css'); >+ ok($ok, "Intra Selected cash register '".$cashregisternumber."'"); >+ $self->debugTakeSessionSnapshot(); >+ >+ return $self; >+} >+ >+sub sendPaymentToPOS { >+ my ($self) = @_; >+ my $d = $self->getDriver(); >+ $self->debugTakeSessionSnapshot(); >+ >+ my $confirm = $d->find_element("input[name='submitbutton'][type='submit']",'css'); >+ >+ # $confirm->click() is broken. It doesn't move on until AJAX at next page is completed. Need to use >+ # alternative method. Click submit with JavaScript and poll until loading screen is open. >+ my $script = q{ >+ $("input[name='submitbutton'][type='submit']").click(); >+ }; >+ $d->execute_script($script); >+ >+ my $func = undef; # we only need to poll for success >+ my $success = sub { >+ eval { >+ my $el = $d->find_element("button[id='recheck']",'css'); >+ }; >+ if ($@) { >+ return 0; >+ } >+ return 1; >+ }; >+ >+ $self->poll($func, $success, 50, 100); # poll for max 5 seconds >+ >+ ok(1, "Intra Sent payment to cash register"); >+ $self->debugTakeSessionSnapshot(); >+ >+ return t::lib::Page::Members::Paycollect->rebrandFromPageObject($self); >+} >+ >+sub setAmount { >+ my ($self, $amount) = @_; >+ my $d = $self->getDriver(); >+ $self->debugTakeSessionSnapshot(); >+ >+ my $input = $d->find_element("input[name='paid']", 'css'); >+ # Clear and send_keys did not work. Set values by JS >+ my $script = qq(('#paid').val('$amount');); >+ $d->execute_script('$'.$script); >+ >+ is($input->get_value(), $amount, "Intra Set payment amount to ".$amount); >+ $self->debugTakeSessionSnapshot(); >+ >+ return $self; >+} >+ >+sub waitUntilPaymentIsAcceptedAtPOS { >+ my ($self) = @_; >+ >+ return waitUntilPaymentIsCompletedAtPOS($self, "paid"); >+} >+sub waitUntilPaymentIsCancelledAtPOS { >+ my ($self) = @_; >+ >+ return waitUntilPaymentIsCompletedAtPOS($self, "cancelled"); >+} >+sub waitUntilPaymentIsCompletedAtPOS { >+ my ($self, $status) = @_; >+ my $d = $self->getDriver(); >+ $self->debugTakeSessionSnapshot(); >+ >+ my $recheck = $d->find_element("button[id='recheck']",'css'); >+ >+ my $func = undef; # we only need to poll for success >+ my $success = sub { >+ eval { >+ my $el = $d->find_element("span#status span.".$status."[style*='inline-block']",'css'); >+ }; >+ if ($@) { >+ return 0; >+ } >+ return 1; >+ }; >+ >+ $self->poll($func, $success, 50, 100); # poll for max 5 seconds >+ >+ ok(1, "Payment is completed"); >+ $self->debugTakeSessionSnapshot(); >+ >+ # Poll until "recheck" button is not found. This means we have been >+ # redirected to Boraccount >+ $func = undef; # we only need to poll for success >+ $success = sub { >+ eval { >+ my $el = $d->find_element("button[id='recheck']",'css'); >+ }; >+ if ($@) { >+ return 1; >+ } >+ return 0; >+ }; >+ >+ $self->poll($func, $success, 50, 100); # poll for max 5 seconds >+ >+ $self->debugTakeSessionSnapshot(); >+ >+ return t::lib::Page::Members::Boraccount->rebrandFromPageObject($self); >+} >+ >+1; #Make the compiler happy! >-- >1.9.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 14536
:
41023
|
41052
|
41057
|
41121
|
41156
|
41254
|
41460
|
41524
|
41525
|
41534
|
41678
|
42060
|
42111
|
42118
|
42136
|
42160
|
42433
|
42435
|
42716
|
44410
|
47254
|
63245