Projekt

Allgemein

Profil

Herunterladen (5,2 KB) Statistiken
| Zweig: | Markierung: | Revision:
4c2d836d Udo Spallek
#=====================================================================
# LX-Office ERP
111276a1 Thomas Kasulke
# Copyright (C) 2006/2007
4c2d836d Udo Spallek
# Web http://www.lx-office.org
#
#=====================================================================
#
111276a1 Thomas Kasulke
# Author: Udo Spallek, Thomas Kasulke
# Email: udono@gmx.net, tkasulke@linet-services.de
4c2d836d Udo Spallek
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#======================================================================
#
# Selenium Main Caller
# Call all Selenium scripts from here. To use Selenium tests in
# Lx-Office you need to Install Selenium Remote Control. Take a look at
# the README Document for further informatinons on installing Selenium
# and testing Lx-Office and of course writing your own testcases.
#
#######################################################################
no strict;
111276a1 Thomas Kasulke
push @INC, ['/t/selenium', \&init_server];
4c2d836d Udo Spallek
use vars qw( $lxdebug $lxtest $sel );
use strict;
use Carp;

d14f75f9 Udo Spallek
use Test::WWW::Selenium;
111276a1 Thomas Kasulke
use Test::More qw(no_plan);
d14f75f9 Udo Spallek
use IO::Socket;
4c2d836d Udo Spallek
111276a1 Thomas Kasulke
if(-f "/tmp/lxtest-temp.conf") {
eval { require('/tmp/lxtest-temp.conf'); };
}
else {
eval { require('t/lxtest.conf'); };
}
4c2d836d Udo Spallek
if ($@) {
diag("No test configuration found in t/lxtest.conf.\n
Maybe you forget to copy t/lxtest.conf.default to t/lxtest.conf. Exit test...\n");
exit 0;
111276a1 Thomas Kasulke
}
4c2d836d Udo Spallek
d14f75f9 Udo Spallek
sub server_is_running {
return IO::Socket::INET->new(PeerAddr => $ENV{SRC_HOST} || $lxtest->{seleniumhost},
PeerPort => $ENV{SRC_PORT} || $lxtest->{seleniumport},
);
}
4c2d836d Udo Spallek
111276a1 Thomas Kasulke
# if (server_is_running) {
# plan tests => 200; # Need to be cutomized
# }
sub init_server {
d4d655d8 Thomas Kasulke
my $singlefileonly = 0;
004280c1 Thomas Kasulke
if ($_[0] eq "singlefileonly") {
$singlefileonly = 1;
shift;
}
111276a1 Thomas Kasulke
if(!server_is_running) {
print "No selenium server found! "
."Maybe you forgot to start it or "
."the preferences in t/lxtest.conf doesen't fit to your system";
exit 0;
}
4c2d836d Udo Spallek
111276a1 Thomas Kasulke
diag('Pretests and initialisation');
d14f75f9 Udo Spallek


111276a1 Thomas Kasulke
$lxtest->{test_id} = time; # create individual ids by unixtime
6c8a96c2 Thomas Kasulke
$lxtest->{testuserlogin} = $lxtest->{testlogin} . $lxtest->{test_id} if(!$lxtest->{testuserlogin});
$lxtest->{testuserpasswd} = $lxtest->{test_id} if(!$lxtest->{testuserpasswd});
$lxtest->{db} = $lxtest->{db} . $lxtest->{test_id} if(!($lxtest->{db} =~ /^seleniumtestdatabase[0-9]{10}$/));
4c2d836d Udo Spallek
111276a1 Thomas Kasulke
ok(defined $lxtest->{rpw}, "Get root password");
d14f75f9 Udo Spallek
111276a1 Thomas Kasulke
ok(defined $lxtest->{dbhost}, "found dbhost in config");
ok(defined $lxtest->{dbport}, "found dbport in config");
ok(defined $lxtest->{dbuser}, "found dbuser in config");
ok(defined $lxtest->{dbpasswd}, "found dbpasswd in config");

$lxtest->{lxadmin_url} = $lxtest->{lxbaseurl} . "admin.pl";
$lxtest->{lxadmin_with_get} = $lxtest->{lxadmin_url} . "?rpw=$lxtest->{rpw}&nextsub=list_users&action=Weiter";
$lxtest->{lxadmin} = $lxtest->{lxadmin_url} . "?rpw=$lxtest->{rpw}&nextsub=list_users&action=Weiter";




eval { $sel = Test::WWW::Selenium->new(
host => $lxtest->{seleniumhost},
port => $lxtest->{seleniumport},
browser => $lxtest->{seleniumbrowser},
browser_url => $lxtest->{lxadmin},
auto_stop => '0',
);
};
if ($@) {
diag("No Selenium Server running, or wrong preferences\n\n");
exit 0;
}
ok(defined $sel, 'Creating Selenium Object');

diag('Starting Selenium tests...');
004280c1 Thomas Kasulke
if(!$singlefileonly) {
foreach my $scriptdir (@_) {
c1efeacb Thomas Kasulke
opendir(SCRIPTS, 't/selenium/testscripts/' . $scriptdir) or die "Can't open directory!" . $!;
004280c1 Thomas Kasulke
foreach (sort readdir(SCRIPTS)) {
d4d655d8 Thomas Kasulke
if ( $_ =~ /^\w\d\d\d.*\.t$|^\d\d\d.*\.t$/ && !$sel->{ran_tests}{"t/selenium/testscripts/". $scriptdir . "/" . $_}) {
require_ok("t/selenium/testscripts/". $scriptdir . "/" . $_);
$sel->{ran_tests}{"t/selenium/testscripts/". $scriptdir . "/" . $_} = 1;
}
004280c1 Thomas Kasulke
}
closedir(SCRIPTS);
111276a1 Thomas Kasulke
}
004280c1 Thomas Kasulke
}
else {
d4d655d8 Thomas Kasulke
foreach (@_) {
if ( $_ =~ /^.*\/\w\d\d\d.*\.t$|^.*\/\d\d\d.*\.t$/ && !$sel->{ran_tests}{$_}) {
require_ok($_);
$sel->{ran_tests}{$_} = 1;
}
}
111276a1 Thomas Kasulke
}
6c8a96c2 Thomas Kasulke
if($!) {
@! = ("Test fehlgeschlagen!");
}
111276a1 Thomas Kasulke
$sel->stop();
d14f75f9 Udo Spallek
}
111276a1 Thomas Kasulke
c1efeacb Thomas Kasulke
sub start_login() {
require "t/selenium/testscripts/base/000Login.t" if(!$sel->{_page_opened});
skip("Failed page to load pages!",) if(!$sel->{_page_opened});

if($sel->get_title() ne "Lx-Office Version 2.4.3 - Selenium - " . $lxtest->{db}){
require "t/selenium/testscripts/base/000Login.t";
}

$sel->select_frame_ok("relative=up");
}
111276a1 Thomas Kasulke
1;