|
Lines 23-43
Link Here
|
| 23 |
|
23 |
|
| 24 |
use Modern::Perl; |
24 |
use Modern::Perl; |
| 25 |
|
25 |
|
| 26 |
use Time::HiRes qw(gettimeofday); |
|
|
| 27 |
use C4::Context; |
26 |
use C4::Context; |
| 28 |
use C4::Biblio qw( AddBiblio ); # We shouldn't use it |
|
|
| 29 |
|
27 |
|
| 30 |
use Test::More tests => 1; |
28 |
use Test::More tests => 1; |
| 31 |
use MARC::Record; |
29 |
use t::lib::Selenium; |
| 32 |
use MARC::Field; |
|
|
| 33 |
|
| 34 |
my $dbh = C4::Context->dbh; |
30 |
my $dbh = C4::Context->dbh; |
| 35 |
my $login = $ENV{KOHA_USER} || 'koha'; |
|
|
| 36 |
my $password = $ENV{KOHA_PASS} || 'koha'; |
| 37 |
my $staff_client_base_url = |
| 38 |
$ENV{KOHA_INTRANET_URL} || C4::Context->preference("staffClientBaseUrl") || q{}; |
| 39 |
my $base_url= $staff_client_base_url . "/cgi-bin/koha/"; |
| 40 |
my $opac_url = $ENV{KOHA_OPAC_URL} || C4::Context->preference("OPACBaseURL") || q{}; |
| 41 |
|
31 |
|
| 42 |
my $number_of_biblios_to_insert = 3; |
32 |
my $number_of_biblios_to_insert = 3; |
| 43 |
our $sample_data = { |
33 |
our $sample_data = { |
|
Lines 52-145
our $sample_data = {
Link Here
|
| 52 |
my $patronusername="test_username"; |
42 |
my $patronusername="test_username"; |
| 53 |
my $patronpassword="password"; |
43 |
my $patronpassword="password"; |
| 54 |
|
44 |
|
| 55 |
our ( $borrowernumber, $start, $prev_time, $cleanup_needed ); |
45 |
our ( $borrowernumber, $cleanup_needed ); |
| 56 |
|
46 |
|
| 57 |
SKIP: { |
47 |
SKIP: { |
| 58 |
eval { require Selenium::Remote::Driver; }; |
48 |
eval { require Selenium::Remote::Driver; }; |
| 59 |
skip "Selenium::Remote::Driver is needed for selenium tests.", 20 if $@; |
49 |
skip "Selenium::Remote::Driver is needed for selenium tests.", 1 if $@; |
| 60 |
|
50 |
|
| 61 |
$cleanup_needed = 1; |
51 |
$cleanup_needed = 1; |
| 62 |
|
52 |
|
| 63 |
open my $fh, '>>', '/tmp/output.txt'; |
53 |
# Go to the mainpage and log in as default user |
| 64 |
|
54 |
my $s = t::lib::Selenium->new; |
| 65 |
# Go to the mainpage and log in as default user |
55 |
my $driver = $s->driver; |
| 66 |
my $driver = Selenium::Remote::Driver->new; |
56 |
my $base_url = $s->base_url; |
| 67 |
$start = gettimeofday; |
|
|
| 68 |
$prev_time = $start; |
| 69 |
$driver->get($base_url."mainpage.pl"); |
57 |
$driver->get($base_url."mainpage.pl"); |
| 70 |
like( $driver->get_title(), qr(Log in to Koha), ); |
58 |
like( $driver->get_title(), qr(Log in to Koha), ); |
| 71 |
auth( $driver, $login, $password ); |
59 |
$s->auth; |
| 72 |
time_diff("main"); |
60 |
|
| 73 |
|
61 |
# Go to Cataloging page open the cataloging |
| 74 |
# Go to Cataloging page |
62 |
$s->click( { href => '/cataloguing/addbooks.pl', |
| 75 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div[1]/div/div[1]/div[1]/div/ul/li[5]/a')->click; |
63 |
main => 'container-main' } ); |
| 76 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[1]/div[2]/button[1]')->click; |
64 |
$driver->find_element("//*[contains(text(), 'New record')]")->click(); |
| 77 |
$driver->pause(10000); |
65 |
$driver->find_element("//*[contains(text(), 'Default framework')]")->click(); |
| 78 |
|
66 |
|
| 79 |
my $handles = $driver->get_window_handles; |
67 |
# Try to save to trigger generation of some fields like OOO, 003, 005, 008 |
| 80 |
$driver->switch_to_window($handles->[1]); |
68 |
# TODO that might not be how Koha cataloging should be used! That was guesswork! |
| 81 |
warn $driver->get_title(); |
69 |
$s->click( { id => 'saverecord' } ); |
| 82 |
$driver->find_element_by_xpath('/html/body/div/div/form/div/div[1]/fieldset/ol/li[3]/input')->send_keys("The Iliad"); |
70 |
# Accept the modal about the fields not being filled (but now there are autogenerated) |
| 83 |
$driver->find_element_by_xpath('/html/body/div/div/form/div/div[1]/fieldset/ol/li[4]/input')->send_keys("Homer"); |
71 |
$driver->accept_alert; |
| 84 |
warn $driver->get_title(); |
72 |
|
| 85 |
$driver->find_element_by_xpath('/html/body/div/div/form/div/fieldset/input')->click; |
73 |
# Fill Transcribing agency |
| 86 |
$driver->pause(20000); |
74 |
$driver->find_element_by_css("[id*=tag_040_subfield_c]")->send_keys("My transcribing agency"); |
| 87 |
|
75 |
# Fill Title |
| 88 |
# Import the MARC result |
76 |
$s->click( { href => '#tab2XX' } ); |
| 89 |
$driver->find_element_by_xpath('/html/body/div/div/div[1]/table/tbody/tr[1]/td[10]/a')->click; |
77 |
$driver->find_element_by_css("[id*=tag_245_subfield_a]")->send_keys("My title".rand()); |
| 90 |
|
78 |
|
| 91 |
# Add Koha item type |
79 |
## Select Koha item type ## |
| 92 |
$driver->switch_to_window($handles->[0]); |
80 |
$s->click( { href => '#tab9XX' } ); |
| 93 |
$driver->pause(20000); |
81 |
# Open the list of item types |
| 94 |
|
82 |
$driver->find_element_by_css("[aria-labelledby*=tag_942_subfield_c]")->click; |
| 95 |
warn $driver->get_title(); |
83 |
# Select the first item type in the list |
| 96 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div[3]/div[1]/div[3]/div[2]/input')->click; |
84 |
$driver->find_element_by_css("[role=option]:nth-of-type(1)")->click; |
| 97 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div[3]/ul/li[10]/a')->click; |
85 |
|
| 98 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div[3]/div[10]/div[2]/div[3]/div')->click; |
86 |
# Now we can save for real |
| 99 |
$driver->find_element_by_xpath('/html/body/div[6]/ul/li[1]/div')->click; |
87 |
$s->click( { id => 'saverecord' } ); |
| 100 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div[1]/div[1]/button[2]')->click; |
88 |
|
| 101 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/form/div[1]/div[1]/ul/li[2]/a')->click; |
89 |
# Add item |
| 102 |
|
90 |
$s->click( { id => 'addsingle' } ); |
| 103 |
$driver->pause(20000); |
91 |
|
| 104 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div/div/form[2]/button')->click; |
92 |
## Delete item ## |
| 105 |
|
93 |
$driver->find_element_by_css("[id*=itemactions]")->click; |
| 106 |
# Add item |
94 |
$driver->find_element_by_css(".delete")->click; |
| 107 |
warn $driver->get_title(); |
95 |
# Confirm |
| 108 |
$driver->find_element_by_xpath('/html/body/div[4]/div/div/div[2]/div[2]/div/form/fieldset[2]/span[1]/input[1]')->click; |
96 |
$driver->accept_alert; |
| 109 |
if ($driver->find_element('//table[@id="itemst"]') ) { |
97 |
|
| 110 |
time_diff("Item added"); |
98 |
# Go to the record detail page ("Normal tab") |
| 111 |
} else { |
99 |
$driver->find_element("//*[contains(text(), 'Normal')]")->click(); |
| 112 |
time_diff("Item not added"); |
100 |
|
| 113 |
} |
101 |
## Delete the record ## |
| 114 |
|
102 |
$driver->find_element("//*[contains(text(), 'Edit')]")->click(); |
| 115 |
close $fh; |
103 |
$s->click( { id => 'deletebiblio' } ); |
| 116 |
$driver->quit(); |
104 |
# Confirm |
|
|
105 |
$driver->accept_alert; |
| 106 |
# Deletion confirmed by the redirection to the advanced search page |
| 107 |
$driver->find_element_by_css("#advanced-search"); |
| 108 |
|
| 109 |
$driver->quit(); |
| 117 |
}; |
110 |
}; |
| 118 |
|
111 |
|
| 119 |
END { |
112 |
END { |
| 120 |
cleanup() if $cleanup_needed; |
113 |
cleanup() if $cleanup_needed; |
| 121 |
}; |
114 |
}; |
| 122 |
|
115 |
|
| 123 |
sub auth { |
|
|
| 124 |
my ( $driver, $login, $password) = @_; |
| 125 |
fill_form( $driver, { userid => $login, password => $password } ); |
| 126 |
my $login_button = $driver->find_element('//input[@id="submit"]'); |
| 127 |
$login_button->submit(); |
| 128 |
} |
| 129 |
|
| 130 |
sub fill_form { |
| 131 |
my ( $driver, $values ) = @_; |
| 132 |
while ( my ( $id, $value ) = each %$values ) { |
| 133 |
my $element = $driver->find_element('//*[@id="'.$id.'"]'); |
| 134 |
my $tag = $element->get_tag_name(); |
| 135 |
if ( $tag eq 'input' ) { |
| 136 |
$driver->find_element('//input[@id="'.$id.'"]')->send_keys($value); |
| 137 |
} elsif ( $tag eq 'select' ) { |
| 138 |
$driver->find_element('//select[@id="'.$id.'"]/option[@value="'.$value.'"]')->click; |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
sub cleanup { |
116 |
sub cleanup { |
| 144 |
my $dbh = C4::Context->dbh; |
117 |
my $dbh = C4::Context->dbh; |
| 145 |
$dbh->do(q|DELETE FROM categories WHERE categorycode = ?|, {}, $sample_data->{category}{categorycode}); |
118 |
$dbh->do(q|DELETE FROM categories WHERE categorycode = ?|, {}, $sample_data->{category}{categorycode}); |
|
Lines 155-163
sub cleanup {
Link Here
|
| 155 |
}; |
128 |
}; |
| 156 |
} |
129 |
} |
| 157 |
|
130 |
|
| 158 |
sub time_diff { |
|
|
| 159 |
my $lib = shift; |
| 160 |
my $now = gettimeofday; |
| 161 |
warn "CP $lib = " . sprintf("%.2f", $now - $prev_time ) . "\n"; |
| 162 |
$prev_time = $now; |
| 163 |
} |
| 164 |
- |