1 package t::lib::Selenium;
3 # This file is part of Koha.
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.
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.
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>.
22 use base qw(Class::Accessor);
23 __PACKAGE__->mk_accessors(qw(login password base_url selenium_addr selenium_port driver));
26 my ( $class, $params ) = @_;
28 my $config = $class->config;
29 $self->{login} = $params->{login} || $config->{login};
30 $self->{password} = $params->{password} || $config->{password};
31 $self->{base_url} = $params->{base_url} || $config->{base_url};
32 $self->{selenium_addr} = $params->{selenium_addr} || $config->{selenium_addr};
33 $self->{selenium_port} = $params->{selenium_port} || $config->{selenium_port};
34 $self->{driver} = Selenium::Remote::Driver->new(
35 port => $self->{selenium_port},
36 remote_server_addr => $self->{selenium_addr},
38 return bless $self, $class;
43 login => $ENV{KOHA_USER} || 'koha',
44 password => $ENV{KOHA_PASS} || 'koha',
45 base_url => ( $ENV{KOHA_INTRANET_URL} || C4::Context->preference("staffClientBaseURL") ) . "/cgi-bin/koha/",
46 selenium_addr => $ENV{SELENIUM_ADDR} || 'localhost',
47 selenium_port => $ENV{SELENIUM_PORT} || 4444,
52 my ( $self, $login, $password ) = @_;
54 $login ||= $self->login;
55 $password ||= $self->password;
56 my $mainpage = $self->base_url . 'mainpage.pl';
58 $self->driver->get($mainpage);
59 $self->fill_form( { userid => $login, password => $password } );
60 my $login_button = $self->driver->find_element('//input[@id="submit"]');
61 $login_button->submit();
65 my ( $self, $values ) = @_;
66 while ( my ( $id, $value ) = each %$values ) {
67 my $element = $self->driver->find_element('//*[@id="'.$id.'"]');
68 my $tag = $element->get_tag_name();
69 if ( $tag eq 'input' ) {
70 $self->driver->find_element('//input[@id="'.$id.'"]')->send_keys($value);
71 } elsif ( $tag eq 'select' ) {
72 $self->driver->find_element('//select[@id="'.$id.'"]/option[@value="'.$value.'"]')->click;
79 t::lib::Selenium - Selenium helper module
83 my $s = t::lib::Selenium->new;
84 my $driver = $s->driver;
85 my $base_url = $s->base_url;
87 $driver->get($s->base_url . 'mainpage.pl');
88 $s->fill_form({ input_id => 'value' });
92 The goal of this module is to group the different actions we need
93 when we use automation test using Selenium
98 my $s = t::lib::Selenium->new;
100 Constructor - Returns the object Selenium
101 You can pass login, password, base_url, selenium_addr, selenium_port
102 If not passed, the environment variables will be used
103 KOHA_USER, KOHA_PASS, KOHA_INTRANET_URL, SELENIUM_ADDR SELENIUM_PORT
104 Or koha, koha, syspref staffClientBaseURL, localhost, 4444
110 Will login into Koha.
117 element_id => 'other_value',
120 Will fill the different elements of a form.
121 The keys must be element ids (input and select are supported so far)
122 The values must a string.
126 Jonathan Druart <jonathan.druart@bugs.koha-community.org>
128 Koha Development Team
132 Copyright 2017 - Koha Development Team
136 This file is part of Koha.
138 Koha is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
139 the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
141 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.
143 You should have received a copy of the GNU General Public License along with Koha; if not, see <http://www.gnu.org/licenses>.