From 417096677129f65132fbf6fed1525d9e0e156cee Mon Sep 17 00:00:00 2001 From: Gerhard Jungwirth Date: Mon, 21 Oct 2013 21:14:54 +0200 Subject: [PATCH] MT#3435 fix tests all selenium tests are working locally with selenium 2.31.0 and phantomjs 1.9.1 and an empty db-schema dump particular fixes: - skip some tests, when no domain is yet created - select_if_unselected to prevent unselecting preselected checkboxes - increase some waiting times to fix races with ajax calls --- t/controller_billing_selenium.t | 7 ++-- t/controller_domain_selenium.t | 71 ++++++++++++++++++--------------- t/controller_peering_selenium.t | 8 ++-- t/lib/Test/WebDriver/Sipwise.pm | 16 ++++++++ 4 files changed, 64 insertions(+), 38 deletions(-) diff --git a/t/controller_billing_selenium.t b/t/controller_billing_selenium.t index af3ec85278..6e129edafa 100644 --- a/t/controller_billing_selenium.t +++ b/t/controller_billing_selenium.t @@ -10,7 +10,7 @@ $d->set_window_size(800,1280) if ($browsername ne "htmlunit"); my $uri = $ENV{CATALYST_SERVER} || 'http://localhost:3000'; $d->get_ok("$uri/logout"); #make sure we are logged out $d->get_ok("$uri/login"); -$d->set_implicit_wait_timeout(1000); +$d->set_implicit_wait_timeout(2500); diag("Do Admin Login"); $d->find(link_text => 'Admin')->click; @@ -70,7 +70,8 @@ $d->fill_element_ok([name => 'zone', 'testingzone']); $d->fill_element_ok([name => 'detail', 'testingdetail']); $d->findclick_ok(name => 'save'); diag("Back to orignial form (create billing fees)"); -$d->findclick_ok(xpath => '//div[contains(@class,"modal")]//div[contains(@class,"dataTables_wrapper")]//td[contains(text(),"testingzone")]/..//input[@type="checkbox"]'); +#sleep 2; # give ajax time to load +$d->select_if_unselected_ok(xpath => '//div[contains(@class,"modal")]//div[contains(@class,"dataTables_wrapper")]//td[contains(text(),"testingzone")]/..//input[@type="checkbox"]'); $d->fill_element_ok([id => 'source', '.*']); $d->fill_element_ok([name => 'destination', '.+']); $d->findclick_ok(id => 'save'); @@ -116,7 +117,7 @@ diag("Edit Wednesday"); $row = $d->find(xpath => '//table//td[contains(text(),"Wednesday")]'); ok($row); $d->move_to(element => ($d->find(xpath => '//h3[contains(text(),"Weekdays")]'))); -sleep 2 if ($browsername eq "htmlunit"); +sleep 2 if ($d->browser_name_in("firefox", "htmlunit")); $d->move_to(element => $row); $d->findclick_ok(xpath => '//table//td[contains(text(),"Wednesday")]/..//a[text()[contains(.,"Edit")]]'); $d->findtext_ok("Edit Wednesday"); diff --git a/t/controller_domain_selenium.t b/t/controller_domain_selenium.t index f8c0989626..afdec0d96e 100644 --- a/t/controller_domain_selenium.t +++ b/t/controller_domain_selenium.t @@ -1,6 +1,6 @@ use Sipwise::Base; use lib 't/lib'; -use Test::More import => [qw(done_testing is ok diag)]; +use Test::More import => [qw(done_testing is ok diag skip)]; use Test::WebDriver::Sipwise qw(); my $browsername = $ENV{BROWSER_NAME} || ""; #possible values: htmlunit, chrome @@ -26,42 +26,49 @@ $d->findclick_ok(xpath => '//*[@id="main-nav"]//*[contains(text(),"Settings")]') $d->find_ok(xpath => '//a[contains(@href,"/domain")]'); $d->findclick_ok(link_text => "Domains"); -diag("Open Preferences of first Domain"); $d->title_is("Domains"); -sleep 1; -my $row = $d->find(xpath => '//table[@id="Domain_table"]/tbody/tr[1]'); -ok($row); -my $edit_link = $d->find_child_element($row, '(./td//a)[contains(text(),"Preferences")]'); -ok($edit_link); -$d->move_to(element => $row); -$edit_link->click; +SKIP: { + sleep 1; + diag("Open Preferences of first Domain"); + my ($row, $edit_link); + try { + $row = $d->find(xpath => '//table[@id="Domain_table"]/tbody/tr[1]'); + $edit_link = $d->find('(//table[@id="Domain_table"]/tbody/tr[1]/td//a)[contains(text(),"Preferences")]'); + } catch { + skip ("It seems, no domains exist", 1); + } -diag('Open the tab "Access Restrictions"'); -$d->location_like(qr!domain/\d+/preferences!); #/ -$d->findclick_ok(link_text => "Access Restrictions"); + ok($edit_link); + $d->move_to(element => $row); + $edit_link->click; -diag("Click edit for the preference concurrent_max"); -$row = $d->find(xpath => '//table/tbody/tr/td[normalize-space(text()) = "concurrent_max"]'); -ok($row); -$edit_link = $d->find_child_element($row, '(./../td//a)[2]'); -ok($edit_link); -$d->move_to(element => $row); -$edit_link->click; + diag('Open the tab "Access Restrictions"'); + $d->location_like(qr!domain/\d+/preferences!); #/ + $d->findclick_ok(link_text => "Access Restrictions"); -diag("Try to change this to a value which is not a number"); -my $formfield = $d->find('id' => 'concurrent_max'); -ok($formfield); -$formfield->clear; -$formfield->send_keys('thisisnonumber'); -$d->findclick_ok(id => 'save'); + diag("Click edit for the preference concurrent_max"); + $row = $d->find(xpath => '//table/tbody/tr/td[normalize-space(text()) = "concurrent_max"]'); + ok($row); + $edit_link = $d->find_child_element($row, '(./../td//a)[2]'); + ok($edit_link); + $d->move_to(element => $row); + $edit_link->click; -diag('Type 789 and click Save'); -$d->findtext_ok('Value must be an integer'); -$formfield = $d->find('id' => 'concurrent_max'); -ok($formfield); -$formfield->clear; -$formfield->send_keys('789'); -$d->findclick_ok(id => 'save'); + diag("Try to change this to a value which is not a number"); + my $formfield = $d->find('id' => 'concurrent_max'); + ok($formfield); + $formfield->clear; + $formfield->send_keys('thisisnonumber'); + $d->findclick_ok(id => 'save'); + + diag('Type 789 and click Save'); + $d->findtext_ok('Value must be an integer'); + $formfield = $d->find('id' => 'concurrent_max'); + ok($formfield); + $formfield->clear; + $formfield->send_keys('789'); + $d->findclick_ok(id => 'save'); +} done_testing; # vim: filetype=perl diff --git a/t/controller_peering_selenium.t b/t/controller_peering_selenium.t index 873f56f41f..1d2a3a1f5f 100644 --- a/t/controller_peering_selenium.t +++ b/t/controller_peering_selenium.t @@ -32,15 +32,15 @@ $d->findclick_ok(link_text => 'Create Peering Group'); diag("Create a Peering Contract"); $d->findclick_ok(xpath => '//input[@type="button" and @value="Create Contract"]'); -$d->findclick_ok(xpath => '//table[@id="contactidtable"]/tbody/tr[1]//input[@type="checkbox"]'); -$d->findclick_ok(xpath => '//table[@id="billing_profileidtable"]/tbody/tr[1]//input[@type="checkbox"]'); +$d->select_if_unselected_ok(xpath => '//table[@id="contactidtable"]/tbody/tr[1]//input[@type="checkbox"]'); +$d->select_if_unselected_ok(xpath => '//table[@id="billing_profileidtable"]/tbody/tr[1]//input[@type="checkbox"]'); $d->findclick_ok(xpath => '//div[contains(@class,"modal-body")]//div//select[@id="status"]/option[@value="active"]'); $d->findclick_ok(xpath => '//div[contains(@class,"modal")]//input[@type="submit"]'); $d->findtext_ok('Create Peering Group'); #Should go back to prev form $d->fill_element_ok([id => 'name', 'testinggroup']); $d->fill_element_ok([id => 'description', 'A group created for testing purposes']); -$d->findclick_ok(xpath => '//table[@id="contractidtable"]/tbody/tr[1]//input[@type="checkbox"]'); +$d->select_if_unselected(xpath => '//table[@id="contractidtable"]/tbody/tr[1]//input[@type="checkbox"]'); $d->findclick_ok(id => 'save'); diag("Edit Servers/Rules of testinggroup"); @@ -70,6 +70,7 @@ $d->findtext_ok('Peering server successfully created'); my $server_rules_uri = $d->get_location; diag('Edit Preferences for "mytestserver".'); +sleep 1; #make sure, we are on the right page $row = $d->find(xpath => '(//table/tbody/tr/td[contains(text(), "mytestserver")]/..)[1]'); ok($row); $edit_link = $d->find_child_element($row, '(./td//a)[contains(text(),"Preferences")]'); @@ -97,6 +98,7 @@ diag("Go back to Servers/Rules"); $d->navigate_ok($server_rules_uri); diag("Delete mytestserver"); +sleep 1; #make sure, we are on the right page $row = $d->find(xpath => '(//table/tbody/tr/td[contains(text(), "mytestserver")]/..)[1]'); ok($row); my $delete_link = $d->find_child_element($row, '(./td//a)[contains(text(),"Delete")]'); diff --git a/t/lib/Test/WebDriver/Sipwise.pm b/t/lib/Test/WebDriver/Sipwise.pm index f6e6e43acd..7bf0bf362c 100644 --- a/t/lib/Test/WebDriver/Sipwise.pm +++ b/t/lib/Test/WebDriver/Sipwise.pm @@ -14,6 +14,16 @@ method findclick(Str $scheme, Str $query) { return 1; } +method select_if_unselected(Str $scheme, Str $query) { + my $elem = $self->find($scheme, $query); + return 0 unless $elem; + return 0 unless $elem->is_displayed; + if (! $elem->is_selected() ) { + $elem->click; + } + return 1; +} + method findtext(Str $text, Any $ignore) { return $self->find(xpath => "//*[contains(text(),\"$text\")]"); } @@ -37,3 +47,9 @@ method fill_element(ArrayRef $options, Any $ignore) { $elem->send_keys($filltext); return 1; } + +sub browser_name_in { + my ($self, @names) = @_; + my $browser_name = $self->get_capabilities->{browserName}; + return $browser_name ~~ @names; +}