]> git.sur5r.net Git - bacula/bacula/blob - regress/tests/bweb-test.pl
regress: Start to test configuration menu in bweb
[bacula/bacula] / regress / tests / bweb-test.pl
1 #!/usr/bin/perl -w
2 use strict;
3
4 =head1 LICENSE
5
6    Bweb - A Bacula web interface
7    Bacula® - The Network Backup Solution
8
9    Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
10
11    The main author of Bweb is Eric Bollengier.
12    The main author of Bacula is Kern Sibbald, with contributions from
13    many others, a complete list can be found in the file AUTHORS.
14
15    This program is Free Software; you can redistribute it and/or
16    modify it under the terms of version two of the GNU General Public
17    License as published by the Free Software Foundation plus additions
18    that are listed in the file LICENSE.
19
20    This program is distributed in the hope that it will be useful, but
21    WITHOUT ANY WARRANTY; without even the implied warranty of
22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23    General Public License for more details.
24
25    You should have received a copy of the GNU General Public License
26    along with this program; if not, write to the Free Software
27    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28    02110-1301, USA.
29
30    Bacula® is a registered trademark of Kern Sibbald.
31    The licensor of Bacula is the Free Software Foundation Europe
32    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zurich,
33    Switzerland, email:ftf@fsfeurope.org.
34
35 =head1 USAGE
36
37     - You need to be in a X session
38     - Install Selenium IDE addon from http://seleniumhq.org/
39     - Install through CPAN WWW::Selenium
40       $ perl -e 'install WWW::Selenium' -MCPAN 
41     - Download Selenium RC (remote control) from  http://seleniumhq.org/
42     - unzip the archive, and start the Selenium server (require java >= 1.5)
43       $ java -jar selenium-server.jar
44     - Load bweb sql file
45     - Start the test
46       $ ./tests/bweb-test.pl
47
48 =cut
49
50 use warnings;
51 use Time::HiRes qw(sleep);
52 use Test::WWW::Selenium;
53 use Test::More "no_plan";
54 use Test::Exception;
55 use Getopt::Long;
56 use scripts::functions;
57
58 my ($login, $pass, $url, $verbose, %part, @part, $noclean);
59 my @available = qw/client group location run missingjob media overview/;
60
61 GetOptions ("login=s"  => \$login,
62             "passwd=s" => \$pass,
63             "url|u=s"  => \$url,
64             "module=s@"   => \@part,
65             "verbose"  => \$verbose,
66             "nocleanup" => \$noclean,
67             );
68
69 die "Usage: $0 --url http://.../cgi-bin/bweb/bweb.pl [-m module] [-n]"
70     unless ($url);
71
72 if (scalar(@part)) {
73     %part = map { $_ => 1 } @part;
74 } else {
75     %part = map { $_ => 1 } @available;
76 }
77
78 if (!$noclean) {
79     cleanup();
80     start_bacula();
81 }
82
83 my $sel = Test::WWW::Selenium->new( host => "localhost", 
84                                     port => 4444, 
85                                     browser => "*firefox", 
86                                     browser_url => $url );
87
88 if ($part{client}) {
89 # test client
90     $sel->open_ok("/cgi-bin/bweb/bweb.pl?");
91     $sel->wait_for_page_to_load_ok("30000");
92     $sel->is_text_present_ok("Informations");
93
94     $sel->click_ok("link=Clients");
95     $sel->wait_for_page_to_load_ok("30000");
96
97     $sel->click_ok("//input[\@name='client']"); # click the first client
98     $sel->click_ok("//button[\@name='action' and \@value='client_status']");
99     $sel->wait_for_page_to_load_ok("30000");
100
101     $sel->is_text_present_ok("Command output");
102     $sel->click_ok("link=Clients");
103     $sel->wait_for_page_to_load_ok("30000");
104
105     $sel->is_text_present_ok("Running Jobs"); # This message is in client status
106 }
107
108 if ($part{media}) {
109 # add media
110     $sel->open_ok("/cgi-bin/bweb/bweb.pl");
111     $sel->click_ok("link=Add Media");
112     $sel->wait_for_page_to_load_ok("30000");
113
114     $sel->select_ok("pool", "label=Scratch");
115     $sel->select_ok("storage", "label=File");
116     $sel->type_ok("nb", "10");
117     $sel->click_ok("//button[\@name='action']"); # create 10 volumes
118     $sel->wait_for_page_to_load_ok("30000");
119
120   WAIT: {
121       for (1..60) {
122           if (eval { $sel->is_text_present("Select") }) { pass; last WAIT }
123         sleep(1);
124       }
125       fail("timeout");
126 }
127     $sel->click_ok("link=All Media");
128     $sel->wait_for_page_to_load_ok("30000");
129
130     $sel->is_text_present_ok("Vol0001");
131     $sel->is_text_present_ok("Vol0010");
132     $sel->select_ok("mediatype", "label=File");
133     $sel->select_ok("volstatus", "label=Append");
134     $sel->select_ok("pool", "label=Scratch");
135     $sel->click_ok("//button[\@name='action']");
136     $sel->wait_for_page_to_load_ok("30000");
137
138     $sel->is_text_present_ok("Vol0001");
139     $sel->click_ok("media");
140     $sel->click_ok("//button[\@name='action' and \@value='update_media']");
141     $sel->wait_for_page_to_load_ok("30000");
142
143     $sel->select_ok("volstatus", "label=Archive");
144     $sel->select_ok("enabled", "label=no");
145     $sel->click_ok("//button[\@name='action']");
146     $sel->wait_for_page_to_load_ok("30000");
147
148     $sel->click_ok("arrow_0");
149     $sel->is_text_present_ok("New Volume status is: Archive");
150     $sel->click_ok("link=All Media");
151     $sel->wait_for_page_to_load_ok("30000");
152
153     $sel->is_text_present_ok("Archive");
154     $sel->select_ok("volstatus", "label=Append");
155     $sel->click_ok("//button[\@name='action']");
156     $sel->wait_for_page_to_load_ok("30000");
157
158     $sel->click_ok("media");
159     $sel->click_ok("//button[\@name='action' and \@value='media_zoom']");
160     $sel->wait_for_page_to_load_ok("30000");
161
162     $sel->is_text_present_ok("Volume Infos");
163     $sel->click_ok("//button[\@name='action' and \@value='purge']");
164     $sel->wait_for_page_to_load_ok("30000");
165
166     $sel->is_text_present_ok("Marking it purged");
167 }
168
169 if ($part{missingjob}) {
170 # view missing jobs
171     $sel->open_ok("/cgi-bin/bweb/bweb.pl");
172     $sel->click_ok("link=Missing Jobs");
173     $sel->wait_for_page_to_load_ok("30000");
174
175     $sel->is_text_present_ok("backup");
176     $sel->is_text_present_ok("BackupCatalog");
177     $sel->click_ok("job");
178     $sel->click_ok("//input[\@name='job' and \@value='BackupCatalog']");
179     $sel->click_ok("//button[\@name='action' and \@value='job']");
180     $sel->wait_for_page_to_load_ok("30000");
181
182     $sel->body_text_isnt("BackupCatalog");
183 }
184
185 if ($part{run}) {
186 # run a new job
187     $sel->open_ok("/cgi-bin/bweb/bweb.pl?");
188     $sel->click_ok("link=Defined Jobs");
189     $sel->wait_for_page_to_load_ok("30000");
190
191     $sel->select_ok("job", "label=backup");
192     $sel->is_text_present_ok("backup");
193     $sel->click_ok("//button[\@name='action' and \@value='run_job_mod']");
194     $sel->wait_for_page_to_load_ok("30000");
195
196     $sel->is_text_present_ok("Default");
197     $sel->is_text_present_ok("Full Set");
198     $sel->is_text_present_ok("Incremental");
199     $sel->click_ok("//button[\@name='action']");
200     $sel->wait_for_page_to_load_ok("30000");
201
202   WAIT: {
203       for (1..60) {
204           if (eval { $sel->is_text_present("Start Backup JobId") }) { pass; last WAIT }
205           sleep(1);
206       }
207     fail("timeout");
208     }
209     $sel->is_text_present_ok("Log: backup on");
210     $sel->click_ok("//button[\@name='action']");
211     $sel->wait_for_page_to_load_ok("30000");
212
213   WAIT: {
214       for (1..60) {
215           if (eval { $sel->is_text_present("Termination: Backup OK") }) { pass; last WAIT }
216           sleep(1);
217       }
218       fail("timeout");
219     }
220     my $volume = $sel->get_text("//tr[\@id='even_row']/td[12]");
221     $sel->click_ok("//button[\@name='action' and \@value='media']");
222     $sel->wait_for_page_to_load_ok("30000");
223
224     my $volume_found = $sel->get_text("//tr[\@id='even_row']/td[1]");
225     $sel->click_ok("media");
226     $sel->text_is("//tr[\@id='even_row']/td[5]", "Append");
227     $sel->click_ok("//button[\@name='action' and \@value='media_zoom']");
228     $sel->wait_for_page_to_load_ok("30000");
229
230     $sel->is_text_present_ok("Volume Infos");
231     $sel->click_ok("//img[\@title='terminated normally']");
232     $sel->wait_for_page_to_load_ok("30000");
233
234     $sel->click_ok("//button[\@name='action' and \@value='fileset_view']");
235     $sel->wait_for_page_to_load_ok("30000");
236
237     $sel->is_text_present_ok("FileSet Full Set");
238     $sel->is_text_present_ok("What is included:");
239     $sel->is_text_present_ok("/regress/build");
240     $sel->go_back_ok();
241     $sel->wait_for_page_to_load_ok("30000");
242
243     $sel->click_ok("//button[\@name='action' and \@value='run_job_mod']");
244     $sel->wait_for_page_to_load_ok("30000");
245
246     $sel->is_element_present_ok("level");
247     $sel->selected_value_is("name=level", "Full");
248     $sel->selected_label_is("name=fileset", "Full Set");
249     $sel->selected_label_is("name=job", "backup");
250     $sel->click_ok("//button[\@name='action' and \@value='fileset_view']");
251     $sel->wait_for_page_to_load_ok("30000");
252
253     $sel->is_text_present_ok("FileSet Full Set");
254     $sel->is_text_present_ok("/regress/build");
255 }
256
257 if ($part{group}) {
258 # test group
259     $sel->open_ok("/cgi-bin/bweb/bweb.pl");
260     $sel->click_ok("link=Groups");
261     $sel->wait_for_page_to_load_ok("30000");
262
263     $sel->text_is("//h1", "Groups");
264     $sel->click_ok("//button[\@name='action' and \@value='groups_edit']");
265     $sel->wait_for_page_to_load_ok("30000");
266
267     $sel->type_ok("newgroup", "All");
268     $sel->select_ok("name=client", "index=0");
269     $sel->click_ok("//button[\@name='action' and \@value='groups_save']");
270     $sel->wait_for_page_to_load_ok("30000");
271
272     $sel->is_text_present_ok("All");
273     $sel->click_ok("//input [\@name='client_group' and \@value='All']");
274     $sel->click_ok("//button[3]");
275     $sel->wait_for_page_to_load_ok("30000");
276
277     $sel->is_text_present_ok("Group: 'All'");
278     $sel->selected_index_is("name=client", "0");
279     $sel->click_ok("//button[\@name='action' and \@value='groups_save']");
280     $sel->wait_for_page_to_load_ok("30000");
281
282     $sel->click_ok("//input[\@name='client_group' and \@value='All']");
283     $sel->click_ok("//button[4]");
284     $sel->wait_for_page_to_load_ok("30000");
285
286     $sel->click_ok("//input[\@name='client']");
287     $sel->click_ok("//button[\@name='action' and \@value='client_edit']");
288     $sel->wait_for_page_to_load_ok("30000");
289
290     $sel->is_text_present_ok("All");
291     $sel->click_ok("link=Groups");
292     $sel->wait_for_page_to_load_ok("30000");
293
294     $sel->click_ok("//button[\@name='action' and \@value='groups_edit']");
295     $sel->wait_for_page_to_load_ok("30000");
296
297     $sel->type_ok("newgroup", "Empty");
298     $sel->click_ok("//button[\@name='action']");
299     $sel->wait_for_page_to_load_ok("30000");
300
301     $sel->click_ok("client_group");
302     $sel->is_text_present_ok("Empty");
303     $sel->click_ok("//button[\@name='action' and \@value='client']");
304     $sel->wait_for_page_to_load_ok("30000");
305
306     $sel->click_ok("//input[\@name='client']");
307     $sel->click_ok("//button[\@name='action' and \@value='client_edit']");
308     $sel->wait_for_page_to_load_ok("30000");
309
310     $sel->click_ok("link=Groups");
311     $sel->wait_for_page_to_load_ok("30000");
312
313     $sel->click_ok("//input[\@name='client_group' and \@value='Empty']");
314     $sel->click_ok("//button[\@name='action' and \@value='groups_del']");
315     ok($sel->get_confirmation() =~ /^Do you want to delete this group[\s\S]$/);
316     $sel->click_ok("link=Groups");
317     $sel->wait_for_page_to_load_ok("30000");
318
319     $sel->click_ok("//button[\@name='action']");
320     $sel->wait_for_page_to_load_ok("30000");
321
322     $sel->type_ok("newgroup", "Empty");
323     $sel->click_ok("//button[\@name='action']");
324     $sel->wait_for_page_to_load_ok("30000");
325
326     $sel->is_text_present_ok("Empty");
327     $sel->click_ok("//input[\@name='client_group' and \@value='All']");
328     $sel->click_ok("//button[\@name='action' and \@value='client']");
329     $sel->wait_for_page_to_load_ok("30000");
330
331     $sel->click_ok("//input[\@name='client']");
332     $sel->click_ok("//button[\@name='action' and \@value='client_edit']");
333     $sel->wait_for_page_to_load_ok("30000");
334
335     ok(not $sel->is_checked("//input[\@name='client_group' and \@value='Empty']"));
336     $sel->click_ok("link=Group Statistics");
337     $sel->wait_for_page_to_load_ok("30000");
338
339     $sel->is_text_present_ok("All");
340     $sel->is_text_present_ok("Empty");
341     $sel->click_ok("link=Groups");
342     $sel->wait_for_page_to_load_ok("30000");
343
344     $sel->click_ok("//input[\@name='client_group' and \@value='Empty']");
345     $sel->click_ok("document.forms[1].elements[4]");
346     $sel->wait_for_page_to_load_ok("30000");
347
348     $sel->type_ok("newgroup", "EmptyGroup");
349     $sel->click_ok("//button[\@name='action']");
350     $sel->wait_for_page_to_load_ok("30000");
351
352     $sel->is_text_present_ok("EmptyGroup");
353 }
354
355 if ($part{location}) {
356 # test location
357     $sel->open_ok("/cgi-bin/bweb/bweb.pl");
358     $sel->click_ok("link=Locations");
359     $sel->wait_for_page_to_load_ok("30000");
360
361     $sel->click_ok("//button[\@name='action' and \@value='location_add']");
362     $sel->wait_for_page_to_load_ok("30000");
363
364     $sel->type_ok("location", "Bank");
365     $sel->click_ok("//button[\@name='action']"); # save
366     $sel->wait_for_page_to_load_ok("30000");
367
368     $sel->is_text_present_ok("Bank");
369     $sel->click_ok("location");
370     $sel->click_ok("//button[\@name='action' and \@value='location_edit']");
371     $sel->wait_for_page_to_load_ok("30000");
372
373     $sel->type_ok("cost", "100");
374     $sel->is_text_present_ok("Location: Bank");
375     $sel->click_ok("//button[\@name='action']");
376     $sel->wait_for_page_to_load_ok("30000");
377
378     $sel->is_text_present_ok("100");
379     $sel->is_element_present_ok("//img[\@src='/bweb/inflag1.png']");
380     $sel->click_ok("location");
381     $sel->click_ok("//button[\@name='action' and \@value='location_edit']");
382     $sel->wait_for_page_to_load_ok("30000");
383
384     $sel->select_ok("enabled", "label=no");
385     $sel->click_ok("//button[\@name='action']");
386     $sel->wait_for_page_to_load_ok("30000");
387
388     $sel->is_element_present_ok("//img[\@src='/bweb/inflag0.png']");
389     $sel->click_ok("location");
390     $sel->click_ok("//button[\@name='action' and \@value='location_edit']");
391     $sel->wait_for_page_to_load_ok("30000");
392
393     $sel->select_ok("enabled", "label=archived");
394     $sel->click_ok("//button[\@name='action']");
395     $sel->wait_for_page_to_load_ok("30000");
396
397     $sel->is_element_present_ok("//img[\@src='/bweb/inflag2.png']");
398     $sel->click_ok("location");
399     $sel->click_ok("//button[\@name='action' and \@value='location_edit']");
400     $sel->wait_for_page_to_load_ok("30000");
401
402     $sel->type_ok("newlocation", "Office");
403     $sel->click_ok("//button[\@name='action']");
404     $sel->wait_for_page_to_load_ok("30000");
405
406     $sel->is_text_present_ok("Office");
407     $sel->click_ok("link=All Media");
408     $sel->wait_for_page_to_load_ok("30000");
409
410     $sel->click_ok("media");
411     $sel->click_ok("//button[\@name='action' and \@value='update_media']");
412     $sel->wait_for_page_to_load_ok("30000");
413
414     $sel->select_ok("location", "label=Office");
415     $sel->click_ok("//button[\@name='action']");
416     $sel->wait_for_page_to_load_ok("30000");
417
418     $sel->selected_value_is("location", "Office");
419     $sel->click_ok("//button[\@name='action' and \@value='media']");
420     $sel->wait_for_page_to_load_ok("30000");
421
422     $sel->select_ok("location", "label=Office");
423     $sel->click_ok("//button[\@name='action']");
424     $sel->wait_for_page_to_load_ok("30000");
425
426     $sel->body_text_isnt("Vol0010");
427     $sel->click_ok("link=Locations");
428     $sel->wait_for_page_to_load_ok("30000");
429
430     $sel->click_ok("location");
431     $sel->click_ok("//button[\@name='action' and \@value='location_del']");
432     ok($sel->get_confirmation() =~ /^Do you want to remove this location[\s\S]$/);
433     $sel->wait_for_page_to_load_ok("30000");
434
435     $sel->is_text_present_ok("Sorry, the location must be empty");
436     $sel->click_ok("link=Locations");
437     $sel->wait_for_page_to_load_ok("30000");
438
439     $sel->click_ok("//button[\@name='action']");
440     $sel->wait_for_page_to_load_ok("30000");
441
442     $sel->type_ok("location", "OtherPlace");
443     $sel->click_ok("//button[\@name='action']");
444     $sel->wait_for_page_to_load_ok("30000");
445
446     $sel->click_ok("location");
447     $sel->click_ok("//button[\@name='action' and \@value='media']");
448     $sel->wait_for_page_to_load_ok("30000");
449
450     $sel->click_ok("media");
451     $sel->click_ok("//button[\@name='action' and \@value='update_media']");
452     $sel->wait_for_page_to_load_ok("30000");
453
454     $sel->select_ok("location", "label=OtherPlace");
455     $sel->click_ok("//button[\@name='action']");
456     $sel->wait_for_page_to_load_ok("30000");
457
458     $sel->click_ok("link=Locations");
459     $sel->wait_for_page_to_load_ok("30000");
460
461     $sel->click_ok("location");
462     $sel->click_ok("//button[\@name='action' and \@value='location_del']");
463     ok($sel->get_confirmation() =~ /^Do you want to remove this location[\s\S]$/);
464     $sel->wait_for_page_to_load_ok("30000");
465
466     $sel->body_text_isnt("Office");
467 }
468
469 if ($part{overview}) {
470     $sel->open_ok("/cgi-bin/bweb/bweb.pl");
471     $sel->click_ok("link=Jobs overview");
472     $sel->wait_for_page_to_load_ok("30000");
473
474     $sel->is_text_present_ok("All");
475     $sel->click_ok("link=All");
476     $sel->wait_for_page_to_load_ok("30000");
477
478     $sel->click_ok("link=zogi-fd");
479     $sel->wait_for_page_to_load_ok("30000");
480
481     $sel->is_text_present_ok("backup");
482     $sel->is_text_present_ok("Full Set");
483 }
484
485 if ($part{config}) {
486     $sel->open_ok("/cgi-bin/bweb/bweb.pl");
487     $sel->click_ok("link=Configuration");
488     $sel->wait_for_page_to_load_ok("30000");
489     $sel->is_text_present_ok("Main Configuration");
490
491     $sel->click_ok("//button[\@name='action' and \@value='edit_main_conf']");
492     $sel->wait_for_page_to_load_ok("30000");
493     $sel->is_text_present_ok("Main Configuration");
494     my $dbi = $sel->get_text("dbi");
495     my $user = $sel->get_text("user");
496     my $pass = $sel->get_text("password");
497     my $histo = $sel->get_text("stat_job_table");
498
499     print "dbi=$dbi histo=$histo\n";
500     if ($histo eq 'Job') {
501         $sel->type_ok("stat_job_table", "JobHisto");
502     } else {
503         $sel->type_ok("stat_job_table", "Job");
504     }
505 }