Bug 19181

Summary: Intranet and OPAC authentication selenium test
Product: Koha Reporter: Alex Buckley <alexbuckley>
Component: Test SuiteAssignee: Jonathan Druart <jonathan.druart>
Status: RESOLVED FIXED QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: jonathan.druart, martin.renvoize, mtompset, tomascohen
Version: master   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=18974
Whiteboard:
Change sponsored?: --- Patch complexity: ---
Bot Control: --- When did the bot last check this:
Who signed the patch off: Text to go in the release notes:
Bug Depends on: 19243    
Bug Blocks: 19384    
Attachments: Selenium test for logging into the Koha intranet and OPAC
Bug 19181 - Selenium test for logging into the Koha intranet and OPAC
Bug 19181 - Selenium test for logging into the Koha intranet and OPAC
Bug 19181: Change to use ENV, fix login and passwords
Bug 19181: Add new tests
Bug 19181: Selenium test for logging into the Koha intranet and OPAC
Bug 19181: Change to use ENV, fix login and passwords
Bug 19181: Add new tests
Bug 19181: Fix jenkins failure
Bug 19181: Do not screenshot

Description Alex Buckley 2017-08-27 00:03:21 UTC
This Selenium tests is to test authentication of a patron to the OPAC and intranet. 

It follows a similar workflow to the basic_workflow.t text by initially creating a patron category and patron user.

Then the superlibrarian user used to create these logs out and the created patron logs into the staff intranet and OPAC
Comment 1 Alex Buckley 2017-08-27 00:48:15 UTC
Created attachment 66502 [details] [review]
Selenium test for logging into the Koha intranet and OPAC

This selenium test goes through the process of creating a category and
patron user (as is completed in the basic_workflow.t test) then the
superlibrarian used to create them is logged out and the newly created
patron user authenticates into the OPAC and staff intranet therefore testing the
authenitcation of both.

Test plan (this test plan includes how to install Selenium as well as
how to run this test, for the benefit of people who have not got
Selenium installed on their machines):

1. wget https://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.0.jar

2. vim /etc/apt/sources.list.d/firefox.list

3. Paste into the file:
deb http://packages.linuxmint.com debian import

4. sudo apt-get update

5. sudo apt-get install firefox

6. sudo apt-get install xvfb

7. Set the SELENIUM_PATH vartiable:
SELENIUM_PATH=/home/vagrant/kohaclone/selenium-server-standalone-2.53.0.jar

8. Xvfb :1 -screen 0 1024x768x24 2>&1 >/dev/null &

9. DISPLAY=:1 java -jar $SELENIUM_PATH

Note: This will start up the selenium server. Everytime you want to shut
down this terminal window and want to restart Selenium just run the step
9 command to restart the Selenium server

10. Open a new terminal window and write in:
git clone https://github.com/gempesaw/Selenium-Remote-Driver --branch
build/master --single-branch --depth 1

11. cd Selenium-Remote-Driver

12. perl Makefile.PL

13. make

14. make test

15. sudo make install

16. Now everything is installed and you can et up for running the selenium tests

17. Create a superlibrarian user with the username koha and password
koha

18. If your usual port configuration for the intranet and OPAC is 8081
and 8080 respectively then set the staffClientBaseURL and OPACBaseURL
system preferences to localhost:8080 and localhost:80 respectively

19. sudo koha-shell <instancename>

20. perl t/db_dependent/selenium/authenticate.t

21. The test should pass.
Note: The time_diff comments in the test output showing what the test is
doing

Note: If you have issues with installing Selenium and
Selenium::Remote::Driver please write a comment on the bug report and I
will be more than happy to create a screencapture video showing all the
steps

Sponsored-By: Catalyst IT
Comment 2 Alex Buckley 2017-08-27 00:49:22 UTC
This patch was originally attached to 18974 however I have placed it in its own bug report to make testing more straightforward
Comment 3 Alex Buckley 2017-08-27 01:51:35 UTC
Created attachment 66505 [details] [review]
Bug 19181 - Selenium test for logging into the Koha intranet and OPAC

