Bug 32242: Add selenium tests
[koha.git] / t / db_dependent / selenium / batch_item_modification.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use C4::Context;
21 use Koha::BackgroundJobs;
22
23 use Test::More tests => 2;
24
25 use t::lib::Selenium;
26 use t::lib::TestBuilder;
27 use utf8;
28
29 my $builder = t::lib::TestBuilder->new;
30
31 my $login = $ENV{KOHA_USER} || 'koha';
32
33 my @cleanup;
34
35 SKIP: {
36     eval { require Selenium::Remote::Driver; };
37     skip "Selenium::Remote::Driver is needed for selenium tests.", 2 if $@;
38
39     my $s        = t::lib::Selenium->new;
40     my $driver   = $s->driver;
41     $driver->set_window_size(3840,1080);
42     my $mainpage = $s->base_url . q|mainpage.pl|;
43     $driver->get($mainpage);
44     like( $driver->get_title(), qr(Log in to Koha), );
45     $s->auth;
46
47     subtest 'test encoding sent to the broker' => sub {
48         my $item = $builder->build_sample_item;
49
50         # Navigate to the batch item mod tool
51         $s->click(
52             { href => '/cataloguing/cataloging-home.pl', main => 'container-main' }
53         );
54         $s->click(
55             { href => 'tools/batchMod.pl', main_class => 'main container-fluid' } );
56         $driver->find_element('//textarea[@id="barcodelist"]')->send_keys($item->barcode);
57         $s->submit_form;
58         my $itemnotes = q{✔ ❤ ★};
59         $driver->find_element('//input[@name="items.itemnotes"]')
60           ->send_keys($itemnotes);
61         $s->submit_form;
62
63         my $view_detail_link = $driver->find_element('//a[contains(@href, "/cgi-bin/koha/admin/background_jobs.pl?op=view&id=")]');
64         my $href = $view_detail_link->get_attribute('href');
65         my $job_id;
66         if ( $href =~ m{id=(\d+)} ) {
67             $job_id = $1;
68         }
69         my $job = Koha::BackgroundJobs->find($job_id);
70         my $i;
71         while ( $job->discard_changes->status ne 'finished' ) {
72             sleep(1);
73             last if ++$i > 10;
74         }
75         is ( $job->status, 'finished', 'job is finished' );
76
77         is( Koha::Items->find($item->itemnumber)->itemnotes, $itemnotes );
78
79         push @cleanup, $item, $item->biblio;
80     };
81
82     $driver->quit();
83 }
84
85 END {
86     $_->delete for @cleanup;
87 };