From e7a0927f0f12c014c450ed42c9c635f2e3c7ca96 Mon Sep 17 00:00:00 2001 From: Nico Schedel Date: Tue, 30 Apr 2019 11:30:10 +0200 Subject: [PATCH] TT#56376 selenium: move login_ok() to Collection.pm Moving function login_ok() from FirefoxExtensions.pm to Collection.pm. FirefoxExtensions.pm should be used to store functions which make programming stuff easier. Common.pm should be used to store commonly used selenium routines. Edited all files accordingly to work with this change. Change-Id: I00ece7de88f7677665c5b8b87ce1e60be9c5854d --- t/lib/Selenium/Collection/Common.pm | 19 +++++++++++++++++++ .../Remote/Driver/FirefoxExtensions.pm | 19 ------------------- t/selenium/admin-login.t | 7 ++++++- t/selenium/controller_billing.t | 7 ++++++- t/selenium/controller_customer.t | 3 ++- t/selenium/controller_domain.t | 2 +- t/selenium/controller_peering.t | 7 ++++++- t/selenium/controller_reseller.t | 2 +- t/selenium/controller_rw_ruleset.t | 2 +- 9 files changed, 42 insertions(+), 26 deletions(-) diff --git a/t/lib/Selenium/Collection/Common.pm b/t/lib/Selenium/Collection/Common.pm index 787d3f709b..6b2b1c036d 100644 --- a/t/lib/Selenium/Collection/Common.pm +++ b/t/lib/Selenium/Collection/Common.pm @@ -10,6 +10,25 @@ has 'driver' => ( is => 'ro' ); +sub login_ok { + my ($self) = @_; + diag("Loading login page (logout first)"); + my $uri = $ENV{CATALYST_SERVER} || 'http://localhost:3000'; + $self->driver->get("$uri/logout"); # make sure we are logged out + $self->driver->get("$uri/login"); + + diag("Do Admin Login"); + ok($self->driver->find_text("Admin Sign In"), "Text Admin Sign In found"); + is($self->driver->get_title, '', 'No Tab Title was set'); + $self->driver->find_element('#username', 'css')->send_keys('administrator'); + $self->driver->find_element('#password', 'css')->send_keys('administrator'); + $self->driver->find_element('#submit', 'css')->click(); + + diag("Checking Admin interface"); + is($self->driver->get_title, 'Dashboard', 'Tab Title is correct'); + is($self->driver->find_element('//*[@id="masthead"]//h2')->get_text(), "Dashboard", 'We are in the Dashboard. Login Successful'); +} + sub create_domain { my ($self, $name, $reseller) = @_; return unless $name; diff --git a/t/lib/Selenium/Remote/Driver/FirefoxExtensions.pm b/t/lib/Selenium/Remote/Driver/FirefoxExtensions.pm index 73e53b9659..055ed09892 100644 --- a/t/lib/Selenium/Remote/Driver/FirefoxExtensions.pm +++ b/t/lib/Selenium/Remote/Driver/FirefoxExtensions.pm @@ -33,25 +33,6 @@ sub BUILD { $self->set_timeout("implicit", 10_000); } -sub login_ok { - my ($self) = @_; - diag("Loading login page (logout first)"); - my $uri = $ENV{CATALYST_SERVER} || 'http://localhost:3000'; - $self->get("$uri/logout"); # make sure we are logged out - $self->get("$uri/login"); - - diag("Do Admin Login"); - ok($self->find_text("Admin Sign In"), "Text Admin Sign In found"); - is($self->get_title, '', 'No Tab Title was set'); - $self->find_element('#username', 'css')->send_keys('administrator'); - $self->find_element('#password', 'css')->send_keys('administrator'); - $self->find_element('#submit', 'css')->click(); - - diag("Checking Admin interface"); - is($self->get_title, 'Dashboard', 'Tab Title is correct'); - is($self->find_element('//*[@id="masthead"]//h2')->get_text(), "Dashboard", 'We are in the Dashboard. Login Successfull'); -} - sub find_text { try { my ($self, $text, $scheme) = @_; diff --git a/t/selenium/admin-login.t b/t/selenium/admin-login.t index d5ce168a71..77236cae80 100644 --- a/t/selenium/admin-login.t +++ b/t/selenium/admin-login.t @@ -4,6 +4,7 @@ use strict; use lib 't/lib'; use Test::More import => [qw(done_testing is diag ok)]; use Selenium::Remote::Driver::FirefoxExtensions; +use Selenium::Collection::Common; my $browsername = $ENV{BROWSER_NAME} || "firefox"; # possible values: firefox, htmlunit, chrome @@ -14,9 +15,13 @@ my $d = Selenium::Remote::Driver::FirefoxExtensions->new( }, ); +my $c = Selenium::Collection::Common->new( + driver => $d +); + ok(1, "Instantiation ok"); -$d->login_ok(); +$c->login_ok(); diag("Done: admin-login.t"); done_testing; diff --git a/t/selenium/controller_billing.t b/t/selenium/controller_billing.t index bd2a07f267..f8aecfb07b 100644 --- a/t/selenium/controller_billing.t +++ b/t/selenium/controller_billing.t @@ -4,6 +4,7 @@ use strict; use lib 't/lib'; use Test::More import => [qw(done_testing is ok diag todo_skip)]; use Selenium::Remote::Driver::FirefoxExtensions; +use Selenium::Collection::Common; my $browsername = $ENV{BROWSER_NAME} || "firefox"; # possible values: firefox, htmlunit, chrome @@ -14,7 +15,11 @@ my $d = Selenium::Remote::Driver::FirefoxExtensions->new( }, ); -$d->login_ok(); +my $c = Selenium::Collection::Common->new( + driver => $d +); + +$c->login_ok(); my $billingname = ("testprofile" . int(rand(10000))); #create string for checking later diag("Go to Billing page"); diff --git a/t/selenium/controller_customer.t b/t/selenium/controller_customer.t index c440a64407..cd847dd6f6 100644 --- a/t/selenium/controller_customer.t +++ b/t/selenium/controller_customer.t @@ -27,7 +27,8 @@ if(!$pbx){ } else { print "---PBX check is ENABLED---\n"; }; -$d->login_ok(); + +$c->login_ok(); my $domainstring = ("test" . int(rand(10000)) . ".example.org"); #create string for checking later $c->create_domain($domainstring); diff --git a/t/selenium/controller_domain.t b/t/selenium/controller_domain.t index d0398e4278..e79c12d681 100644 --- a/t/selenium/controller_domain.t +++ b/t/selenium/controller_domain.t @@ -19,7 +19,7 @@ my $c = Selenium::Collection::Common->new( ); diag('Logging in'); -$d->login_ok(); +$c->login_ok(); my $domainstring = ("test" . int(rand(10000)) . ".example.org"); #create string for checking later $c->create_domain($domainstring); diff --git a/t/selenium/controller_peering.t b/t/selenium/controller_peering.t index 8fdeed446d..96840313a2 100644 --- a/t/selenium/controller_peering.t +++ b/t/selenium/controller_peering.t @@ -4,6 +4,7 @@ use strict; use lib 't/lib'; use Test::More import => [qw(done_testing is ok diag todo_skip)]; use Selenium::Remote::Driver::FirefoxExtensions; +use Selenium::Collection::Common; my $browsername = $ENV{BROWSER_NAME} || "firefox"; # possible values: firefox, htmlunit, chrome @@ -14,7 +15,11 @@ my $d = Selenium::Remote::Driver::FirefoxExtensions->new( }, ); -$d->login_ok(); +my $c = Selenium::Collection::Common->new( + driver => $d +); + +$c->login_ok(); my $groupname = ("testinggroup" . int(rand(10000))); #create string for checking later diff --git a/t/selenium/controller_reseller.t b/t/selenium/controller_reseller.t index cecede9c62..06eb8a39df 100644 --- a/t/selenium/controller_reseller.t +++ b/t/selenium/controller_reseller.t @@ -19,7 +19,7 @@ my $c = Selenium::Collection::Common->new( driver => $d ); -$d->login_ok(); +$c->login_ok(); my $resellername = ("test" . int(rand(10000))); my $contractid = ("test" . int(rand(10000))); diff --git a/t/selenium/controller_rw_ruleset.t b/t/selenium/controller_rw_ruleset.t index 52d013cba9..f01823dcf9 100644 --- a/t/selenium/controller_rw_ruleset.t +++ b/t/selenium/controller_rw_ruleset.t @@ -19,7 +19,7 @@ my $c = Selenium::Collection::Common->new( driver => $d ); -$d->login_ok(); +$c->login_ok(); my $resellername = ("test" . int(rand(10000))); my $contractid = ("test" . int(rand(10000)));