This selenium test goes through the process of creating a category and
patron user (as is completed in the basic_workflow.t test) then the
superlibrarian used to create them is logged out and the newly created
patron user authenticates into the OPAC and staff intranet therefore testing the
authenitcation of both.

Test plan (this test plan includes how to install Selenium as well as
how to run this test, for the benefit of people who have not got
Selenium installed on their machines):

1. wget https://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.0.jar

2. vim /etc/apt/sources.list.d/firefox.list

3. Paste into the file:
deb http://packages.linuxmint.com debian import

4. sudo apt-get update

5. sudo apt-get install firefox

6. sudo apt-get install xvfb

7. Set the SELENIUM_PATH vartiable:
SELENIUM_PATH=/home/vagrant/kohaclone/selenium-server-standalone-2.53.0.jar

8. Xvfb :1 -screen 0 1024x768x24 2>&1 >/dev/null &

9. DISPLAY=:1 java -jar $SELENIUM_PATH

Note: This will start up the selenium server. Everytime you want to shut
down this terminal window and want to restart Selenium just run the step
9 command to restart the Selenium server

10. Open a new terminal window and write in:
git clone https://github.com/gempesaw/Selenium-Remote-Driver --branch
build/master --single-branch --depth 1

11. cd Selenium-Remote-Driver

12. perl Makefile.PL

13. make

14. make test

15. sudo make install

16. Now everything is installed and you can et up for running the selenium tests

17. Create a superlibrarian user with the username koha and password
koha

18. If your usual port configuration for the intranet and OPAC is 8081
and 8080 respectively then set the staffClientBaseURL and OPACBaseURL
system preferences to localhost:8080 and localhost:80 respectively

19. sudo koha-shell <instancename>

20. perl t/db_dependent/selenium/authenticate.t

21. The test should pass.
Note: The time_diff comments in the test output showing what the test is
doing

Note: If you have issues with installing Selenium and
Selenium::Remote::Driver please write a comment on the bug report and I
will be more than happy to create a screencapture video showing all the
steps

Sponsored-By: Catalyst IT
Comment 4 M. Tompsett 2017-10-24 22:48:38 UTC
This should be tweaked according to https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19337#c1
Comment 5 M. Tompsett 2017-10-24 22:53:29 UTC
Comment on attachment 66505 [details] [review]
Bug 19181 - Selenium test for logging into the Koha intranet and OPAC

Review of attachment 66505 [details] [review]:
-----------------------------------------------------------------

See the description of ENV variables to be used here:
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=19337#c1

::: t/db_dependent/selenium/authenticate.t
@@ +32,5 @@
> +use MARC::Field;
> +
> +my $dbh = C4::Context->dbh;
> +my $login = 'koha';
> +my $password = 'koha';

This (user/password) does not use the possible ENV code that other tests use.

@@ +33,5 @@
> +
> +my $dbh = C4::Context->dbh;
> +my $login = 'koha';
> +my $password = 'koha';
> +my $base_url= 'http://'.C4::Context->preference("staffClientBaseURL")."/cgi-bin/koha/";

protocol is now part of staff URL.

@@ +34,5 @@
> +my $dbh = C4::Context->dbh;
> +my $login = 'koha';
> +my $password = 'koha';
> +my $base_url= 'http://'.C4::Context->preference("staffClientBaseURL")."/cgi-bin/koha/";
> +my $opac_url= C4::Context->preference("OPACBaseURL");

