Automatisierte Syntaxtests, Framework für spätere Modultests.
[kivitendo-erp.git] / t / old / selenium / cleanup.pl
1 #=====================================================================
2 # LX-Office ERP
3 # Copyright (C) 2006
4 # Web http://www.lx-office.org
5 #
6 #=====================================================================
7 #
8 #  Author: Udo Spallek
9 #   Email: udono@gmx.net
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 Cleanup Script
26 # To clean up all the messy databases and users while debugging testcases
27
28 #######################################################################
29   no strict;
30   push @INC, ['/t/selenium'];
31   use vars qw( $lxdebug $lxtest $sel );
32   use strict;
33   use Carp;
34
35   use WWW::Selenium;
36   use IO::Socket;
37
38   my $cleanedupdb = '';
39   my $cleanedupusers = '';
40
41   eval { require('t/lxtest.conf'); };
42   if ($@) {
43     print "No test configuration found in t/lxtest.conf.\n
44     Maybe you forget to copy t/lxtest.conf.default to t/lxtest.conf. Exit test...\n";
45   exit 0;
46   };
47
48   sub server_is_running {
49     return IO::Socket::INET->new(PeerAddr => $ENV{SRC_HOST} || $lxtest->{seleniumhost},
50                                  PeerPort => $ENV{SRC_PORT} || $lxtest->{seleniumport},
51                                 );
52   }
53   if (server_is_running) {
54   }
55   else {
56     exit 0;
57   }
58
59   $lxtest->{testuserlogin}   = $lxtest->{testlogin};
60   $lxtest->{db}              = $lxtest->{db};
61
62   $lxtest->{lxadmin} = $lxtest->{lxbaseurl} . "admin.pl?rpw=$lxtest->{rpw}&nextsub=list_users&action=Weiter";
63
64   eval { $sel = WWW::Selenium->new(
65     host => $lxtest->{seleniumhost},
66     port => $lxtest->{seleniumport},
67     browser => $lxtest->{seleniumbrowser},
68     browser_url => $lxtest->{lxadmin},
69     auto_stop => '0',
70     );
71   };
72   if ($@) {
73     print "No Selenium Server running, or wrong preferences\n\n";
74     exit 0;
75   }
76
77
78   print "\nStarting Testdebugging Cleanup...\n";
79
80
81 ### Delete user
82
83 $sel->start;
84 print "Cleanup all users '$lxtest->{testuserlogin}*'\n";
85 $sel->open($lxtest->{lxadmin});
86
87 my @links= $sel->get_all_links();
88 my $testuserlogin = $lxtest->{testuserlogin};
89
90 foreach my $link (@links) {
91
92   if ($link =~ /$testuserlogin\d\d\d\d\d\d\d\d\d\d/){
93     $sel->click("link=$lxtest->{testuserlogin}11*");
94     $sel->wait_for_page_to_load($lxtest->{timeout});
95     $sel->click("//input[(\@name=\"action\") and (\@value=\"Löschen\")]");
96     $sel->wait_for_page_to_load($lxtest->{timeout});
97     $cleanedupusers .= "     $link\n";
98   }
99 }
100
101 print "Lock the system\n";
102 $sel->click("//input[(\@name=\"action\") and (\@value=\"System sperren\")]");
103 $sel->wait_for_page_to_load($lxtest->{timeout});
104
105 print "Cleanup all test databasees: '$lxtest->{db}*'\n";
106
107   $sel->click("//input[(\@name=\"action\") and (\@value=\"Datenbankadministration\")]");
108   $sel->wait_for_page_to_load($lxtest->{timeout});
109   $sel->type("dbhost", $lxtest->{dbhost});
110   $sel->type("dbport", $lxtest->{dbport});
111   $sel->type("dbuser", $lxtest->{dbuser});
112   $sel->type("dbpasswd", $lxtest->{dbpasswd});
113  
114   $sel->click("//input[(\@name=\"action\") and (\@value=\"Datenbank löschen\")]");
115   $sel->wait_for_page_to_load($lxtest->{timeoutlong});
116
117   my $field = $sel->get_body_text();
118   my $database= $lxtest->{db};
119   my @fields = split('  ', $field);
120
121   
122   foreach my $field (@fields) {
123
124     if ($field =~ /$database\d\d\d\d\d\d\d\d\d\d/){
125       $sel->open($lxtest->{lxadmin});
126       $sel->click("//input[(\@name=\"action\") and (\@value=\"Datenbankadministration\")]");
127       $sel->wait_for_page_to_load($lxtest->{timeout});
128       $sel->type("dbhost", $lxtest->{dbhost});
129       $sel->type("dbport", $lxtest->{dbport});
130       $sel->type("dbuser", $lxtest->{dbuser});
131       $sel->type("dbpasswd", $lxtest->{dbpasswd});
132      
133       $sel->click("//input[(\@name=\"action\") and (\@value=\"Datenbank löschen\")]");
134       $sel->wait_for_page_to_load($lxtest->{timeoutlong});
135       $sel->check("name=db value=$field"); 
136       $sel->click("//input[(\@name=\"action\") and (\@value=\"Weiter\")]");
137       $cleanedupdb .= "     $field\n";
138       
139     }
140   }
141   
142 $sel->open($lxtest->{lxadmin});
143 print "Unlock the system\n";
144
145 $sel->click("//input[(\@name=\"action\") and (\@value=\"System entsperren\")]");
146 $sel->wait_for_page_to_load($lxtest->{timeout});
147
148 $cleanedupdb = "none.\n" if ($cleanedupdb eq '');
149 $cleanedupusers = "none.\n" if ($cleanedupusers eq '');
150
151 print "Ready. \nReport:\n--- Cleaned up Users:\n$cleanedupusers---Cleaned up Databases:\n$cleanedupdb";
152
153 $sel->stop;
154
155 exit 1;
156
157