From 9f84773890bed4b0c6b9826e3b286b35dcf67fbc Mon Sep 17 00:00:00 2001 From: Julian FIOL Date: Mon, 1 Jun 2015 15:19:34 +0200 Subject: [PATCH] Bug 13849 : Adding Cucumber tests to create a new biblio To test: 0/ * Install the selenium server (have a look at bug 13691) * Install libtest-bdd-cucumber-perl (pkg) and App::pherkin (cpan) * Edit t/db_dependent/cucumber/features/step_definitions/basic_steps.pl and fill the login and password of a superlibrarian user. Maybe you should also change the address of the selenium server (search for 'remote_server_addr'). 1/ Start the selenium server and launch the tests: $ cd t/db_dependent/cucumber $ pherkin or $ prove tests.t This patch add a new scenario creating a new biblio --- t/db_dependent/cucumber/features/2-biblio.feature | 18 ++++++++++++++++++ .../features/step_definitions/2-biblio_steps.pl | 13 +++++++++++++ .../cucumber/features/step_definitions/basic_steps.pl | 13 ++++++++++++- .../cucumber/features/step_definitions/hooks_steps.pl | 1 + t/lib/Cucumber/Paths.pm | 9 +++++---- 5 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 t/db_dependent/cucumber/features/2-biblio.feature create mode 100644 t/db_dependent/cucumber/features/step_definitions/2-biblio_steps.pl diff --git a/t/db_dependent/cucumber/features/2-biblio.feature b/t/db_dependent/cucumber/features/2-biblio.feature new file mode 100644 index 0000000..cc35d9a --- /dev/null +++ b/t/db_dependent/cucumber/features/2-biblio.feature @@ -0,0 +1,18 @@ +Feature: Add a biblio + As a librarian + I want to add a new biblio + + Background: + Given I am logged in as a library admin + + Scenario: Add a biblio + Given I have gone to the new biblio page + When I have clicked on the ui-id-1 link + And I have filled the input field starting by tag_200_subfield_a_ with "MyBookName" + And I have filled the select field starting by tag_200_subfield_b_ with "LIVR" + And I have filled the input field starting by tag_200_subfield_f_ with "MyAuthor" + And I have filled the input field starting by tag_100_subfield_a_ with "20150601d u||y0frey50 ba" + When I have clicked on the ui-id-2 link + And I have filled the select field starting by tag_101_subfield_a_ with "fre" + When I have clicked on the saverecord button + Then The biblio "MyBookName" should have been created diff --git a/t/db_dependent/cucumber/features/step_definitions/2-biblio_steps.pl b/t/db_dependent/cucumber/features/step_definitions/2-biblio_steps.pl new file mode 100644 index 0000000..81ed561 --- /dev/null +++ b/t/db_dependent/cucumber/features/step_definitions/2-biblio_steps.pl @@ -0,0 +1,13 @@ +use Modern::Perl; + +use Test::More; +use Test::BDD::Cucumber::StepFile; +use C4::Context; + +Then qr(The biblio "(.*)" should have been created), sub { + S->{title} = $1; + my $dbh = C4::Context->dbh; + my $exists = $dbh->selectcol_arrayref(q| + SELECT COUNT(*) FROM biblio where title = ?|, {}, S->{title} ); + is( $exists->[0], 1, 'The biblio '.S->{title}.' should exist' ); +}; \ No newline at end of file diff --git a/t/db_dependent/cucumber/features/step_definitions/basic_steps.pl b/t/db_dependent/cucumber/features/step_definitions/basic_steps.pl index d23245b..318ee67 100644 --- a/t/db_dependent/cucumber/features/step_definitions/basic_steps.pl +++ b/t/db_dependent/cucumber/features/step_definitions/basic_steps.pl @@ -32,6 +32,14 @@ Given qr{I have gone to the (.*) page}, sub { S->{driver}->get( $path ); }; +When qr(I have filled the (.*) field starting by (.*) with "(.*)"), sub { + my $type = $1; + my $id = $2; + my $value = $3; + my $id_full = S->{driver}->find_element('//'.$type.'[contains(@id,"'.$id.'")]')->get_attribute('id'); + t::lib::Cucumber::Form::fill( S->{driver}, { $id_full => $value } ); +}; + When qr(I have clicked on the submit button), sub { my $button; # Try to find submit button @@ -56,8 +64,11 @@ When qr(I have clicked on the (\S+) (\S+)), sub { my $tag; if ( $type eq 'link' ) { $tag = 'a'; + S->{driver}->find_element('//'.$tag.'[@id="'.$id.'"]')->click; + } + else { + S->{driver}->find_element('//'.$type.'[@id="'.$id.'"]')->click; } - S->{driver}->find_element('//'.$tag.'[@id="'.$id.'"]')->click; }; When qr{I have filled the field (\S+) with "(.*)"}, sub { diff --git a/t/db_dependent/cucumber/features/step_definitions/hooks_steps.pl b/t/db_dependent/cucumber/features/step_definitions/hooks_steps.pl index a5bb0ee..6ab134b 100644 --- a/t/db_dependent/cucumber/features/step_definitions/hooks_steps.pl +++ b/t/db_dependent/cucumber/features/step_definitions/hooks_steps.pl @@ -2,4 +2,5 @@ After sub { my $dbh = C4::Context->dbh; $dbh->do(q|DELETE FROM categories WHERE categorycode = ?|, {}, S->{patron_category_code}); $dbh->do(q|DELETE FROM borrowers WHERE userid=?|, {}, S->{patron_userid}); + $dbh->do(q|DELETE FROM biblio WHERE title=?|, {}, S->{title}); }; diff --git a/t/lib/Cucumber/Paths.pm b/t/lib/Cucumber/Paths.pm index 91c64ab..b2132c4 100644 --- a/t/lib/Cucumber/Paths.pm +++ b/t/lib/Cucumber/Paths.pm @@ -6,11 +6,12 @@ sub get { my ( $page ) = @_; my $base_url = 'http://'.C4::Context->preference("staffClientBaseURL")."/cgi-bin/koha/"; my $paths = { - 'mainpage' => $base_url.'mainpage.pl?logout.x=1', + 'mainpage' => $base_url.'mainpage.pl?logout.x=1', 'patron category list' => $base_url.'admin/categorie.pl', - 'new patron category' => $base_url.'admin/categorie.pl?op=add_form', - 'patron home' => $base_url.'members/members-home.pl', - 'new patron' => $base_url.'members/memberentry.pl?op=add&category_type=A' + 'new patron category' => $base_url.'admin/categorie.pl?op=add_form', + 'patron home' => $base_url.'members/members-home.pl', + 'new patron' => $base_url.'members/memberentry.pl?op=add&category_type=A', + 'new biblio' => $base_url.'cataloguing/addbiblio.pl?frameworkcode=FA', }; die "Invalid path" unless exists $paths->{$page}; return $paths->{$page}; -- 2.4.2