Einkaufsrechnungen: Lieferanten richtig escapen.
[kivitendo-erp.git] / t / selenium / AllTests.t
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2006/2007
4 # Web http://www.lx-office.org
5 #
6 #=====================================================================
7 #
8 #  Author: Udo Spallek, Thomas Kasulke
9 #   Email: udono@gmx.net, tkasulke@linet-services.de
10 #
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
15 #
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write to the Free Software
22 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #======================================================================
24
25 # Selenium Main Caller
26 # Call all Selenium scripts from here. To use Selenium tests in 
27 # Lx-Office you need to Install Selenium Remote Control. Take a look at 
28 # the README Document for further informatinons on installing Selenium 
29 # and testing Lx-Office and of course writing your own testcases.
30 #
31 #######################################################################
32   no strict;
33   push @INC, ['/t/selenium', \&init_server];
34   use vars qw( $lxdebug $lxtest $sel );
35   use strict;
36   use Carp;
37
38   use Test::WWW::Selenium;
39   use Test::More qw(no_plan);
40   use IO::Socket;
41
42   if(-f "/tmp/lxtest-temp.conf") {
43     eval { require('/tmp/lxtest-temp.conf'); };
44   }
45   else {
46     eval { require('t/lxtest.conf'); };
47   }
48   if ($@) {
49     diag("No test configuration found in t/lxtest.conf.\n
50     Maybe you forget to copy t/lxtest.conf.default to t/lxtest.conf. Exit test...\n");
51   exit 0;
52   }
53
54   sub server_is_running {
55     return IO::Socket::INET->new(PeerAddr => $ENV{SRC_HOST} || $lxtest->{seleniumhost},
56                                  PeerPort => $ENV{SRC_PORT} || $lxtest->{seleniumport},
57                                 );
58   }
59   
60 #   if (server_is_running) {
61 #     plan tests => 200; # Need to be cutomized
62 #   }
63   sub init_server {
64     my $singlefileonly = 0;
65     if ($_[0] eq "singlefileonly") {  
66       $singlefileonly = 1;
67       shift;
68     }
69     if(!server_is_running) {
70       print "No selenium server found! "
71            ."Maybe you forgot to start it or "
72            ."the preferences in t/lxtest.conf doesen't fit to your system";
73       exit 0;
74     }
75
76     diag('Pretests and initialisation');
77
78
79
80     $lxtest->{test_id} = time; # create individual ids by unixtime
81     $lxtest->{testuserlogin}   = $lxtest->{testlogin} . $lxtest->{test_id} if(!$lxtest->{testuserlogin});
82     $lxtest->{testuserpasswd}  = $lxtest->{test_id} if(!$lxtest->{testuserpasswd});
83     $lxtest->{db}              = $lxtest->{db} . $lxtest->{test_id} if(!($lxtest->{db} =~ /^seleniumtestdatabase[0-9]{10}$/));
84
85     ok(defined $lxtest->{rpw}, "Get root password");
86   
87     ok(defined $lxtest->{dbhost}, "found dbhost in config");
88     ok(defined $lxtest->{dbport}, "found dbport in config");
89     ok(defined $lxtest->{dbuser}, "found dbuser in config");
90     ok(defined $lxtest->{dbpasswd}, "found dbpasswd in config");
91
92     $lxtest->{lxadmin_url} = $lxtest->{lxbaseurl} . "admin.pl";
93     $lxtest->{lxadmin_with_get} = $lxtest->{lxadmin_url} . "?rpw=$lxtest->{rpw}&nextsub=list_users&action=Weiter";
94     $lxtest->{lxadmin} = $lxtest->{lxadmin_url} . "?rpw=$lxtest->{rpw}&nextsub=list_users&action=Weiter";
95
96
97
98
99     eval { $sel = Test::WWW::Selenium->new(
100       host => $lxtest->{seleniumhost},
101       port => $lxtest->{seleniumport},
102       browser => $lxtest->{seleniumbrowser},
103       browser_url => $lxtest->{lxadmin},
104       auto_stop => '0',
105       );
106     };
107     if ($@) {
108       diag("No Selenium Server running, or wrong preferences\n\n");
109       exit 0;
110     }
111     
112     ok(defined $sel, 'Creating Selenium Object');
113
114     diag('Starting Selenium tests...');
115     
116     if(!$singlefileonly) {
117       foreach my $scriptdir (@_) {
118         opendir(SCRIPTS, 't/selenium/testscripts/' . $scriptdir) or die "Can't open directory!" . $!;
119         foreach (sort readdir(SCRIPTS)) {
120           if ( $_ =~ /^\w\d\d\d.*\.t$|^\d\d\d.*\.t$/  && !$sel->{ran_tests}{"t/selenium/testscripts/". $scriptdir . "/" . $_}) {
121             require_ok("t/selenium/testscripts/". $scriptdir . "/" . $_);
122             $sel->{ran_tests}{"t/selenium/testscripts/". $scriptdir . "/" . $_} = 1;
123           }
124         }
125         closedir(SCRIPTS);
126       }
127     }
128     else {
129       foreach (@_) { 
130         if ( $_ =~ /^.*\/\w\d\d\d.*\.t$|^.*\/\d\d\d.*\.t$/  && !$sel->{ran_tests}{$_}) {
131           require_ok($_); 
132           $sel->{ran_tests}{$_} = 1;
133         }
134       }
135     }
136     if($!) {
137       @! = ("Test fehlgeschlagen!");
138     }
139     $sel->stop();
140   }
141   
142   sub start_login() {
143     require "t/selenium/testscripts/base/000Login.t" if(!$sel->{_page_opened});
144     skip("Failed page to load pages!",) if(!$sel->{_page_opened});
145
146     if($sel->get_title() ne "Lx-Office Version 2.4.3 - Selenium - " . $lxtest->{db}){
147       require "t/selenium/testscripts/base/000Login.t";
148     }
149
150     $sel->select_frame_ok("relative=up");
151   }
152   
153 1;