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");