1 # This file is part of Koha.
3 # Koha is free software; you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # Koha is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use t::lib::TestBuilder;
25 eval { require Selenium::Remote::Driver; };
27 plan skip_all => "Selenium::Remote::Driver is needed for Selenium tests.";
34 my $builder = t::lib::TestBuilder->new;
36 my $s = t::lib::Selenium->new;
37 my $driver = $s->driver;
38 my $base_url = $s->base_url;
40 # Adjust the height and width of the generated screenshots
41 #$driver->set_window_size( 2160, 991 ); # Height, then Width
43 my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 1, branchcode => 'CPL' } } );
44 my $password = Koha::AuthUtils::generate_password( $patron->category );
45 t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 );
46 $patron->set_password( { password => $password } );
48 push @cleanup, $patron;
50 $s->auth( $patron->userid, $password );
52 subtest 'Perform a system preferences search for "log", and try to expand/collapse both "Policy" sections that appear' => sub {
56 $driver->get( $base_url . 'admin/preferences.pl?tab=&op=search&searchfield=log' );
57 #$driver->capture_screenshot( 'Selenium_00.png' );
59 my $xpath_v1_expr1 = '//h3[@id="accounting_Policy"]';
61 # The first "Policy" section should be under the "Accounting" preferences top-level section and be initially expanded
62 my $first_policy_section_toggle_elt = $driver->find_element( $xpath_v1_expr1 );
63 is( $first_policy_section_toggle_elt->get_attribute( 'class' , 1 ), 'expanded', 'The first "Policy" section (under "Accounting") is currently expanded' );
65 # Clicking on the expand/collapse button should collapse this section
66 $first_policy_section_toggle_elt->click;
67 #$driver->capture_screenshot( 'Selenium_01.png' );
68 is( $first_policy_section_toggle_elt->get_attribute( 'class' , 1 ), 'collapsed', 'The first "Policy" section (under "Accounting") is now collapsed' );
70 # Clicking on the expand/collapse button once more should expand this section back to its original state
71 $first_policy_section_toggle_elt->click;
72 #$driver->capture_screenshot( 'Selenium_02.png' );
73 is( $first_policy_section_toggle_elt->get_attribute( 'class' , 1 ), 'expanded', 'The first "Policy" section (under "Accounting") is back to the expanded state' );
75 my $xpath_v1_expr2 = '//h3[@id="acquisitions_Policy"]';
77 # The second "Policy" section should be under the "Acquisitions" preferences top-level section and be initially expanded
78 my $second_policy_section_toggle_elt = $driver->find_element( $xpath_v1_expr2 );
79 is( $second_policy_section_toggle_elt->get_attribute( 'class' , 1 ), 'expanded', 'The second "Policy" section (under "Acquisitions") is currently expanded' );
81 # Clicking on the expand/collapse button should collapse this section
82 $second_policy_section_toggle_elt->click;
83 #$driver->capture_screenshot( 'Selenium_03.png' );
84 is( $second_policy_section_toggle_elt->get_attribute( 'class' , 1 ), 'collapsed', 'The second "Policy" section (under "Acquisitions") is now collapsed' );
86 # Clicking on the expand/collapse button once more should expand this section back to its original state
87 $second_policy_section_toggle_elt->click;
88 #$driver->capture_screenshot( 'Selenium_04.png' );
89 is( $second_policy_section_toggle_elt->get_attribute( 'class' , 1 ), 'expanded', 'The second "Policy" section (under "Acquisitions") is back to the expanded state' );
93 # Delete the test patron
95 $_->delete for @cleanup;