From a972addb2a8b275cadabd3e5479cb2d88785e08d Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 27 Dec 2017 10:01:27 -0300 Subject: [PATCH] Bug 19883: Add a selenium script to hit all the pages The idea here would be to catch possible hidden issues, and especially when the requested data do not exist (for instance hit circulation.pl?borrowernumber=42 without borrowernumber=42 in your DB). All these pages must not return 500. This is not ready at all for inclusion for several reasons: - Based on existing data (id=1 most of the time) - DB will be modified - Not idempotent - All pages are not covered (TODO) --- t/db_dependent/selenium/hit_pages.t | 564 ++++++++++++++++++++++++++++++++++++ 1 file changed, 564 insertions(+) create mode 100644 t/db_dependent/selenium/hit_pages.t diff --git a/t/db_dependent/selenium/hit_pages.t b/t/db_dependent/selenium/hit_pages.t new file mode 100644 index 0000000000..cbda464b99 --- /dev/null +++ b/t/db_dependent/selenium/hit_pages.t @@ -0,0 +1,564 @@ +#!/usr/bin/perl + +# 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 . + +use Modern::Perl; + +use C4::Context; + +use Test::More; +use MARC::Record; +use MARC::Field; + +my $number_of_tests; +plan tests => $number_of_tests; + +my $dbh = C4::Context->dbh; +my $login = $ENV{KOHA_USER} || 'koha'; +my $password = $ENV{KOHA_PASS} || 'koha'; +my $base_url= ( $ENV{KOHA_INTRANET_URL} || C4::Context->preference("staffClientBaseURL") ) . "/cgi-bin/koha/"; +my $selenium_addr = $ENV{SELENIUM_ADDR} || 'localhost'; +my $selenium_port = $ENV{SELENIUM_PORT} || 4444; + +# Avoid "undef error - round() overflow. Try smaller precision or use Math::BigFloat" +$dbh->do(q|update aqbudgets set budget_encumb=0, budget_expend=0|); + +my @pages; + +# root +BEGIN { $number_of_tests += 4 } +push @pages, qw( +about.pl +edithelp.pl +help.pl +mainpage.pl +); + +# admin +BEGIN { $number_of_tests += 70 } +push @pages, qw( +admin/admin-home.pl +admin/aqbudgetperiods.pl +admin/aqbudgetperiods.pl?op=add_form&budget_period_id=1 +admin/aqbudgetperiods.pl?op=delete_confirm +admin/aqbudgets.pl +admin/aqbudgets.pl?budget_period_id=1 +admin/aqbudgets.pl?op=add_form&budget_id=1&budget_period_id=1 +admin/aqbudgets.pl?op=delete_confirm&budget_id=1&budget_period_id=1 +~admin/aqcontract.pl +admin/aqcontract.pl?op=add_form&booksellerid=1 +~admin/aqcontract.pl?op=add_form&contractnumber=1&booksellerid=1 +~admin/aqcontract.pl?op=delete_confirm&contractnumber=1&booksellerid=1 +admin/aqplan.pl +admin/aqplan.pl?budget_period_id=1 +admin/audio_alerts.pl +admin/authorised_values.pl +admin/authorised_values.pl?op=add_form +admin/authorised_values.pl?searchfield=LOST +admin/authorised_values.pl?op=add_form&id=1 +admin/authorised_values.pl?op=delete&id=1 +admin/auth_subfields_structure.pl +admin/auth_tag_structure.pl +admin/authtypes.pl +admin/biblio_framework.pl +admin/biblio_framework.pl?op=add_form +admin/biblio_framework.pl?op=add_form&frameworkcode=FA +admin/biblio_framework.pl?op=delete_confirm&frameworkcode=FA +admin/branches.pl +admin/branches.pl?op=add_form +admin/branches.pl?op=add_form&branchcode=CPL +admin/branches.pl?op=delete_confirm&branchcode=CPL +~admin/branches.pl?categorycode=CAT&op=add_form_category +~admin/branches.pl?categorycode=CAT&op=delete_confirm_category +admin/branch_transfer_limits.pl +admin/categories.pl +admin/categories.pl?op=add_form +admin/categories.pl?op=add_form&categorycode=S +admin/categories.pl?op=delete_confirm&categorycode=S +admin/checkmarc.pl +admin/cities.pl +admin/cities.pl?op=add_form +admin/cities.pl?op=add_form&cityid=1 +admin/cities.pl?op=delete_confirm&cityid=1 +admin/classsources.pl +admin/clone-rules.pl +admin/columns_settings.pl +admin/currency.pl +admin/currency.pl?op=add_form +admin/currency.pl?op=add_form¤cy_code=EUR +admin/currency.pl?op=delete_confirm¤cy_code=EUR +admin/didyoumean.pl +admin/edi_accounts.pl +admin/edi_ean_accounts.pl +admin/fieldmapping.pl +admin/import_export_framework.pl +admin/item_circulation_alerts.pl +admin/items_search_field.pl +admin/items_search_fields.pl +admin/itemtypes.pl +admin/itemtypes.pl?op=add_form +admin/itemtypes.pl?op=add_form&itemtype=BK +admin/itemtypes.pl?op=delete_confirm&itemtype=BK +admin/koha2marclinks.pl +admin/localization.pl +admin/marc_subfields_structure.pl +admin/marctagstructure.pl +admin/matching-rules.pl +admin/oai_set_mappings.pl +admin/oai_sets.pl +admin/patron-attr-types.pl +admin/preferences.pl +admin/printers.pl +admin/searchengine/elasticsearch/mappings.pl +admin/smart-rules.pl +admin/sms_providers.pl +admin/sru_modmapping.pl +admin/systempreferences.pl +admin/transport-cost-matrix.pl +admin/usage_statistics.pl +admin/z3950servers.pl +admin/z3950servers.pl?op=add&type=zed +admin/z3950servers.pl?op=add&type=sru +admin/z3950servers.pl?op=edit&id=1 +admin/z3950servers.pl?op=add&id=1 +admin/z3950servers.pl?op=delete_confirmed&id=1 +); + +# acqui +BEGIN { $number_of_tests += 61 } +push @pages, qw( +acqui/acqui-home.pl +~acqui/addorderiso2709.pl +~acqui/addorderiso2709.pl?import_batch_id=1&basketno=1&booksellerid=1 +~acqui/addorder.pl +acqui/add_user_search.pl +~acqui/basketgroup.pl +acqui/basketgroup.pl?booksellerid=1 +acqui/basketgroup.pl?op=add&booksellerid=1 +acqui/basketgroup.pl?op=add&booksellerid=1&basketgroupid=1 +acqui/basketheader.pl +acqui/basketheader.pl?booksellerid=1&op=add_form +~acqui/basket.pl +acqui/basket.pl?basketno=1 +acqui/basket.pl?op=edi_confirm&basketno=1 +acqui/basket.pl?op=close&basketno=1&booksellerid=1 +acqui/basket.pl?op=reopen&basketno=1 +acqui/booksellers.pl +acqui/booksellers.pl?booksellerid=1 +acqui/booksellers.pl?booksellerid=1&allbaskets=1 +acqui/cancelorder.pl +~acqui/cancelorder.pl?ordernumber=1&biblionumber=1&basketno=1 +acqui/edi_ean.pl +acqui/edifactmsgs.pl +acqui/edimsg.pl +~acqui/finishreceive.pl +acqui/histsearch.pl +acqui/invoice-files.pl +~acqui/invoice.pl +~acqui/invoice.pl?invoiceid=1__need_to_create_invoice +~acqui/invoice.pl?op=reopen&invoiceid=1__need_to_create_invoice +acqui/invoices.pl +~acqui/invoices.pl?op=do_search&invoicenumber=1__need_to_create_invoice +acqui/lateorders-export.pl +acqui/lateorders.pl +~acqui/modordernotes.pl +~acqui/modordernotes.pl?ordernumber=1__need_to_create_order +~acqui/modordernotes.pl?ordernumber=1&type=internal +~acqui/modordernotes.pl?ordernumber=1&type=vendor +~acqui/neworderbiblio.pl +~acqui/neworderempty.pl +acqui/neworderempty.pl?booksellerid=1&basketno=1&biblionumber=1 +~acqui/newordersubscription.pl +acqui/newordersubscription.pl?booksellerid=1&basketno=1 +~acqui/newordersuggestion.pl +acqui/newordersuggestion.pl?booksellerid=1&basketno=1 +acqui/ordered.pl +acqui/orderreceive.pl +acqui/parcel.pl +acqui/parcel.pl?invoiceid=1 +~acqui/parcels.pl +acqui/parcels.pl?booksellerid=1 +acqui/spent.pl +~acqui/supplier.pl +acqui/supplier.pl?booksellerid=1 +acqui/transferorder.pl +~acqui/uncertainprice.pl +acqui/uncertainprice.pl?booksellerid=1 +acqui/uncertainprice.pl?booksellerid=1&owner=1 +acqui/updatesupplier.pl +~acqui/z3950_search.pl +acqui/z3950_search.pl?booksellerid=1&basketno=1 +); + +# acqui +BEGIN { $number_of_tests += 12 } +push @pages, qw( +authorities/auth_finder.pl +authorities/auth_finder.pl?authtypecode=PERSO_NAME +authorities/authorities-home.pl +authorities/authorities-list.pl +authorities/authorities.pl +authorities/blinddetail-biblio-search.pl +~authorities/detail-biblio-search.pl +authorities/detail.pl +authorities/detail.pl?authid=1 +authorities/export.pl +~authorities/merge_ajax.pl__no_title_but_ok +authorities/merge.pl +~authorities/ysearch.pl__no_title_but_ok +); + +# basket +BEGIN { $number_of_tests += 7 } +push @pages, qw( +basket/basket.pl +basket/downloadcart.pl +basket/downloadcart.pl?format=iso2709&bib_list=1 +basket/downloadcart.pl?format=ris&bib_list=1 +basket/downloadcart.pl?format=bibtex&bib_list=1 +basket/downloadcart.pl?format=1&bib_list=1 +basket/sendbasket.pl +); + +# catalogue +BEGIN { $number_of_tests += 25 } +push @pages, qw( +catalogue/detail.pl +catalogue/detail.pl?biblionumber=1 +catalogue/export.pl +~catalogue/getitem-ajax.pl__no_title_but_ok +~catalogue/getitem-ajax.pl?itemnumber=1__no_title_but_ok +catalogue/image.pl?imagenumber=1 +catalogue/image.pl?imagenumber=1&thumbnail=1 +catalogue/imageviewer.pl +catalogue/imageviewer.pl?biblionumber=1&imagenumber=1 +catalogue/ISBDdetail.pl +catalogue/ISBDdetail.pl?biblionumber=1 +~catalogue/issuehistory.pl +catalogue/issuehistory.pl?biblionumber=1 +catalogue/itemsearch.pl +catalogue/labeledMARCdetail.pl +catalogue/labeledMARCdetail.pl?biblionumber=1 +catalogue/MARCdetail.pl +catalogue/MARCdetail.pl?biblionumber=1 +~catalogue/moredetail.pl +catalogue/moredetail.pl?biblionumber=1 +catalogue/moredetail.pl?biblionumber=1&itemnumber=1 +catalogue/search-history.pl +catalogue/search.pl +catalogue/search.pl?type=intranet&op=do_search&q=an=1 +catalogue/search.pl?q=d +catalogue/showmarc.pl +catalogue/showmarc.pl?id=1 +catalogue/showmarc.pl?id=1&viewas=html +catalogue/showmarc.pl?id=1&viewas=card +~catalogue/updateitem.pl +); + +# cataloguing +BEGIN { $number_of_tests += 17 } +push @pages, qw( +cataloguing/addbiblio.pl +cataloguing/addbiblio.pl?biblionumber=1 +cataloguing/addbiblio.pl?frameworkcode=FA +cataloguing/addbiblio.pl?mode=popup +cataloguing/addbooks.pl +~cataloguing/additem.pl +cataloguing/additem.pl?biblionumber=1 +cataloguing/additem.pl?op=edititem&biblionumber=1&itemnumber=1 +cataloguing/editor.pl +~cataloguing/linkitem.pl +~cataloguing/merge_ajax.pl__no_title_but_ok +cataloguing/merge.pl +cataloguing/merge.pl?biblionumber=1&biblionumber=2 +cataloguing/moveitem.pl?biblionumber=1 +cataloguing/plugin_launcher.pl +cataloguing/plugin_launcher.pl?plugin_name=marc21_linking_section.pl +~cataloguing/ysearch.pl__this_die +~cataloguing/ysearch.pl?table=biblioitems&field=publishercode__no_title_but_ok +cataloguing/z3950_auth_search.pl +cataloguing/z3950_auth_search.pl?authid=1 +cataloguing/z3950_search.pl +cataloguing/z3950_search.pl?biblionumber=1 +); + +# circ +BEGIN { $number_of_tests += 27 } +push @pages, qw( +circ/add_message.pl +~circ/article-request-slip.pl +~circ/article-request-slip.pl?id=1__need_to_create_AR +circ/article-requests.pl +circ/bookcount.pl +circ/bookcount.pl?biblionumber=1&bi=1&itm=1 +circ/branchoverdues.pl +circ/branchtransfers.pl +circ/circulation-home.pl +circ/circulation.pl +circ/circulation.pl?borrowernumber=1 +circ/circulation.pl?findborrower=42 +circ/del_message.pl +circ/del_message.pl??message_id=1&borrowernumber=1 +~circ/hold-transfer-slip.pl__timeout +circ/offline.pl +circ/on-site_checkouts.pl +circ/overdue.pl +circ/pendingreserves.pl +circ/renew.pl +circ/request-article.pl +circ/request-article.pl?biblionumber=1 +circ/reserveratios.pl +circ/returns.pl +circ/returns.pl?itemnumber=1 +circ/returns.pl?itemnumber=1&canceltransfer=1 +circ/selectbranchprinter.pl +~circ/transfer-slip.pl__timeout +circ/transferstoreceive.pl +circ/view_holdsqueue.pl +circ/waitingreserves.pl +~circ/ypattrodue-attr-search-authvalue.pl__no_title_but_ok +~circ/ysearch.pl__no_title_but_ok +); + +# clubs +BEGIN { $number_of_tests += 4 } +push @pages, qw( +clubs/club-enrollments.pl +clubs/club-enrollments.pl?id=1 +~clubs/clubs-add-modify.pl +clubs/clubs-add-modify.pl?club_template_id=1 +clubs/clubs.pl +~clubs/patron-clubs-tab.pl +~clubs/patron-clubs-tab.pl?borrowernumber=1 +~clubs/patron-clubs-tab.pl?borrowernumber=1&id=1 +~clubs/patron-enroll.pl +~clubs/patron-enroll.pl??borrowernumber=1&id=1 +~clubs/templates-add-modify.pl&id=1 +); + +# course_reserves +BEGIN { $number_of_tests += 10 } +push @pages, qw( +course_reserves/add_items.pl +course_reserves/add_items.pl?course_id=1 +course_reserves/course-details.pl +course_reserves/course-details.pl?course_id=1 +course_reserves/course.pl +course_reserves/course.pl?course_id=1 +course_reserves/course-reserves.pl +course_reserves/mod_course.pl +course_reserves/mod_course.pl?course_id=1 +course_reserves/mod_course.pl?course_id=1&action=del +); + +# ill TODO +BEGIN { $number_of_tests += 0 } +push @pages, qw( +); + +# installer TODO +BEGIN { $number_of_tests += 0 } +push @pages, qw( +); + +# labels TODO +BEGIN { $number_of_tests += 0 } +push @pages, qw( +); + +# members +BEGIN { $number_of_tests += 57 } +push @pages, qw( +members/boraccount.pl +members/boraccount.pl?borrowernumber=1 +~members/default_messageprefs.pl__no_title_but_ok +~members/default_messageprefs.pl?categorycode=CAT__no_title_but_ok +members/deletemem.pl +members/deletemem.pl?member=1 +members/discharge.pl +members/discharge.pl?borrowernumber=1 +members/discharges.pl +members/discharges.pl?op=allow&borrowernumber=1 +members/files.pl +members/files.pl?borrowernumber=1 +members/guarantor_search.pl +members/holdshistory.pl +members/holdshistory.pl?borrowernumber=1 +~members/housebound.pl +members/housebound.pl?borrowernumber=1 +members/mancredit.pl +members/mancredit.pl?borrowernumber=1 +members/maninvoice.pl +members/maninvoice.pl?borrowernumber=1 +members/memberentry.pl +members/memberentry.pl?op=modify&destination=circ&borrowernumber=1 +members/member-flags.pl +members/member-flags.pl?member=1 +members/member-password.pl +members/member-password.pl?member=1 +members/member.pl +members/members-home.pl +members/members-update-do.pl +members/members-update.pl +members/mod_debarment.pl +members/mod_debarment.pl?borrowernumber=1&borrower_debarment_id=1&action=del +members/moremember.pl +members/moremember.pl?borrowernumber=1 +members/nl-search.pl +members/notices.pl +members/notices.pl?borrowernumber=1 +members/patronimage.pl +members/patronimage.pl?borrowernumber=1 +members/paycollect.pl +members/paycollect.pl?borrowernumber=1 +members/pay.pl +members/pay.pl?borrowernumber=1 +members/printfeercpt.pl +~members/printfeercpt.pl?action=print&accountlines_id=1&borrowernumber=1__timeout +members/printinvoice.pl +~members/printinvoice.pl?action=print&accountlines_id=1&borrowernumber=1__timeout +~members/print_overdues.pl__timeout__but_should_not +~members/print_overdues.pl?borrowernumber=1__timeout +~members/printslip.pl +members/purchase-suggestions.pl +members/purchase-suggestions.pl?borrowernumber=1 +members/readingrec.pl +members/readingrec.pl?borrowernumber=1 +members/readingrec.pl?borrowernumber=1&op=export_barcodes +members/routing-lists.pl +members/routing-lists.pl?borrowernumber=1 +members/setstatus.pl +members/setstatus.pl?borrowernumber=1&destination=circ&reregistration=y +members/statistics.pl +members/statistics.pl?borrowernumber=1 +members/summary-print.pl +members/update-child.pl +); + +# opac TODO +BEGIN { $number_of_tests += 0 } +push @pages, qw( +); + +# patroncards TODO +BEGIN { $number_of_tests += 0 } +push @pages, qw( +); + +# patron_lists TODO +BEGIN { $number_of_tests += 0 } +push @pages, qw( +); + +# plugins TODO +BEGIN { $number_of_tests += 0 } +push @pages, qw( +); + +# reports TODO +BEGIN { $number_of_tests += 0 } +push @pages, qw( +); + +# reserves TODO +BEGIN { $number_of_tests += 0 } +push @pages, qw( +); + +# reviews TODO +BEGIN { $number_of_tests += 0 } +push @pages, qw( +); + +# serials TODO +BEGIN { $number_of_tests += 0 } +push @pages, qw( +); + +# services TODO +BEGIN { $number_of_tests += 0 } +push @pages, qw( +); + +# suggestions TODO +BEGIN { $number_of_tests += 0 } +push @pages, qw( +); + +# svc TODO +BEGIN { $number_of_tests += 0 } +push @pages, qw( +); + +# tags TODO +BEGIN { $number_of_tests += 0 } +push @pages, qw( +); + +# tools TODO +BEGIN { $number_of_tests += 0 } +push @pages, qw( +); + +# virtualshelves TODO +BEGIN { $number_of_tests += 0 } +push @pages, qw( +); + + +SKIP: { + eval { require Selenium::Remote::Driver; }; + skip "Selenium::Remote::Driver is needed for selenium tests.", $number_of_tests if $@; + + my $driver = Selenium::Remote::Driver->new( + port => $selenium_port, + remote_server_addr => $selenium_addr, + ); + + BEGIN { $number_of_tests += 1 } + $driver->get($base_url."mainpage.pl"); + like( $driver->get_title(), qr(Log in to Koha), ); + auth( $driver, $login, $password ); + + for my $page ( @pages ) { + next if $page =~ m|^~|; + $driver->get("$base_url/$page"); + my $title = $driver->get_title; + ok( $title, "$page should have a title (maybe a 500 is raised)" ); + } + + $driver->quit(); +}; + +sub auth { + my ( $driver, $login, $password) = @_; + fill_form( $driver, { userid => $login, password => $password } ); + my $login_button = $driver->find_element('//input[@id="submit"]'); + $login_button->submit(); +} + +sub fill_form { + my ( $driver, $values ) = @_; + while ( my ( $id, $value ) = each %$values ) { + my $element = $driver->find_element('//*[@id="'.$id.'"]'); + my $tag = $element->get_tag_name(); + if ( $tag eq 'input' ) { + $driver->find_element('//input[@id="'.$id.'"]')->send_keys($value); + } elsif ( $tag eq 'select' ) { + $driver->find_element('//select[@id="'.$id.'"]/option[@value="'.$value.'"]')->click; + } + } +} -- 2.11.0