From 7440730e9a0dce92cc65330f8cbd6e8cf54d5542 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 12 Jan 2024 13:27:50 +0100 Subject: [PATCH] Bug 35329: Add POD + tidy Selenium.pm Signed-off-by: Owen Leonard Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- t/lib/Selenium.pm | 49 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/t/lib/Selenium.pm b/t/lib/Selenium.pm index 8cbd673ddd..3fc65b0c60 100644 --- a/t/lib/Selenium.pm +++ b/t/lib/Selenium.pm @@ -114,17 +114,18 @@ sub opac_auth { sub fill_form { my ( $self, $values ) = @_; while ( my ( $id, $value ) = each %$values ) { - my $attr = 'id'; + my $attr = 'id'; my $attr_value = $id; if ( $id =~ m{=} ) { - ($attr, $attr_value) = split '=', $id; + ( $attr, $attr_value ) = split '=', $id; } - my $element = $self->driver->find_element(sprintf '//*[@%s="%s"]', $attr, $attr_value); - my $tag = $element->get_tag_name(); + my $element = $self->driver->find_element( sprintf '//*[@%s="%s"]', $attr, $attr_value ); + my $tag = $element->get_tag_name(); if ( $tag eq 'input' ) { - $self->driver->find_element(sprintf '//input[@%s="%s"]', $attr, $attr_value)->send_keys($value); + $self->driver->find_element( sprintf '//input[@%s="%s"]', $attr, $attr_value )->send_keys($value); } elsif ( $tag eq 'select' ) { - $self->driver->find_element(sprintf '//select[@%s="%s"]//option[@value="%s"]', $attr, $attr_value, $value)->click; + $self->driver->find_element( sprintf '//select[@%s="%s"]//option[@value="%s"]', $attr, $attr_value, $value ) + ->click; } } } @@ -201,12 +202,12 @@ sub wait_for_element_visible { sub wait_for_element_hidden { my ( $self, $xpath_selector ) = @_; - my ($hidden, $elt); + my ( $hidden, $elt ); $self->remove_error_handler; my $max_retries = $self->max_retries; my $i; while ( not $hidden ) { - $elt = eval {$self->driver->find_element($xpath_selector) }; + $elt = eval { $self->driver->find_element($xpath_selector) }; $hidden = $elt || !$elt->is_displayed; $self->driver->pause(1000) unless $hidden; @@ -351,13 +352,43 @@ when we use automation test using Selenium =head2 click - $s->click + $s->click($xpath_selector); This is a bit dirty for now but will evolve depending on the needs 3 parameters possible but only the following 2 forms are used: $s->click({ href => '/module/script.pl?foo=bar', main => 'doc3' }); # Sometimes we have doc or doc3. To make sure we are not going to hit a link in the header $s->click({ id => 'element_id }); +=head2 wait_for_element_visible + + $s->wait_for_element_visible($xpath_selector) + + Wait 10s for an element to be visible + +=head2 wait_for_element_hidden + + $s->wait_for_element_hidden($xpath_selector) + + Wait 10s for an element to be hidden + +=head2 wait_for_ajax + + $s->wait_for_ajax; + + Wait 10s for all the current AJAX requests to be received. + +=head2 get_next_alert_text + + $s->get_next_alert_text; + + Retrieve the next alert text. + +=head2 show_all_entries + + $s->show_all_entries($xpath_selector); + + Select the "All" entries of the DataTables present in the selector. + =head2 click_when_visible $c->click_when_visible -- 2.39.5