Friday, August 24, 2012

Steps to install perl module for test-distribution in Ubuntu/Linux


How to install perl module for test-distribution in Ubuntu/Linux?

Posted by Joys of Programming on in Perl
When using Test::Distribution in a test script, it goes through all the modules in your distribution, checks their POD, checks that they compile ok and checks that they all define a $VERSION. This module also performs a numer of test on the distribution itself. It checks that your files match your SIGNATURE file if you have one. It checks that your distribution isn’t missing certain ‘core’ description files. It checks to see you havent’ missed out listing any pre-requisites in Makefile.PL It defines its own testing plan, so you usually don’t use it in conjunction with other Test::* modules in the same file. It’s recommended that you just create a one-line test script as shown in the SYNOPSIS above. However, there are options.To install this package in Ubuntu,
$ sudo apt-get install libtest-distribution-perl


How to install perl module for test-exception in Ubuntu/Linux?

Posted by Joys of Programming on in Perl
Test::Exception is a Perl test module that provides a few convenience methods for testing exception-based code. It is built with Test::Builder and plays happily with Test::More and friends. Note that this module only checks for exceptions, so it ignores other methods of halting program executing – including exit(). If your code causes the Perl interpreter to exit, Test::Exception won’t be able to catch it.To install this package in Ubuntu,
$ sudo apt-get install libtest-exception-perl

Selenium Test Suite on Ubuntu

In case you have a Ubuntu server running Hudson (software for Continuous Integration), you may want to make a first attempt to run a Selenium test suite in command line before setting up a Hudson job that automatically runs the test suite.
Let’s suppose you already have a test suite; if not, check my previous post:  How to create a test suite in Selenium?, where I created a simple test suite composed of 2 test cases, one that checks the elements present in Google Sign up form and other that tests the error messages texts when you submit the sign up form with all fields empty.
 I am going to assume your local machine is Windows and that you are going to use these tools to work with the Ubuntu server:
  • Putty (terminal emulator application)
  • WinSCP (FTP client for Windows)
  • For using these tools you just need to know the IP address, user and password to access the Ubuntu Server.

In the following sections, I am going to show you how to install Selenium RC on Ubuntu and how to run the test suite. In case you don’t have a X server running, I am also going to show you how to use xvfb and capture a screenshot with xwd  to see if everything work as expected.

Install Selenium RC on Ubuntu                                                           

1. Download the zip file from http://seleniumhq.org/download/ in the server or use WinSCP to copy the zip file from your machine to the server.
2. Open a Putty terminal and connect to the Ubuntu server 
3. Change to the directory, where you will have Selenium RC.
4. unzip [selenium RC zip file] 

Copy the Selenium test suite and test cases from your machine to the Ubuntu server

1. Open WinSCP.
2. Connect to Ubuntu server.
3. Copy the files from your machine to a location in the server.
For example, these files:
  • Test Suite file:  TestSuite.html
  • Test cases files:
    • GoogleSignUpform.html
    • GoogleSignUpdErrors.html
  • Test Results file: TestResults.html (this is an empty HTML file for saving test results)

Edit your HTML test suite file

The HTML test suite file contains the file location of each test case in your local machine. You need to edit the file location of each test case with the location in the Ubuntu server.
WinSCP is a remote editor, you can use it to open and edit the test suite file.

Run Selenium RC to execute your test

1. Open a Putty terminal.
2. Connect to the Ubuntu server.
3. Go to the location where you unzipped Selenium RC.
4. Execute the command:
java -jar selenium-server.jar -htmlSuite *[browser] [initial address] [test suite location] [test result html file for results] 
For example:
java -jar selenium-server.jar -htmlSuite *firefox 
http://www.google.com  
/home/oshyn/projects/selenium/TestSuite.html  /home/oshyn/projects/selenium/TestResults.html

You will get the following error, as Firefox in the Ubuntu server requires a display: 

“Error: no display specified …. HTML suite exception seen:”

You get this error when no X server is running and in this case Firefox needs a X server.
 

Set up a Virtual Display with xvfb

I read this very useful article: http://shotgunsandpenguins.blogspot.com/2008/10/how-to-run-selenium-tests-with-hudson_14.html, in which the author shows some very simple steps to set up the virtual display with xvfb (virtual framebuffer). In summary you need to:

1. Download xvfb,  by running in a putty terminal:
sudo aptitude install xvfb

xvfb is normally installed  in /usr/bin/xvfb 

2. Execute xvfb to specify the display you will use: 
/usr/bin/Xvfb :7 -ac -screen 0 1024x768x8 
:7  makes xvfb use display 7
-ac Disables access control to the X server, enabling access by any host
(Useful for running test suites remotely)
-screen 0 1024x768x8 creates screen 0 on the chosen display (7) at resolution 1024x768 and 8-bit color depth.
These errors  and warnings may appear but command will still run:
expected keysym, got XF86KbdLightOnOff: line 70 of pc
expected keysym, got XF86KbdBrightnessDown: line 71 of pc
expected keysym, got XF86KbdBrightnessUp: line 72 of pc
Could not init font path element /var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType, removing from list!
FreeFontPath: FPE "/usr/share/fonts/X11/misc" refcount is 2, should be 1; fixing.

Run the test suite with the virtual display

After you installed and configured xvfb to use a specific display:
1. In another Putty terminal, set the DISPLAY variable to use the display you configured with xvfb:
export DISPLAY=":7.0"
2.Execute the command:
java -jar selenium-server.jar -htmlSuite *[browser] [initial address] [test suite location] [test result html file for results]
For example:
java -jar selenium-server.jar -htmlSuite *firefox http://www.google. com /home/oshyn/projects/selenium/TestSuite.html /home/oshyn/projects/selenium/TestResults.html
Now you won’t get the error: “Error: no display specified …. HTML suite exception seen:” 
You can copy the result HTML file to you machine using WinSCP.

Take a screenshot of the server

After running the test, you may want to take a screenshot of the X window to see if no errors appear.
To do this, you can use xwd program, which will store the window image as a dump file.
In a Putty terminal, run this command:
xwd -root -display :7.0 -out firefox 
7.0 is the display in which we run the Test suite. 
firefox is the name of the dump file.
In order to convert the dump file in a png file, you can download ImageMagick by running this command in a Putty terminal:
sudo apt-get install imagemagick 
Then to convert the dump file into a .png file:
convert firefox firefox.png

No comments:

Post a Comment