1 #=====================================================================
4 # Web http://www.lx-office.org
6 #=====================================================================
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.
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 #======================================================================
25 # Selenium Cleanup Script
26 # To clean up all the messy databases and users while debugging testcases
28 #######################################################################
30 push @INC, ['/t/selenium'];
31 use vars qw( $lxdebug $lxtest $sel );
39 my $cleanedupusers = '';
41 eval { require('t/lxtest.conf'); };
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";
48 sub server_is_running {
49 return IO::Socket::INET->new(PeerAddr => $ENV{SRC_HOST} || $lxtest->{seleniumhost},
50 PeerPort => $ENV{SRC_PORT} || $lxtest->{seleniumport},
53 if (server_is_running) {
59 $lxtest->{testuserlogin} = $lxtest->{testlogin};
60 $lxtest->{db} = $lxtest->{db};
62 $lxtest->{lxadmin} = $lxtest->{lxbaseurl} . "admin.pl?rpw=$lxtest->{rpw}&nextsub=list_users&action=Weiter";
64 eval { $sel = WWW::Selenium->new(
65 host => $lxtest->{seleniumhost},
66 port => $lxtest->{seleniumport},
67 browser => $lxtest->{seleniumbrowser},
68 browser_url => $lxtest->{lxadmin},
73 print "No Selenium Server running, or wrong preferences\n\n";
78 print "\nStarting Testdebugging Cleanup...\n";
84 print "Cleanup all users '$lxtest->{testuserlogin}*'\n";
85 $sel->open($lxtest->{lxadmin});
87 my @links= $sel->get_all_links();
88 my $testuserlogin = $lxtest->{testuserlogin};
90 foreach my $link (@links) {
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";
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});
105 print "Cleanup all test databasees: '$lxtest->{db}*'\n";
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});
114 $sel->click("//input[(\@name=\"action\") and (\@value=\"Datenbank löschen\")]");
115 $sel->wait_for_page_to_load($lxtest->{timeoutlong});
117 my $field = $sel->get_body_text();
118 my $database= $lxtest->{db};
119 my @fields = split(' ', $field);
122 foreach my $field (@fields) {
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});
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";
142 $sel->open($lxtest->{lxadmin});
143 print "Unlock the system\n";
145 $sel->click("//input[(\@name=\"action\") and (\@value=\"System entsperren\")]");
146 $sel->wait_for_page_to_load($lxtest->{timeout});
148 $cleanedupdb = "none.\n" if ($cleanedupdb eq '');
149 $cleanedupusers = "none.\n" if ($cleanedupusers eq '');
151 print "Ready. \nReport:\n--- Cleaned up Users:\n$cleanedupusers---Cleaned up Databases:\n$cleanedupdb";