TT#56376 selenium: fix crash on find_text()

Adding try/catch to find_text() to prevent it from crashing if
nothing is found.

Change-Id: I9bdfae408e41d51db27c1abdd81fd1f3c16bc2f3
changes/11/28811/7
Nico Schedel 7 years ago
parent 32e646eff9
commit c70b063cfe

@ -2,7 +2,7 @@ package Selenium::Remote::Driver::FirefoxExtensions;
use warnings;
use strict;
use TryCatch;
use Moo;
use Test::More import => [qw(diag ok is)];
@ -54,9 +54,15 @@ sub login_ok {
}
sub find_text {
my ($self, $text, $scheme) = @_;
$scheme //= "xpath";
return $self->find_element("//*[contains(text(),\"$text\")]", $scheme);
try {
my ($self, $text, $scheme) = @_;
$scheme //= "xpath";
return $self->find_element("//*[contains(text(),\"$text\")]", $scheme);
}
catch {
return;
};
}
sub select_if_unselected {

@ -93,10 +93,10 @@ ok($row, "Find row");
$d->move_action(element => $row);
ok(1, "Mouse over row");
$d->find_element('//div[contains(@class,"dataTables_wrapper")]//td[contains(text(),"testingdetail")]/..//a[contains(@class,"btn-secondary") and contains(text(),"Delete")]')->click();
ok($d->find_text("Are you sure?"));
ok($d->find_text("Are you sure?"), 'Delete dialog appears');
$d->find_element('#dataConfirmOK', 'css')->click();
diag('skip was here');
ok($d->find_text("successfully deleted"));
ok($d->find_text("successfully deleted"), 'Text "successfully deleted" appears');
diag("Click Edit Zones");
$d->find_element("Edit Zones", 'link_text')->click();
@ -110,7 +110,7 @@ $row = $d->find_element('//div[contains(@class,"dataTables_wrapper")]//td[contai
ok($row);
$d->move_action(element => $row);
$d->find_element('//div[contains(@class,"dataTables_wrapper")]//td[contains(text(),"testingzone")]/..//a[contains(text(),"Delete")]')->click();
$d->find_text("Are you sure?");
ok($d->find_text("Are you sure?"), 'Delete dialog appears');
$d->find_element('#dataConfirmOK', 'css')->click();
diag("Go to Billing page (again)");
@ -148,7 +148,7 @@ sleep 1; # give ajax time to load
my $btn = $d->find_element('//table//td[contains(text(),"Wednesday")]/..//a[text()[contains(.,"Edit")]]');
ok($btn);
$btn->click();
$d->find_text("Edit Wednesday");
ok($d->find_text("Edit Wednesday"), 'Edit Wednesday button exists');
diag("Pop-up 'Edit Wednesday' was properly opened");
diag("add/delete a time def to Wednesday");
@ -177,7 +177,7 @@ my $delete_button = $d->find_child_element($row, './/a[contains(@class,"btn-seco
ok($delete_button);
sleep 2 if ($browsername eq "htmlunit");
$delete_button->click();
$d->find_text("Are you sure?");
ok($d->find_text("Are you sure?"), 'Delete dialog appears');
$d->find_element('#dataConfirmOK', 'css')->click();
done_testing;

@ -141,9 +141,9 @@ $edit_link = $d->find_child_element($row, '(./td//a)[contains(text(),"Terminate"
ok($edit_link, 'Found terminate button');
$d->move_action(element => $row);
$edit_link->click();
$d->find_text("Are you sure?");
ok($d->find_text("Are you sure?"), 'Delete dialog appears');
$d->find_element('#dataConfirmOK', 'css')->click();
$d->find_text("Customer successfully terminated");
ok($d->find_text("Customer successfully terminated"), 'Text "Customer successfully terminated" appears');
done_testing;
# vim: filetype=perl

@ -74,10 +74,11 @@ $formfield->send_keys('thisisnonumber');
$d->find_element("#save", 'css')->click();
diag('Type 789 and click Save');
$d->find_text('Value must be an integer');
ok($d->find_text('Value must be an integer'), "Wrong value detected");
$formfield = $d->find_element('#concurrent_max', 'css');
ok($formfield);
$formfield->clear();
diag('Saving integer value into "concurrent_max"');
$formfield->send_keys('789');
$d->find_element('#save', 'css')->click();
done_testing();

@ -33,7 +33,7 @@ $d->scroll_to_element($elem);
$d->select_if_unselected('//table[@id="billing_profileidtable"]/tbody/tr[1]//input[@type="checkbox"]');
$d->find_element('//div[contains(@class,"modal-body")]//div//select[@id="status"]/option[@value="active"]')->click();
$d->find_element('//div[contains(@class,"modal")]//input[@type="submit"]')->click();
$d->find_text('Create Peering Group'); # Should go back to prev form
ok($d->find_text('Create Peering Group'), 'Succesfully went back to previous form'); # Should go back to prev form
$d->fill_element('#name', 'css', 'testinggroup');
$d->fill_element('#description', 'css', 'A group created for testing purposes');
@ -63,8 +63,7 @@ $d->fill_element('#name', 'css', 'mytestserver');
$d->fill_element('#ip', 'css', '10.0.0.100');
$d->fill_element('#host', 'css', 'sipwise.com');
$d->find_element('#save', 'css')->click();
$d->find_text('Peering server successfully created');
ok($d->find_text('Peering server successfully created'), 'Text "Peering server successfully created" appears');
my $server_rules_uri = $d->get_current_url();
diag('Edit Preferences for "mytestserver".');
@ -93,7 +92,7 @@ $edit_link->click();
diag('Change to "P-Asserted-Identity');
$d->find_element('//div[contains(@class,"modal-body")]//select[@id="inbound_upn"]/option[@value="pai_user"]')->click();
$d->find_element('#save', 'css')->click();
$d->find_text('Preference inbound_upn successfully updated');
ok($d->find_text('Preference inbound_upn successfully updated'), 'Text "Preference inbound_upn successfully updated" appears');
diag("Go back to Servers/Rules");
$d->get($server_rules_uri);
@ -111,9 +110,9 @@ $delete_link = $d->find_child_element($row, '(./td//a)[contains(text(),"Delete")
ok($delete_link);
$d->move_action(element => $row);
$delete_link->click();
$d->find_text("Are you sure?");
ok($d->find_text("Are you sure?"), 'Delete dialog appears');
$d->find_element('#dataConfirmOK', 'css')->click();
$d->find_text("successfully deleted"); # delete does not work
ok($d->find_text("successfully deleted"), 'Text "successfully deleted" appears');
diag("Delete the previously created Peering Rule");
diag(" - searching garbage (waiting for AJAX to load)");
@ -130,11 +129,11 @@ $delete_link = $d->find_child_element($row, '(./td//a)[contains(text(),"Delete")
ok($delete_link);
$d->move_action(element => $row);
$delete_link->click();
$d->find_text("Are you sure?");
ok($d->find_text("Are you sure?"), 'Delete dialog appears');
$d->find_element('#dataConfirmOK', 'css')->click();
diag('skip was here');
ok($d->find_text("successfully deleted"));
ok($d->find_text("successfully deleted"), 'Text "successfully deleted" appears');
diag('Go back to "SIP Peering Groups".');
$d->get($peerings_uri);
@ -146,11 +145,11 @@ $delete_link = $d->find_child_element($row, '(./td//a)[contains(text(),"Delete")
ok($delete_link);
$d->move_action(element => $row);
$delete_link->click();
$d->find_text("Are you sure?");
ok($d->find_text("Are you sure?"), 'Delete dialog appears');
$d->find_element('#dataConfirmOK', 'css')->click();
diag('skip was here');
ok($d->find_text("successfully deleted"));
ok($d->find_text("successfully deleted"), 'Text "successfully deleted" appears');
done_testing;
# vim: filetype=perl

@ -38,8 +38,8 @@ is($d->find_element('//table[@id="Resellers_table"]//tr[1]/td[1]')->get_text(),
diag("Going to create a reseller");
$d->find_element('Create Reseller', 'link_text')->click();
$d->find_element('#save', 'css')->click();
$d->find_text("Contract field is required");
$d->find_text("Name field is required");
ok($d->find_text("Contract field is required"), 'Error "Contract field is required" appears');
ok($d->find_text("Name field is required"), 'Error "Name field is required" appears');
$d->find_element('#mod_close', 'css')->click();
diag("Click Edit on the first reseller shown (first row)");
@ -61,7 +61,7 @@ $d->move_action(element => $row,xoffset=>1); # 1 because if the mouse doesn't mo
$btn = $d->find_child_element($row, './/a[contains(@class,"btn-secondary")]');
ok($btn);
$btn->click();
$d->find_text("Are you sure?");
ok($d->find_text("Are you sure?"), 'Delete dialog appears');
$d->find_element('//div[@id="dataConfirmModal"]//button[contains(text(),"Cancel")]')->click();
done_testing;

Loading…
Cancel
Save