View | Details | Raw Unified | Return to bug 19243
Collapse All | Expand All

(-)a/t/db_dependent/selenium/administration_tasks.t (+141 lines)
Line 0 Link Here
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
#This selenium test tests the Koha Administration module functionality including adding circ rules, item types and modifying frameworks
19
20
#Note: If you are testing this on kohadevbox with selenium installed in kohadevbox then you need to set the staffClientBaseURL to localhost:8080 and the OPACBaseURL to http://localhost:80
21
22
use Modern::Perl;
23
24
use C4::Context;
25
26
use Test::More tests => 1;
27
28
use t::lib::Selenium;
29
30
my $login = $ENV{KOHA_USER} || 'koha';
31
32
my $itemtype      = 'UT_DVD';
33
my $frameworkcode = 'UTFW';     # frameworkcode is only 4 characters max!
34
my $branchcode    = 'UT_BC';
35
our ($cleanup_needed);
36
37
SKIP: {
38
    eval { require Selenium::Remote::Driver; };
39
    skip "Selenium::Remote::Driver is needed for selenium tests.", 1 if $@;
40
41
    $cleanup_needed = 1;
42
43
    my $s        = t::lib::Selenium->new;
44
    my $driver   = $s->driver;
45
    my $mainpage = $s->base_url . q|mainpage.pl|;
46
    $driver->get($mainpage);
47
    like( $driver->get_title(), qr(Log in to Koha), );
48
    $s->auth;
49
50
    { # Item types
51
        # Navigate to the Administration area and create an item type
52
        $s->click( { href => '/admin/admin-home.pl', main => 'doc3' } )
53
          ;    # Koha administration
54
        $s->click( { href => '/admin/itemtypes.pl', main => 'doc' } );  # Item Types
55
        $s->click( { href => '/admin/itemtypes.pl?op=add_form', main => 'doc3' } )
56
          ;    # New item type
57
        $s->fill_form(
58
            { itemtype => $itemtype, description => "Digital Optical Disc" } );
59
        $s->submit_form;
60
        $s->click(
61
            {
62
                href => '/admin/itemtypes.pl?op=add_form&itemtype=' . $itemtype,
63
                main => 'doc3'
64
            }
65
        );     # New item type
66
    };
67
68
    { # Circulation/fine rules
69
        $driver->get($mainpage);
70
        $s->click( { href => '/admin/admin-home.pl', main => 'doc3' } )
71
          ;    # Koha administration
72
        $s->click( { href => '/admin/smart-rules.pl', main => 'doc' } )
73
          ;    # Circulation and fines rules
74
               # TODO Create smart navigation here
75
    };
76
77
    { # Biblio frameworks
78
        $driver->get($mainpage);
79
        $s->click( { href => '/admin/admin-home.pl', main => 'doc3' } )
80
          ;    # Koha administration
81
        $s->click( { href => '/admin/biblio_framework.pl', main => 'doc' } )
82
          ;    # MARC bibliographic framework
83
        $s->click(
84
            { href => '/admin/biblio_framework.pl?op=add_form', main => 'doc3' } )
85
          ;    # New framework
86
        $s->fill_form(
87
            {
88
                frameworkcode => $frameworkcode,
89
                description   => 'just a description'
90
            }
91
        );
92
        $s->submit_form;
93
        $s->click( { id => 'frameworkactions' . $frameworkcode } );
94
        $s->click(
95
            {
96
                href => 'marctagstructure.pl?frameworkcode=' . $frameworkcode,
97
                main => 'doc3'
98
            }
99
        );    # MARC structure # FIXME '/admin/' is missing in the url
100
              # TODO Click on OK to create the MARC structure
101
    };
102
103
    { #Libraries
104
        $driver->get($mainpage);
105
        $s->click( { href => '/admin/admin-home.pl', main => 'doc3' } )
106
          ;    # Koha administration
107
        $s->click( { href => '/admin/branches.pl', main => 'doc' } )
108
          ;    # Libraries and groups
109
        $s->click( { href => '/admin/branches.pl?op=add_form', main => 'doc3' } )
110
          ;    # New library
111
        $s->fill_form( { branchcode => $branchcode, branchname => 'my library' } );
112
        $s->submit_form;
113
        $s->click(
114
            {
115
                href => '/admin/branches.pl?op=add_form&branchcode=' . $branchcode,
116
                main => 'doc3'
117
            }
118
        );     # Edit
119
        $s->fill_form( { branchname => 'another branchname' } );
120
        $s->submit_form;
121
        $s->click(
122
            {
123
                href => '/admin/branches.pl?op=delete_confirm&branchcode='. $branchcode,
124
                main => 'doc3'
125
            }
126
        );     # Delete
127
    };
128
129
    $driver->quit();
130
}
131
132
END {
133
    cleanup() if $cleanup_needed;
134
};
135
136
sub cleanup {
137
    my $dbh = C4::Context->dbh;
138
    $dbh->do(q|DELETE FROM itemtypes WHERE itemtype=?|, undef, $itemtype);
139
    $dbh->do(q|DELETE FROM biblio_framework WHERE frameworkcode=?|, undef, $frameworkcode);
140
    $dbh->do(q|DELETE FROM branches WHERE branchcode=?|, undef, $branchcode);
141
}
(-)a/t/lib/Selenium.pm (-2 / +62 lines)
Lines 74-79 sub fill_form { Link Here
74
    }
