TT#56376 selenium: add wait_for_text() method

Added wait_for_text() to wait until a text appears.
Can also be used to check if text is here.
It will return true or false to be used in further testing

Change-Id: Ib28636b7757a5312652da86d3b43b9fd8547522b
changes/42/28842/7
Nico Schedel 6 years ago
parent 61a9c10a36
commit 63d32e7dc1

@ -114,4 +114,22 @@ sub browser_name_in {
return scalar grep {/^$browser_name$/} @names;
}
sub wait_for_text {
my ($self, $xpath, $expected, $timeout) = @_;
return unless $xpath && $expected;
$timeout = 5 unless $timeout; # seconds. Default timeout value if none is specified.
my $started = time();
my $elapsed = time();
try{
while ($elapsed - $started <= $timeout){
$elapsed = time();
return 1 if $self->find_element($xpath)->get_text() eq $expected;
}
}
catch{
return;
};
return;
}
1;

@ -108,9 +108,7 @@ $d->find_element('//*[@id="save"]')->click();
diag("Trying to find subscriber");
$d->find_element('//*[@id="subscribers_table_filter"]/label/input')->send_keys($username);
sleep(1) until $d->find_element('//*[@id="subscribers_table"]/tbody/tr/td[2]')->get_text() ~~ $username;
my $userfromtable = $d->get_text('//*[@id="subscribers_table"]/tbody/tr/td[2]');
is($userfromtable, $username, "Subscriber was found");
ok($d->wait_for_text('//*[@id="subscribers_table"]/tbody/tr/td[2]', $username), 'Subscriber was found');
diag("Edit Fraud Limits");
my $elem = $d->find_element('//div[contains(@class,"accordion-heading")]//a[contains(text(),"Fraud Limits")]');

@ -38,11 +38,8 @@ $d->find_element('//*[@id="Domain_table"]/tbody/tr/td'); #trying to trick ajax
diag("Check if entry exists and if the search works");
$d->find_element('//*[@id="Domain_table_filter"]/label/input')->clear();
$d->find_element('//*[@id="Domain_table_filter"]/label/input')->send_keys($domainstring); #actual value
sleep(1) until $d->find_element('//*[@id="Domain_table"]/tbody/tr/td[3]')->get_text() ~~ $domainstring; #waiting because ajax
ok($d->wait_for_text('//*[@id="Domain_table"]/tbody/tr/td[3]', $domainstring), 'Entry was found');
diag('Searching for element');
my $domainfromtable = $d->get_text('//*[@id="Domain_table"]/tbody/tr/td[3]');
is($domainfromtable, $domainstring, "Entry was found");
sleep 1; # prevent stale element exception
diag("Open Preferences of first Domain");

Loading…
Cancel
Save