View | Details | Raw Unified | Return to bug 35506
Collapse All | Expand All

(-)a/t/db_dependent/selenium/regressions.t (-1 / +12 lines)
Lines 189-194 subtest 'Display circulation table correctly' => sub { Link Here
189
    # Display the table clicking on the "Show checkouts" button
189
    # Display the table clicking on the "Show checkouts" button
190
    $driver->find_element('//a[@id="issues-table-load-now-button"]')->click;
190
    $driver->find_element('//a[@id="issues-table-load-now-button"]')->click;
191
191
192
    # Wait for the checkouts table to load
193
    $s->wait_for_ajax;
194
192
    my @thead_th = $driver->find_elements('//table[@id="issues-table"]/thead/tr/th');
195
    my @thead_th = $driver->find_elements('//table[@id="issues-table"]/thead/tr/th');
193
    my $thead_length = 0;
196
    my $thead_length = 0;
194
    $thead_length += $_->get_attribute('colspan', 1) || 0 for @thead_th;
197
    $thead_length += $_->get_attribute('colspan', 1) || 0 for @thead_th;
Lines 313-326 subtest 'Encoding in session variables' => sub { Link Here
313
            $driver->find_element('//input[@id="barcode"]')->send_keys( $item->barcode );
316
            $driver->find_element('//input[@id="barcode"]')->send_keys( $item->barcode );
314
            $driver->find_element('//fieldset[@id="circ_circulation_issue"]/button[@type="submit"]')->click;
317
            $driver->find_element('//fieldset[@id="circ_circulation_issue"]/button[@type="submit"]')->click;
315
318
319
            # For some crazy reason it's not reliable to wait for the page to
320
            # refresh. It can get stuck (seen in failure screenshot). Even if
321
            # the logs show that a page was returned to the browser. The
322
            # checkout is made so going directly again to the page works.
323
            $driver->get( $base_url . "/circ/circulation.pl?borrowernumber=" . $patron->borrowernumber );
324
316
            # Display the table clicking on the "Show checkouts" button
325
            # Display the table clicking on the "Show checkouts" button
317
            $driver->find_element('//a[@id="issues-table-load-now-button"]')
326
            $driver->find_element('//a[@id="issues-table-load-now-button"]')
318
              ->click;
327
              ->click;
328
            # Wait for the checkouts table to load
329
            $s->wait_for_ajax;
319
330
320
            my @tds = $driver->find_elements(
331
            my @tds = $driver->find_elements(
321
                '//table[@id="issues-table"]/tbody/tr[2]/td');
332
                '//table[@id="issues-table"]/tbody/tr[2]/td');
322
333
323
            # Select the td for "Checked out from" (FIXME this is not robust and could be improved
334
            # Select the td for "Checked out from"
324
            my $td_checked_out_from = $tds[8];
335
            my $td_checked_out_from = $tds[8];
325
            is(
336
            is(
326
                $td_checked_out_from->get_text(),
337
                $td_checked_out_from->get_text(),
(-)a/t/lib/Selenium.pm (-11 / +25 lines)
Lines 56-67 sub add_error_handler { Link Here
56
    $self->{driver}->error_handler(
56
    $self->{driver}->error_handler(
57
        sub {
57
        sub {
58
            my ( $driver, $selenium_error ) = @_;
58
            my ( $driver, $selenium_error ) = @_;
59
            print STDERR "\nSTRACE:";
59
            $self->_print_stack_trace;
60
            my $i = 1;
61
            while ( (my @call_details = (caller($i++))) ){
62
                print STDERR "\t" . $call_details[1]. ":" . $call_details[2] . " in " . $call_details[3]."\n";
63
            }
64
            print STDERR "\n";
65
            $self->capture( $driver );
60
            $self->capture( $driver );
66
            $driver->quit();
61
            $driver->quit();
67
            croak $selenium_error;
62
            croak $selenium_error;
Lines 194-210 sub wait_for_element_visible { Link Here
194
}
189
}
195
190
196
sub wait_for_ajax {
191
sub wait_for_ajax {
197
    my ( $self ) = @_;
192
    my ( $self, $max_retries ) = @_;
198
193
199
    my $is_ready;
194
    my $is_ready;
200
    my $max_retries = $self->max_retries;
195
    $max_retries ||= $self->max_retries;
201
    my $i;
196
    my $i;
197
    $is_ready = $self->driver->execute_script('return jQuery.active == 0');
202
    while ( not $is_ready ) {
198
    while ( not $is_ready ) {
203
        $is_ready = $self->driver->execute_script('return jQuery.active == 0');
199
        $is_ready = $self->driver->execute_script('return jQuery.active == 0');
204
        $self->driver->pause(1000) unless $is_ready;
200
        $self->driver->pause(1000) unless $is_ready;
205
201
206
        die "Cannot wait more for jQuery to be active (wait_for_ajax)"
202
        if ( $max_retries <= ++$i ) {
207
            if $max_retries <= ++$i
203
            $self->capture( $self->driver );
204
            $self->_print_stack_trace;
205
            $self->driver->quit();
206
            die "Cannot wait more for jQuery to be active (wait_for_ajax)";
207
        }
208
    }
208
    }
209
}
209
}
210
210
Lines 267-272 sub click_when_visible { Link Here
267
267
268
sub max_retries { 10 }
268
sub max_retries { 10 }
269
269
270
sub _print_stack_trace {
271
    print STDERR "\nSTRACE:";
272
    my $i = 1;
273
    while ( ( my @call_details = ( caller( $i++ ) ) ) ) {
274
        print STDERR "\t" . $call_details[1] . ":" . $call_details[2] . " in " . $call_details[3] . "\n";
275
    }
276
    print STDERR "\n";
277
}
278
279
270
=head1 NAME
280
=head1 NAME
271
281
272
t::lib::Selenium - Selenium helper module
282
t::lib::Selenium - Selenium helper module
Lines 358-363 It will remove any kinds of error raised by the driver. Link Here
358
It can be useful in some cases, for instance if you want to make sure something will not happen and that could make the driver exploses otherwise.
368
It can be useful in some cases, for instance if you want to make sure something will not happen and that could make the driver exploses otherwise.
359
You certainly should call it for only one statement then must call add_error_handler right after.
369
You certainly should call it for only one statement then must call add_error_handler right after.
360
370
371
=head2 wait_for_ajax
372
373
    Wait until all XHR requests are finished. Timeouts after
374
    $self->max_retries attempts. (ajustable by optional argument)
375
361
=head1 AUTHORS
376
=head1 AUTHORS
362
377
363
Jonathan Druart <jonathan.druart@bugs.koha-community.org>
378
Jonathan Druart <jonathan.druart@bugs.koha-community.org>
364
- 

Return to bug 35506