From 52bf6e4ea9900683c9ef6d7ac80c101151b2f23f Mon Sep 17 00:00:00 2001 From: Nico Schedel Date: Mon, 6 May 2019 09:38:10 +0200 Subject: [PATCH] TT#56376 selenium: add file: controller_admin.t controller_admin.t: - tests if admin is added and checks if said admin can log in. - deletes admin after test Common.pm: - extended login_ok(), it can now use any user or password. If none is specified, it will use the default username/pw: administrator. Change-Id: I89a332176a58fdf6a0ad31495f88633c373a39db --- t/lib/Selenium/Collection/Common.pm | 8 ++- t/selenium/controller_admin.t | 85 +++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 t/selenium/controller_admin.t diff --git a/t/lib/Selenium/Collection/Common.pm b/t/lib/Selenium/Collection/Common.pm index 6b2b1c036d..2a19ade3dc 100644 --- a/t/lib/Selenium/Collection/Common.pm +++ b/t/lib/Selenium/Collection/Common.pm @@ -11,7 +11,9 @@ has 'driver' => ( ); sub login_ok { - my ($self) = @_; + my ($self, $login, $pwd) = @_; + $login = 'administrator' unless $login; + $pwd = 'administrator' unless $pwd; 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 @@ -20,8 +22,8 @@ sub login_ok { 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('#username', 'css')->send_keys($login); + $self->driver->find_element('#password', 'css')->send_keys($pwd); $self->driver->find_element('#submit', 'css')->click(); diag("Checking Admin interface"); diff --git a/t/selenium/controller_admin.t b/t/selenium/controller_admin.t new file mode 100644 index 0000000000..74919bc715 --- /dev/null +++ b/t/selenium/controller_admin.t @@ -0,0 +1,85 @@ +use warnings; +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 + +my $d = Selenium::Remote::Driver::FirefoxExtensions->new( + browser_name => $browsername, + extra_capabilities => { + acceptInsecureCerts => \1, + }, +); + +my $c = Selenium::Collection::Common->new( + driver => $d +); + +my $adminname = ("admin" . int(rand(100000)) . "test"); +my $adminpwd = ("pwd" . int(rand(100000)) . "test"); +my $resellername = ("reseller" . int(rand(100000)) . "test"); +my $contractid = ("contract" . int(rand(100000)) . "test"); + +$c->login_ok(); + +$c->create_reseller_contract($contractid); +$c->create_reseller($resellername, $contractid); + +diag('Go to admin interface'); +$d->find_element('//*[@id="main-nav"]//*[contains(text(),"Settings")]')->click(); +$d->find_element("Administrators", 'link_text')->click(); + +diag('Trying to create a new administrator'); +$d->find_element("Create Administrator", 'link_text')->click(); + +diag('Fill in values'); +$d->fill_element('//*[@id="reselleridtable_filter"]/label/input', 'xpath', 'thisshouldnotexist'); +ok($d->find_element_by_css('#reselleridtable tr > td.dataTables_empty', 'css'), 'Garbage text was not found'); +$d->fill_element('//*[@id="reselleridtable_filter"]/label/input', 'xpath', $resellername); +ok($d->wait_for_text('//*[@id="reselleridtable"]/tbody/tr[1]/td[2]', $resellername), "Reseller found"); +$d->select_if_unselected('//*[@id="reselleridtable"]/tbody/tr[1]/td[5]/input', 'xpath'); +$d->fill_element('//*[@id="login"]', 'xpath', $adminname); +$d->fill_element('//*[@id="password"]', 'xpath', $adminpwd); +$d->find_element('//*[@id="save"]')->click(); + +diag('Search for our new admin'); +$d->fill_element('//*[@id="administrator_table_filter"]/label/input', 'xpath', 'thisshouldnotexist'); +ok($d->find_element_by_css('#administrator_table tr > td.dataTables_empty', 'css'), 'Garbage text was not found'); +$d->fill_element('//*[@id="administrator_table_filter"]/label/input', 'xpath', $adminname); +ok($d->wait_for_text('//*[@id="administrator_table"]/tbody/tr[1]/td[3]', $adminname), "Admin found"); + +diag('New admin tries to login now'); +$c->login_ok($adminname, $adminpwd); + +diag('Go to admin interface'); +$d->find_element('//*[@id="main-nav"]//*[contains(text(),"Settings")]')->click(); +$d->find_element("Administrators", 'link_text')->click(); + +diag('Switch over to default admin'); +$c->login_ok(); + +diag('Go to admin interface'); +$d->find_element('//*[@id="main-nav"]//*[contains(text(),"Settings")]')->click(); +$d->find_element("Administrators", 'link_text')->click(); + +diag('Try to delete Administrator'); +$d->fill_element('//*[@id="administrator_table_filter"]/label/input', 'xpath', 'thisshouldnotexist'); +ok($d->find_element_by_css('#administrator_table tr > td.dataTables_empty', 'css'), 'Garbage text was not found'); +$d->fill_element('//*[@id="administrator_table_filter"]/label/input', 'xpath', $adminname); +ok($d->wait_for_text('//*[@id="administrator_table"]/tbody/tr[1]/td[3]', $adminname), "Admin found"); +$d->move_action(element => $d->find_element('//*[@id="administrator_table"]/tbody/tr[1]/td//a[contains(text(), "Delete")]')); +$d->find_element('//*[@id="administrator_table"]/tbody/tr[1]/td//a[contains(text(), "Delete")]')->click(); +$d->find_element('//*[@id="dataConfirmOK"]')->click(); + +diag('Check if admin is deleted'); +$d->fill_element('//*[@id="administrator_table_filter"]/label/input', 'xpath', $adminname); +ok($d->find_element_by_css('#administrator_table tr > td.dataTables_empty', 'css'), 'Admin was deleted'); + +$c->delete_reseller_contract($contractid); +$c->delete_reseller($resellername); + +done_testing(); \ No newline at end of file