Wednesday, January 29, 2014

Liferay Selenium Testing

How to Run Selenium Tests:
Download the Liferay 6.1 source code and check if the “portal-web\test” folder is present and if not then download any previous version of Liferay Source code and copy the folder at the below location
\liferay-portal-src-6.1.1-ce-ga2\portal-web

Before running Selenium test there are some prerequisites that must be met before beginning. Be sure to add the following line to your portal-ext.properties file found at “liferay-portal-6.1.1-ce-ga2\tomcat-7.0.27\webapps\ROOT\WEB-INF\classes”:
                                         captcha.max.challenges=-1
 
Changing the captcha.max.challenges to -1 will eliminate any random text verifications that Selenium is unable to deal with.
 
Before running the tests always make sure to close any Firefox or java processes that are open.
The ant task assumes several things are true about your current setup:
1.      In addition to whatever version of Liferay you are running the test on, that you also have the Plugins trunk currently installed. If you do have the Plugins trunk installed on your machine be sure to define its location in the release.properties file. IF you are not interested in running tests on Liferay plugins you must comment out the following lines in build-test.xml:
<!--<replace
file="${app.server.tomcat.portal.dir}/WEB-INF/web.xml"
token="session-timeout&gt;30&lt;"
value="session-timeout&gt;2&lt;"
/>-->
 
<!--<antcall target="test-tomcat-runtime">
<param name="test.class" value="Plugins1TestSuite" />
<param name="portlet.plugins.includes" value="alfresco-content-portlet, analog-clock-portlet" />
</antcall>
 
<antcall target="test-tomcat-runtime">
<param name="test.class" value="Plugins2TestSuite" />
<param name="portlet.plugins.includes" value="sample-localized-  portlet,sample-orbeon-forms-portlet" />
</antcall>-->
 
 
2. Comment out the tests you do not want to run from PortalWebTestSuite.java (Be sure you leave the login test in as it is necessary to log into the portal to use the message board portlet).
Description: http://www.liferay.com/c/wiki/get_page_attachment?p_l_id=4464764&nodeId=1071674&title=How+to+Run+Selenium+Tests&fileName=How+to+Run+Selenium+Tests%2FCommentOutPortalWebTestSuite.jpg
 
 
Modify test-Portal-Web. Properties file (source\portal-web\test):
 
Edit the test-Portal-Web. Properties file to specify the browser type. Make sure you have following lines in that file.
 
selenium.host=localhost
                                                           selenium.port=4444
 
#browser.type=*chrome
#browser.type=*firefox
                                                           #browser.type=*iehta
browser.type=*iexplore
 
company.id=1
portal.url=http://localhost:8080
 
 
 
      Run the ant start command:    
                    Open the command prompt and navigate to source folder (\liferay-portal-src-6.1.1-ce-ga2\portal-web) and execute the following
                 Command.
 
                                                          ant start
 
 
 
 
There are two components that must be running in order to run the Selenium Test Suite:
1.      Tomcat
2.      Selenium Server
                 Start the tomcat.
                        Start your application server. (Tomcat)                 
                  Start Selenium Server
                      1. In the command line navigate to the /source/lib/development directory.
                      2. Execute the following line - java -jar selenium-server.jar
If you get any Class not found exception at point 2 then copy the attached jar in the above source/lib/development directory and continue steps 1 & 2 with  Execute the following line - java -jar selenium-server-standalone-2.1.0.jar





Begin the test
1.      In a new command line window navigate to the /source/portal-web/ directory.
2.      Execute the following line:
ant test
It will run all the selenium test cases and you can see the results in test-results folder.