From 63d32e7dc143fba45da3397b14d891d73efd285f Mon Sep 17 00:00:00 2001 From: Nico Schedel Date: Mon, 8 Apr 2019 10:02:50 +0200 Subject: [PATCH] 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 --- .../Remote/Driver/FirefoxExtensions.pm | 18 ++++++++++++++++++ t/selenium/controller_customer.t | 4 +--- t/selenium/controller_domain.t | 5 +---- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/t/lib/Selenium/Remote/Driver/FirefoxExtensions.pm b/t/lib/Selenium/Remote/Driver/FirefoxExtensions.pm index f0ab9a7e3e..fe85db5d48 100644 --- a/t/lib/Selenium/Remote/Driver/FirefoxExtensions.pm +++ b/t/lib/Selenium/Remote/Driver/FirefoxExtensions.pm @@ -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; diff --git a/t/selenium/controller_customer.t b/t/selenium/controller_customer.t index 4297b11a81..8af2683842 100644 --- a/t/selenium/controller_customer.t +++ b/t/selenium/controller_customer.t @@ -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")]'); diff --git a/t/selenium/controller_domain.t b/t/selenium/controller_domain.t index b22e7abc22..ad0a584618 100644 --- a/t/selenium/controller_domain.t +++ b/t/selenium/controller_domain.t @@ -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");