Bug 21775: [18.05.x] Add selenium tests for audio alerts
[koha.git] / t / db_dependent / selenium / regressions.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
22 use Test::More tests => 2;
23
24 use t::lib::Selenium;
25 use t::lib::TestBuilder;
26
27 eval { require Selenium::Remote::Driver; };
28 skip "Selenium::Remote::Driver is needed for selenium tests.", 1 if $@;
29
30 my $s = t::lib::Selenium->new;
31
32 my $driver = $s->driver;
33 my $opac_base_url = $s->opac_base_url;
34 my $base_url = $s->base_url;
35
36 # It seems that we do not have enough records indexed with ES
37 my $SearchEngine_value = C4::Context->preference('SearchEngine');
38 C4::Context->set_preference('SearchEngine', 'Zebra');
39
40 my $AudioAlerts_value = C4::Context->preference('AudioAlerts');
41 C4::Context->set_preference('AudioAlerts', '1');
42
43 my @data_to_cleanup;
44
45 subtest 'OPAC - Remove from cart' => sub {
46     plan tests => 4;
47
48     $driver->get( $opac_base_url . "opac-search.pl?q=d" );
49
50     # A better way to do that would be to modify the way we display the basket count
51     # We should show/hide the count instead or recreate the node
52     my @basket_count_elts = $driver->find_elements('//span[@id="basketcount"]/span');
53     is( scalar(@basket_count_elts), 0, 'Basket should be empty');
54
55     # This will fail if nothing is indexed, but at this point we should have everything setup correctly
56     my @checkboxes = $driver->find_elements('//input[@type="checkbox"][@name="biblionumber"]');
57     my $biblionumber1 = $checkboxes[0]->get_value();
58     my $biblionumber3 = $checkboxes[2]->get_value();
59     my $biblionumber5 = $checkboxes[4]->get_value();
60
61     $driver->find_element('//a[@class="addtocart cart'.$biblionumber1.'"]')->click;
62     my $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
63     is( $basket_count_elt->get_text(),
64         1, 'One element should have been added to the cart' );
65
66     $driver->find_element('//a[@class="addtocart cart'.$biblionumber3.'"]')->click;
67     $driver->find_element('//a[@class="addtocart cart'.$biblionumber5.'"]')->click;
68     $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
69     is( $basket_count_elt->get_text(),
70         3, '3 elements should have been added to the cart' );
71
72     $driver->find_element('//a[@class="cartRemove cartR'.$biblionumber3.'"]')->click;
73     $basket_count_elt = $driver->find_element('//span[@id="basketcount"]/span');
74     is( $basket_count_elt->get_text(),
75         2, '1 element should have been removed from the cart' );
76 };
77
78 subtest 'Play sound on the circulation page' => sub {
79     plan tests => 1;
80
81     my $builder  = t::lib::TestBuilder->new;
82     my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { flags => 0 }});
83
84     my $mainpage = $s->base_url . q|mainpage.pl|;
85     $driver->get($mainpage);
86     like( $driver->get_title(), qr(Log in to Koha), );
87     $s->auth;
88
89     $driver->get( $base_url . "/circ/circulation.pl?borrowernumber=" . $patron->borrowernumber );
90
91     my $audio_node = $driver->find_element('//span[@id="audio-alert"]/audio[@src="/intranet-tmpl/prog/sound/beep.ogg"]');
92
93     push @data_to_cleanup, $patron, $patron->category, $patron->library;
94 };
95
96 END {
97     C4::Context->preference('SearchEngine', $SearchEngine_value);
98     C4::Context->preference('AudioAlerts', $AudioAlerts_value);
99     $_->delete for @data_to_cleanup;
100 };