From: Udo Spallek Date: Mon, 4 Dec 2006 08:01:43 +0000 (+0000) Subject: Neue Testingstruktur zur Simulation eines Demobetriebs von Lx X-Git-Tag: release-2.4.0^2~132 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=4e8f112f29ea92e2d820c9e9df57ca819e1708a5;p=kivitendo-erp.git Neue Testingstruktur zur Simulation eines Demobetriebs von Lx --- diff --git a/t/demolx/AllTests.t b/t/demolx/AllTests.t new file mode 100644 index 000000000..89951e92e --- /dev/null +++ b/t/demolx/AllTests.t @@ -0,0 +1,115 @@ +#===================================================================== +# LX-Office ERP +# Copyright (C) 2006 +# Web http://www.lx-office.org +# +#===================================================================== +# +# Author: Udo Spallek +# Email: udono@gmx.net +# +# 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; + push @INC, ['/t/selenium']; + use vars qw( $lxdebug $lxtest $sel ); + use strict; + use Carp; + + use Test::WWW::Selenium; + use Test::More; + use IO::Socket; + + eval { require('t/lxtest.conf'); }; + 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; + }; + + sub server_is_running { + return IO::Socket::INET->new(PeerAddr => $ENV{SRC_HOST} || $lxtest->{seleniumhost}, + PeerPort => $ENV{SRC_PORT} || $lxtest->{seleniumport}, + ); + } + if (server_is_running) { + plan tests => 204; # Need to be cutomized + } + else { + plan skip_all => "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; + } + + diag('Pretests and initialisation'); + + + + $lxtest->{test_id} = time; # create individual ids by unixtime + $lxtest->{testuserlogin} = $lxtest->{testlogin} . $lxtest->{test_id}; + $lxtest->{testuserpasswd} = $lxtest->{test_id}; + $lxtest->{db} = $lxtest->{db} . $lxtest->{test_id}; + + ok(defined $lxtest->{rpw}, "Get root password"); + + 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} = $lxtest->{lxbaseurl} . "admin.pl?path=$lxtest->{path}&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...'); + + opendir(SCRIPTS, 't/selenium/testscripts'); + my @testscripts = sort readdir(SCRIPTS); + + foreach my $script (@testscripts){ + my $file = "t/selenium/testscripts/" . $script; + require_ok($file) if ( $script =~ /^\d\d\d.*\.t$/ ); + } + exit 1; + + $sel=''; # Destroy selenium object + + exit 1; + diff --git a/t/demolx/README b/t/demolx/README new file mode 100644 index 000000000..35ae59a71 --- /dev/null +++ b/t/demolx/README @@ -0,0 +1,7 @@ +This directory contains all selenium testscripts for lx-office. +Selenium testscrips are the prefered way to test the higher lx +functionalities. For the selenium tests you need to install and +run a local selenium server on a machine whitch is able to start +a browser session. See README for more informations. + + diff --git a/t/demolx/cleanup.pl b/t/demolx/cleanup.pl new file mode 100644 index 000000000..f5a0d552d --- /dev/null +++ b/t/demolx/cleanup.pl @@ -0,0 +1,157 @@ +#===================================================================== +# LX-Office ERP +# Copyright (C) 2006 +# Web http://www.lx-office.org +# +#===================================================================== +# +# Author: Udo Spallek +# Email: udono@gmx.net +# +# 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 Cleanup Script +# To clean up all the messy databases and users while debugging testcases +# +####################################################################### + no strict; + push @INC, ['/t/selenium']; + use vars qw( $lxdebug $lxtest $sel ); + use strict; + use Carp; + + use WWW::Selenium; + use IO::Socket; + + my $cleanedupdb = ''; + my $cleanedupusers = ''; + + eval { require('t/lxtest.conf'); }; + if ($@) { + print "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; + }; + + sub server_is_running { + return IO::Socket::INET->new(PeerAddr => $ENV{SRC_HOST} || $lxtest->{seleniumhost}, + PeerPort => $ENV{SRC_PORT} || $lxtest->{seleniumport}, + ); + } + if (server_is_running) { + } + else { + exit 0; + } + + $lxtest->{testuserlogin} = $lxtest->{testlogin}; + $lxtest->{db} = $lxtest->{db}; + + $lxtest->{lxadmin} = $lxtest->{lxbaseurl} . "admin.pl?path=$lxtest->{path}&rpw=$lxtest->{rpw}&nextsub=list_users&action=Weiter"; + + eval { $sel = WWW::Selenium->new( + host => $lxtest->{seleniumhost}, + port => $lxtest->{seleniumport}, + browser => $lxtest->{seleniumbrowser}, + browser_url => $lxtest->{lxadmin}, + auto_stop => '0', + ); + }; + if ($@) { + print "No Selenium Server running, or wrong preferences\n\n"; + exit 0; + } + + + print "\nStarting Testdebugging Cleanup...\n"; + + +### Delete user + +$sel->start; +print "Cleanup all users '$lxtest->{testuserlogin}*'\n"; +$sel->open($lxtest->{lxadmin}); + +my @links= $sel->get_all_links(); +my $testuserlogin = $lxtest->{testuserlogin}; + +foreach my $link (@links) { + + if ($link =~ /$testuserlogin\d\d\d\d\d\d\d\d\d\d/){ + $sel->click("link=$lxtest->{testuserlogin}11*"); + $sel->wait_for_page_to_load($lxtest->{timeout}); + $sel->click("//input[(\@name=\"action\") and (\@value=\"Löschen\")]"); + $sel->wait_for_page_to_load($lxtest->{timeout}); + $cleanedupusers .= " $link\n"; + } +} + +print "Lock the system\n"; +$sel->click("//input[(\@name=\"action\") and (\@value=\"System sperren\")]"); +$sel->wait_for_page_to_load($lxtest->{timeout}); + +print "Cleanup all test databasees: '$lxtest->{db}*'\n"; + + $sel->click("//input[(\@name=\"action\") and (\@value=\"Datenbankadministration\")]"); + $sel->wait_for_page_to_load($lxtest->{timeout}); + $sel->type("dbhost", $lxtest->{dbhost}); + $sel->type("dbport", $lxtest->{dbport}); + $sel->type("dbuser", $lxtest->{dbuser}); + $sel->type("dbpasswd", $lxtest->{dbpasswd}); + + $sel->click("//input[(\@name=\"action\") and (\@value=\"Datenbank löschen\")]"); + $sel->wait_for_page_to_load($lxtest->{timeoutlong}); + + my $field = $sel->get_body_text(); + my $database= $lxtest->{db}; + my @fields = split(' ', $field); + + + foreach my $field (@fields) { + + if ($field =~ /$database\d\d\d\d\d\d\d\d\d\d/){ + $sel->open($lxtest->{lxadmin}); + $sel->click("//input[(\@name=\"action\") and (\@value=\"Datenbankadministration\")]"); + $sel->wait_for_page_to_load($lxtest->{timeout}); + $sel->type("dbhost", $lxtest->{dbhost}); + $sel->type("dbport", $lxtest->{dbport}); + $sel->type("dbuser", $lxtest->{dbuser}); + $sel->type("dbpasswd", $lxtest->{dbpasswd}); + + $sel->click("//input[(\@name=\"action\") and (\@value=\"Datenbank löschen\")]"); + $sel->wait_for_page_to_load($lxtest->{timeoutlong}); + $sel->check("name=db value=$field"); + $sel->click("//input[(\@name=\"action\") and (\@value=\"Weiter\")]"); + $cleanedupdb .= " $field\n"; + + } + } + +$sel->open($lxtest->{lxadmin}); +print "Unlock the system\n"; + +$sel->click("//input[(\@name=\"action\") and (\@value=\"System entsperren\")]"); +$sel->wait_for_page_to_load($lxtest->{timeout}); + +$cleanedupdb = "none.\n" if ($cleanedupdb eq ''); +$cleanedupusers = "none.\n" if ($cleanedupusers eq ''); + +print "Ready. \nReport:\n--- Cleaned up Users:\n$cleanedupusers---Cleaned up Databases:\n$cleanedupdb"; + +$sel->stop; + +exit 1; + + diff --git a/t/demolx/testscripts/001CreateTestDatabase.t b/t/demolx/testscripts/001CreateTestDatabase.t new file mode 100644 index 000000000..cf0c2f6de --- /dev/null +++ b/t/demolx/testscripts/001CreateTestDatabase.t @@ -0,0 +1,37 @@ +### Create Database + +$sel->open_ok($lxtest->{lxadmin}); +$sel->title_is("Lx-Office ERP Administration -"); + +diag('Lock the system'); +$sel->click_ok("//input[(\@name=\"action\") and (\@value=\"System sperren\")]"); +$sel->wait_for_page_to_load_ok($lxtest->{timeout}); + +diag("Create test database '$lxtest->{db}'"); +$sel->title_is("Lx-Office ERP Administration -"); +$sel->click_ok("//input[(\@name=\"action\") and (\@value=\"Datenbankadministration\")]"); +$sel->wait_for_page_to_load_ok($lxtest->{timeout}); +$sel->title_is("Lx-Office ERP / Datenbankadministration -"); +$sel->type_ok("dbuser", $lxtest->{dbuser}); +$sel->type_ok("dbpasswd", $lxtest->{dbpasswd}); +$sel->type_ok("dbuser", $lxtest->{dbuser}); +$sel->type_ok("dbhost", $lxtest->{dbhost}); +$sel->type_ok("dbport", $lxtest->{dbport}); +$sel->type_ok("dbdefault", $lxtest->{dbdefault}); +$sel->click_ok("//input[(\@name=\"action\") and (\@value=\"Datenbank anlegen\")]"); +$sel->wait_for_page_to_load_ok($lxtest->{timeout}); +$sel->title_is("Lx-Office ERP Datenbankadministration / Datenbank anlegen -"); +$sel->type_ok("db", $lxtest->{db}); +$sel->select_ok("encoding", "label=ISO 8859-1"); +$sel->click_ok("//input[(\@name=\"chart\") and (\@value=\"Germany-DATEV-SKR03EU\")]"); +$sel->click_ok("//input[(\@name=\"action\") and (\@value=\"Weiter\")]"); +$sel->wait_for_page_to_load_ok($lxtest->{timeoutlong}); +$sel->title_is("Lx-Office ERP Datenbankadministration / Datenbank anlegen -"); +$sel->click_ok("//input[(\@name=\"action\") and (\@value=\"Weiter\")]"); +$sel->wait_for_page_to_load_ok($lxtest->{timeout}); +$sel->title_is("Lx-Office ERP Administration -"); + +diag('Unlock the system'); +$sel->click_ok("//input[(\@name=\"action\") and (\@value=\"System entsperren\")]"); +$sel->wait_for_page_to_load_ok($lxtest->{timeout}); +$sel->title_is("Lx-Office ERP Administration -"); diff --git a/t/demolx/testscripts/002CreateTestUser.t b/t/demolx/testscripts/002CreateTestUser.t new file mode 100644 index 000000000..aaf51d439 --- /dev/null +++ b/t/demolx/testscripts/002CreateTestUser.t @@ -0,0 +1,32 @@ + +### Create new user +diag("Create test user '$lxtest->{testuserlogin}'"); +$sel->open_ok($lxtest->{lxadmin}); +$sel->title_is("Lx-Office ERP Administration -"); +$sel->click_ok("action"); +$sel->wait_for_page_to_load_ok($lxtest->{timeout}); +$sel->title_is("Lx-Office ERP Administration / Benutzer erfassen -"); +$sel->type_ok("login", $lxtest->{testuserlogin}); +$sel->type_ok("password", $lxtest->{testuserpasswd}); +$sel->type_ok("name", "Selenium"); +$sel->type_ok("email", "selenium\@lx-office.org"); +$sel->type_ok("signature", "Selenium Testuser"); +$sel->type_ok("tel", "0000"); +$sel->type_ok("fax", "1111"); +$sel->type_ok("company", "Sel-enium"); +$sel->type_ok("signature", "Selenium Testuser\nTestfirma"); +$sel->type_ok("address", "Testfirma"); +$sel->type_ok("steuernummer", "111-222-333-444"); +$sel->type_ok("co_ustid", "1234567"); +$sel->type_ok("duns", "0987654321"); +$sel->click_ok("dbdriver"); +$sel->type_ok("newtemplates", "seleniumtestuser"); +$sel->click_ok("menustyle"); +$sel->type_ok("Pg_dbhost", $lxtest->{dbhost}); +$sel->type_ok("Pg_dbname", $lxtest->{db}); +$sel->type_ok("Pg_dbport", $lxtest->{dbport}); +$sel->type_ok("Pg_dbuser", $lxtest->{dbuser}); +$sel->type_ok("Pg_dbpasswd", $lxtest->{dbpasswd}); +$sel->click_ok("action"); +$sel->wait_for_page_to_load_ok($lxtest->{timeout}); +$sel->title_is("Lx-Office ERP Administration -"); diff --git a/t/demolx/testscripts/005UpdateDatabase.t b/t/demolx/testscripts/005UpdateDatabase.t new file mode 100644 index 000000000..53a2e792a --- /dev/null +++ b/t/demolx/testscripts/005UpdateDatabase.t @@ -0,0 +1,62 @@ +### Update Database + +# NOTEST: some preruns for initializing missing parameters +$sel->open($lxtest->{lxadmin}); +$sel->click("//input[(\@name=\"action\") and (\@value=\"Datenbankadministration\")]"); +$sel->wait_for_page_to_load($lxtest->{timeout}); +$sel->type("dbuser", $lxtest->{dbuser}); +$sel->type("dbpasswd", $lxtest->{dbpasswd}); +$sel->type("dbuser", $lxtest->{dbuser}); +$sel->type("dbhost", $lxtest->{dbhost}); +$sel->type("dbport", $lxtest->{dbport}); +$sel->type("dbdefault", $lxtest->{dbdefault}); +$sel->click("//input[(\@name=\"action\") and (\@value=\"Datenbank aktualisieren\")]"); +$sel->wait_for_page_to_load($lxtest->{timeoutlong}); +$sel->title_is("Lx-Office ERP Datenbankadministration / Datenbank aktualisieren -"); + +my $count =0; + +while (){ # count the number of radiobuttons + eval { $sel->is_checked("//input[(\@id=\"$count\")]"); }; + if ( $@ ) { $count--; last; }; + $count++; +} + +#TEST: Now run the Tests + +$sel->open_ok($lxtest->{lxadmin}); +$sel->title_is("Lx-Office ERP Administration -"); + +#diag('Lock the system'); +#$sel->click_ok("//input[(\@name=\"action\") and (\@value=\"System sperren\")]"); +#$sel->wait_for_page_to_load_ok($lxtest->{timeout}); + +diag('Update the database'); + +$sel->click_ok("//input[(\@name=\"action\") and (\@value=\"Datenbankadministration\")]"); +$sel->wait_for_page_to_load_ok($lxtest->{timeout}); +$sel->title_is("Lx-Office ERP / Datenbankadministration -"); +$sel->type_ok("dbuser", $lxtest->{dbuser}); +$sel->type_ok("dbpasswd", $lxtest->{dbpasswd}); +$sel->type_ok("dbuser", $lxtest->{dbuser}); +$sel->type_ok("dbhost", $lxtest->{dbhost}); +$sel->type_ok("dbport", $lxtest->{dbport}); +$sel->type_ok("dbdefault", $lxtest->{dbdefault}); +$sel->click_ok("//input[(\@name=\"action\") and (\@value=\"Datenbank aktualisieren\")]"); +$sel->wait_for_page_to_load_ok($lxtest->{timeoutlong}); +$sel->title_is("Lx-Office ERP Datenbankadministration / Datenbank aktualisieren -"); + +for (my $i=0; $i <= $count; $i++){ + $sel->uncheck_ok("//input[(\@id=\"$i\")]"); +} + +#$sel->click_ok("//input[\@value=\"$lxtest->{db}\"]"); +$sel->check_ok("//input[\@name=\"db$lxtest->{db}\"]"); +$sel->click_ok("//input[(\@name=\"action\") and (\@value=\"Weiter\")]"); +$sel->title_like( qr/Lx-Office ERP Datenbankadministration/ ); + +#diag('Unlock the system'); +#$sel->click_ok("//input[(\@name=\"action\") and (\@value=\"System entsperren\")]"); +#$sel->wait_for_page_to_load_ok($lxtest->{timeout}); +#$sel->title_is("Lx-Office ERP Administration -"); + diff --git a/t/demolx/testscripts/K998DeleteTestUser.t b/t/demolx/testscripts/K998DeleteTestUser.t new file mode 100644 index 000000000..f0c430e82 --- /dev/null +++ b/t/demolx/testscripts/K998DeleteTestUser.t @@ -0,0 +1,9 @@ +### Delete user +diag("Delete test user '$lxtest->{testuserlogin}'"); +$sel->open_ok($lxtest->{lxadmin}); +$sel->title_is("Lx-Office ERP Administration -"); +$sel->click_ok("link=$lxtest->{testuserlogin}"); +$sel->wait_for_page_to_load_ok($lxtest->{timeout}); +$sel->title_is("Lx-Office ERP Administration / Benutzerdaten bearbeiten -"); +$sel->click_ok("//input[(\@name=\"action\") and (\@value=\"Löschen\")]"); +$sel->wait_for_page_to_load_ok($lxtest->{timeout}); diff --git a/t/demolx/testscripts/K999DeleteTestDatabase.t b/t/demolx/testscripts/K999DeleteTestDatabase.t new file mode 100644 index 000000000..511fbd291 --- /dev/null +++ b/t/demolx/testscripts/K999DeleteTestDatabase.t @@ -0,0 +1,35 @@ +#### Delete database + + +$sel->open_ok($lxtest->{lxadmin}); +$sel->title_is("Lx-Office ERP Administration -"); + +diag('Lock the system'); +$sel->click_ok("//input[(\@name=\"action\") and (\@value=\"System sperren\")]"); +$sel->wait_for_page_to_load_ok($lxtest->{timeout}); + +diag("Delete test database '$lxtest->{db}'"); +$sel->click_ok("//input[(\@name=\"action\") and (\@value=\"Datenbankadministration\")]"); +$sel->wait_for_page_to_load_ok($lxtest->{timeout}); +$sel->title_is("Lx-Office ERP / Datenbankadministration -"); +$sel->type_ok("dbhost", $lxtest->{dbhost}); +$sel->type_ok("dbport", $lxtest->{dbport}); +$sel->type_ok("dbuser", $lxtest->{dbuser}); +$sel->type_ok("dbpasswd", $lxtest->{dbpasswd}); +$sel->click_ok("//input[(\@name=\"action\") and (\@value=\"Datenbank löschen\")]"); +$sel->wait_for_page_to_load_ok($lxtest->{timeoutlong}); +$sel->title_is("Lx-Office ERP Datenbankadministration / Datenbank löschen -"); + +$sel->click_ok("//input[\@value=\"$lxtest->{db}\"]"); + +$sel->click_ok("//input[(\@name=\"action\") and (\@value=\"Weiter\")]"); +$sel->wait_for_page_to_load_ok($lxtest->{timeout}); +$sel->body_text_is("Lx-Office ERP Datenbankadministration / Datenbank löschen $lxtest->{db} wurde erfolgreich gelöscht"); +$sel->click_ok("//input[(\@name=\"action\") and (\@value=\"Weiter\")]"); +$sel->wait_for_page_to_load_ok($lxtest->{timeout}); +$sel->title_is("Lx-Office ERP Administration -"); + +diag('Unlock the system'); +$sel->click_ok("//input[(\@name=\"action\") and (\@value=\"System entsperren\")]"); +$sel->wait_for_page_to_load_ok($lxtest->{timeout}); +$sel->title_is("Lx-Office ERP Administration -"); \ No newline at end of file diff --git a/t/demolx/testscripts/README b/t/demolx/testscripts/README new file mode 100644 index 000000000..70b4818d7 --- /dev/null +++ b/t/demolx/testscripts/README @@ -0,0 +1,2 @@ +All Selenium testscripts can be found here. The tests will be included +sequential from 001 to 999. \ No newline at end of file