KOHA_INTRANET_URL and KOHA_OPAC_URL env logic should be used here too.
Comment 6 M. Tompsett 2017-10-24 23:13:37 UTC
t/db_dependent/selenium/authenticate.t .. 2/9
#   Failed test at t/db_dependent/selenium/authenticate.t line 83.
Wide character in print at /usr/local/share/perl/5.20.2/Test2/Formatter/TAP.pm line 113.
#                   'Koha › Log in to Koha'
#     doesn't match '(?^u:Patron categories)'
23:10:33.991 INFO - Executing: [find element: By.xpath: //a[@id="newcategory"]])
23:10:34.114 WARN - Exception thrown
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector
":"//a[@id=\"newcategory\"]"}
Command duration or timeout: 10 milliseconds

Yes, this is a yucky mix of outputs.
But sorry, I'm going to Failed QA this.
Comment 7 M. Tompsett 2017-10-30 03:33:11 UTC
Created attachment 68824 [details] [review]
Bug 19181 - Selenium test for logging into the Koha intranet and OPAC

This selenium test goes through the process of creating a category and
patron user (as is completed in the basic_workflow.t test) then the
superlibrarian used to create them is logged out and the newly created
patron user authenticates into the OPAC and staff intranet therefore testing the
authenitcation of both.

Test plan (this test plan includes how to install Selenium as well as
how to run this test, for the benefit of people who have not got
Selenium installed on their machines):

1. wget https://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.0.jar

2. vim /etc/apt/sources.list.d/firefox.list

3. Paste into the file:
deb http://packages.linuxmint.com debian import

4. sudo apt-get update

5. sudo apt-get install firefox

6. sudo apt-get install xvfb

7. Set the SELENIUM_PATH vartiable:
SELENIUM_PATH=/home/vagrant/kohaclone/selenium-server-standalone-2.53.0.jar

8. Xvfb :1 -screen 0 1024x768x24 2>&1 >/dev/null &

9. DISPLAY=:1 java -jar $SELENIUM_PATH

Note: This will start up the selenium server. Everytime you want to shut
down this terminal window and want to restart Selenium just run the step
9 command to restart the Selenium server

10. Open a new terminal window and write in:
git clone https://github.com/gempesaw/Selenium-Remote-Driver --branch
build/master --single-branch --depth 1

11. cd Selenium-Remote-Driver

12. perl Makefile.PL

13. make

14. make test

15. sudo make install

16. Now everything is installed and you can et up for running the selenium tests

17. Create a superlibrarian user with the username koha and password
koha

18. If your usual port configuration for the intranet and OPAC is 8081
and 8080 respectively then set the staffClientBaseURL and OPACBaseURL
system preferences to localhost:8080 and localhost:80 respectively

19. sudo koha-shell <instancename>

20. perl t/db_dependent/selenium/authenticate.t

21. The test should pass.
Note: The time_diff comments in the test output showing what the test is
doing

Note: If you have issues with installing Selenium and
Selenium::Remote::Driver please write a comment on the bug report and I
will be more than happy to create a screencapture video showing all the
steps

Sponsored-By: Catalyst IT

https://bugs.koha-community.org/show_bug.cgi?id=19181

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Comment 8 M. Tompsett 2017-10-30 03:33:14 UTC
Created attachment 68825 [details] [review]
Bug 19181: Change to use ENV, fix login and passwords

The kohadevbox has admin/admin set, so for testing when
creating the initial superuser, if you wish to minimize
effort, use admin/admin. Otherwise, make sure to:
export KOHA_USER={whatever your user is}
export KOHA_PASS={whatever your password is}
before attempting to run the test.

Also, this test was failing because of a validation check on
the passwords requiring uppercase letters, lowercase letters,
and numbers. Changed the sample data passwords to fix.

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Comment 9 M. Tompsett 2017-10-30 03:34:01 UTC
The readability of this code is a vast improvement over bug 18974. :)
Comment 10 M. Tompsett 2017-11-02 03:15:58 UTC
This and the other selenium tests all are blocked by bug 19243.
Comment 11 Jonathan Druart 2018-04-25 19:11:28 UTC
Created attachment 74854 [details] [review]
Bug 19181: Add new tests

This patch reuses the method newly added to Selenium.pm and improve
existing tests.
Comment 12 M. Tompsett 2018-04-26 17:47:12 UTC
Comment on attachment 74854 [details] [review]
Bug 19181: Add new tests

Review of attachment 74854 [details] [review]:
-----------------------------------------------------------------

