Line 0
Link Here
|
|
|
1 |
use Modern::Perl; |
2 |
|
3 |
use Test::More; |
4 |
use Test::BDD::Cucumber::StepFile; |
5 |
use Selenium::Remote::Driver; |
6 |
use t::lib::Cucumber::Form; |
7 |
use t::lib::Cucumber::Paths; |
8 |
use C4::Context; |
9 |
|
10 |
our $login = 'koha'; |
11 |
our $password = 'koha'; |
12 |
|
13 |
# FIXME The body ids don't depend on the action we are doing (list or add views) |
14 |
#our $body_ids = { |
15 |
# 'new patron category' => 'admin/admin-home.pl', |
16 |
#}; |
17 |
|
18 |
|
19 |
Given qr{I am logged in as a library admin}, sub { |
20 |
my $driver = Selenium::Remote::Driver->new({remote_server_addr => 'localhost'}); |
21 |
my $mainpage = t::lib::Cucumber::Paths::get('mainpage'); |
22 |
$driver->get($mainpage); |
23 |
t::lib::Cucumber::Form::fill( $driver, { userid => $login, password => $password } ); |
24 |
my $login_button = $driver->find_element('//input[@id="submit"]'); |
25 |
$login_button->submit(); |
26 |
S->{driver} = $driver; |
27 |
}; |
28 |
|
29 |
Given qr{I have gone to the (.*) page}, sub { |
30 |
my $page = $1; |
31 |
my $path = t::lib::Cucumber::Paths::get( $page ); |
32 |
S->{driver}->get( $path ); |
33 |
}; |
34 |
|
35 |
When qr(I have clicked on the submit button), sub { |
36 |
my $button; |
37 |
# Try to find submit button |
38 |
eval { |
39 |
$button = S->{driver}->find_element('//fieldset[@class="action"]/input[@type="submit"]'); |
40 |
}; |
41 |
eval { |
42 |
$button = S->{driver}->find_element('//input[@id="submit"]'); |
43 |
} unless $button; |
44 |
eval { |
45 |
$button = S->{driver}->find_element('//input[@type="submit"]'); |
46 |
} unless $button; |
47 |
|
48 |
die "There is no submit button on this page" unless $button; |
49 |
$button->click; |
50 |
}; |
51 |
|
52 |
When qr(I have clicked on the (\S+) (\S+)), sub { |
53 |
my $id = $1; |
54 |
my $type = $2; |
55 |
|
56 |
my $tag; |
57 |
if ( $type eq 'link' ) { |
58 |
$tag = 'a'; |
59 |
} |
60 |
S->{driver}->find_element('//'.$tag.'[@id="'.$id.'"]')->click; |
61 |
}; |
62 |
|
63 |
When qr{I have filled the field (\S+) with "(.*)"}, sub { |
64 |
my ($id, $value) = ($1, $2); |
65 |
t::lib::Cucumber::Form::fill( S->{driver}, { $id => $value } ); |
66 |
}; |
67 |
|
68 |
Then qr{I should see the (.*) page}, sub { |
69 |
my $page = $1; |
70 |
my $title; |
71 |
if ( $page eq "new patron category" ) { |
72 |
$title = 'New category'; |
73 |
} |
74 |
like( S->{driver}->get_title(), qr($title) ); |
75 |
}; |