74
    }
75
}
75
}
76
76
77
sub submit_form {
78
    my ( $self ) = @_;
79
80
    my $default_submit_selector = '//fieldset[@class="action"]/input[@type="submit"]';
81
    $self->click_when_visible( $default_submit_selector );
82
}
83
84
sub click {
85
    my ( $self, $params ) = @_;
86
    my $xpath_selector;
87
    if ( exists $params->{main} ) {
88
        $xpath_selector = '//div[@id="'.$params->{main}.'"]';
89
    }
90
    if ( exists $params->{href} ) {
91
        $xpath_selector .= '//a[contains(@href, "'.$params->{href}.'")]';
92
    }
93
    if ( exists $params->{id} ) {
94
        $xpath_selector .= '//*[@id="'.$params->{id}.'"]';
95
    }
96
    $self->click_when_visible( $xpath_selector );
97
}
98
99
sub click_when_visible {
100
    my ( $self, $xpath_selector ) = @_;
101
    $self->driver->set_implicit_wait_timeout(20000);
102
    my ($visible, $elt);
103
    while ( not $visible ) {
104
        $elt = $self->driver->find_element($xpath_selector);
105
        $visible = $elt->is_displayed;
106
        $self->driver->pause(1000) unless $visible;
107
    }
108
    $elt->click;
109
}
110
77
=head1 NAME
111
=head1 NAME
78
112
79
t::lib::Selenium - Selenium helper module
113
t::lib::Selenium - Selenium helper module
Lines 121-130 when we use automation test using Selenium Link Here
121
    The keys must be element ids (input and select are supported so far)
155
    The keys must be element ids (input and select are supported so far)
122
    The values must a string.
156
    The values must a string.
123
157
124
=head1 AUTHOR
158
=head2 submit_form
159
160
    $s->submit_form;
161
162
    It will submit the form using the submit button present in in the fieldset with a clas="action".
163
    It should be the default way. If it does not work you should certainly fix the Koha interface.
164
165
=head2 click
166
167
    $s->click
168
169
    This is a bit dirty for now but will evolve depending on the needs
170
    3 parameters possible but only the following 2 forms are used:
171
    $s->click({ href => '/module/script.pl?foo=bar', main => 'doc3' }); # Sometimes we have doc or doc3. To make sure we are not going to hit a link in the header
172
    $s->click({ id => 'element_id });
173
174
=head2 click_when_visible
175
176
    $c->click_when_visible
177
178
    Should always be called to avoid the "An element could not be located on the page" error
179
180
=head2
181
182
183
=head1 AUTHORS
125
184
126
Jonathan Druart <jonathan.druart@bugs.koha-community.org>
185
Jonathan Druart <jonathan.druart@bugs.koha-community.org>
127
186
187
Alex Buckley <alexbuckley@catalyst.net.nz>
188
128
Koha Development Team
189
Koha Development Team
129
190
130
=head1 COPYRIGHT
191
=head1 COPYRIGHT
131
- 

Return to bug 19243