::: t/lib/Selenium.pm
@@ +74,4 @@
>      $login_button->submit();
>  }
>  
> +sub opac_auth {

We don't have anything which calls this.
Comment 13 Jonathan Druart 2018-05-03 12:59:04 UTC
Nope but we may use it later.
I wanted to tell explicitly which form we use to login from the authentication.t tests.
Comment 14 Jonathan Druart 2018-05-03 12:59:51 UTC
I can remove it anyway if you think it should.
Comment 15 Tomás Cohen Arazi 2018-05-08 14:21:05 UTC
Created attachment 75156 [details] [review]
Bug 19181: Selenium test for logging into the Koha intranet and OPAC

This selenium test goes through the process of creating a category and
patron user (as is completed in the basic_workflow.t test) then the
superlibrarian used to create them is logged out and the newly created
patron user authenticates into the OPAC and staff intranet therefore testing the
authenitcation of both.

Test plan (this test plan includes how to install Selenium as well as
how to run this test, for the benefit of people who have not got
Selenium installed on their machines):

1. wget https://selenium-release.storage.googleapis.com/2.53/selenium-server-standalone-2.53.0.jar

2. vim /etc/apt/sources.list.d/firefox.list

3. Paste into the file:
deb http://packages.linuxmint.com debian import

4. sudo apt-get update

5. sudo apt-get install firefox

6. sudo apt-get install xvfb

7. Set the SELENIUM_PATH vartiable:
SELENIUM_PATH=/home/vagrant/kohaclone/selenium-server-standalone-2.53.0.jar

8. Xvfb :1 -screen 0 1024x768x24 2>&1 >/dev/null &

9. DISPLAY=:1 java -jar $SELENIUM_PATH

Note: This will start up the selenium server. Everytime you want to shut
down this terminal window and want to restart Selenium just run the step
9 command to restart the Selenium server

10. Open a new terminal window and write in:
git clone https://github.com/gempesaw/Selenium-Remote-Driver --branch
build/master --single-branch --depth 1

11. cd Selenium-Remote-Driver

12. perl Makefile.PL

13. make

14. make test

15. sudo make install

16. Now everything is installed and you can et up for running the selenium tests

17. Create a superlibrarian user with the username koha and password
koha

18. If your usual port configuration for the intranet and OPAC is 8081
and 8080 respectively then set the staffClientBaseURL and OPACBaseURL
system preferences to localhost:8080 and localhost:80 respectively

19. sudo koha-shell <instancename>

20. perl t/db_dependent/selenium/authenticate.t

21. The test should pass.
Note: The time_diff comments in the test output showing what the test is
doing

Note: If you have issues with installing Selenium and
Selenium::Remote::Driver please write a comment on the bug report and I
will be more than happy to create a screencapture video showing all the
steps

Sponsored-By: Catalyst IT

https://bugs.koha-community.org/show_bug.cgi?id=19181

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 16 Tomás Cohen Arazi 2018-05-08 14:21:11 UTC
Created attachment 75157 [details] [review]
Bug 19181: Change to use ENV, fix login and passwords

The kohadevbox has admin/admin set, so for testing when
creating the initial superuser, if you wish to minimize
effort, use admin/admin. Otherwise, make sure to:
export KOHA_USER={whatever your user is}
export KOHA_PASS={whatever your password is}
before attempting to run the test.

Also, this test was failing because of a validation check on
the passwords requiring uppercase letters, lowercase letters,
and numbers. Changed the sample data passwords to fix.

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 17 Tomás Cohen Arazi 2018-05-08 14:21:17 UTC
Created attachment 75158 [details] [review]
Bug 19181: Add new tests

This patch reuses the method newly added to Selenium.pm and improve
existing tests.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 18 Jonathan Druart 2018-05-11 14:12:45 UTC
Pushed to master for 18.05, thanks to everybody involved!
Comment 19 Jonathan Druart 2018-05-11 18:42:04 UTC
Created attachment 75278 [details] [review]
Bug 19181: Fix jenkins failure
Comment 20 Jonathan Druart 2018-05-11 18:45:07 UTC
Pushed to master
Comment 21 Jonathan Druart 2018-05-11 19:25:30 UTC
Created attachment 75285 [details] [review]
Bug 19181: Do not screenshot
Comment 22 Jonathan Druart 2018-05-14 14:20:24 UTC
Last patch pushed to master.