From a922c8cc968f41f0cbf5f577adef16312474223a Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 17 Nov 2022 14:32:49 +0100 Subject: [PATCH] Bug 32242: Add selenium tests This is not testing the thing at the correct level, but at least we test the whole workflow. Signed-off-by: Tomas Cohen Arazi --- .../selenium/batch_item_modification.t | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100755 t/db_dependent/selenium/batch_item_modification.t diff --git a/t/db_dependent/selenium/batch_item_modification.t b/t/db_dependent/selenium/batch_item_modification.t new file mode 100755 index 0000000000..acb5cac3eb --- /dev/null +++ b/t/db_dependent/selenium/batch_item_modification.t @@ -0,0 +1,87 @@ +#!/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 Koha::BackgroundJobs; + +use Test::More tests => 2; + +use t::lib::Selenium; +use t::lib::TestBuilder; +use utf8; + +my $builder = t::lib::TestBuilder->new; + +my $login = $ENV{KOHA_USER} || 'koha'; + +my @cleanup; + +SKIP: { + eval { require Selenium::Remote::Driver; }; + skip "Selenium::Remote::Driver is needed for selenium tests.", 2 if $@; + + my $s = t::lib::Selenium->new; + my $driver = $s->driver; + $driver->set_window_size(3840,1080); + my $mainpage = $s->base_url . q|mainpage.pl|; + $driver->get($mainpage); + like( $driver->get_title(), qr(Log in to Koha), ); + $s->auth; + + subtest 'test encoding sent to the broker' => sub { + my $item = $builder->build_sample_item; + + # Navigate to the batch item mod tool + $s->click( + { href => '/cataloguing/cataloging-home.pl', main => 'container-main' } + ); + $s->click( + { href => 'tools/batchMod.pl', main_class => 'main container-fluid' } ); + $driver->find_element('//textarea[@id="barcodelist"]')->send_keys($item->barcode); + $s->submit_form; + my $itemnotes = q{✔ ❤ ★}; + $driver->find_element('//input[@name="items.itemnotes"]') + ->send_keys($itemnotes); + $s->submit_form; + + my $view_detail_link = $driver->find_element('//a[contains(@href, "/cgi-bin/koha/admin/background_jobs.pl?op=view&id=")]'); + my $href = $view_detail_link->get_attribute('href'); + my $job_id; + if ( $href =~ m{id=(\d+)} ) { + $job_id = $1; + } + my $job = Koha::BackgroundJobs->find($job_id); + my $i; + while ( $job->discard_changes->status ne 'finished' ) { + sleep(1); + last if ++$i > 10; + } + is ( $job->status, 'finished', 'job is finished' ); + + is( Koha::Items->find($item->itemnumber)->itemnotes, $itemnotes ); + + push @cleanup, $item, $item->biblio; + }; + + $driver->quit(); +} + +END { + $_->delete for @cleanup; +}; -- 2.39.5