Sunday, September 2, 2012

How to Organize your selenium Project Structure

One of the major issues or problems I faced when I designed my test suites in selenium is on How should I organize my project and folder structures. There are many blogs and sites that cover issues you face in sleneium. I could not find many links which address this issue.


Contents:

Here in this post I will explain how I organized my selenium Test Suites, Cases, reports and ANT build file in Eclipse. I request every one to go through environment Setup page to ensure you can kick start the selenium testing.

Please Note that this article is on how to organize your selenium related folder structure, You may have a look at good practices in writing Selenium tests[under construction :)]  on how to write test cases. if you want to know the details on how to create a folder and source folder in eclipse have a look here.

Folder Structure

This is how I organize my folder structure for Selenium Projects...

src

Holds all your tests related java files. This folder will hold all your test packages. If you are using Eclipse for your project do not forget to mark this folder Use as Source folder.

I will as per my convention have all the Test Cases file names start with TestCase<nnn>_<feature>_<small_desc>.java. This convention will help me to filter out and run only the cases I want to run during test execution.

helper

Holds all the helper methods and utilities. This folder too will be of type source folder but you can drop in your re-usable wrappers and utilities in this folder just to keep your test suites clean.

build

This folder will hold your compiled .class files which you can jar and distribute.

backup

will hold your previous run logs. I have created this folder to hold the history of my runs. When ever I ran my test cases the latest results were overriding the previous ones. We will zip all my results and logs in this folder.

dist

In case you ant to distribute your suites as jar files. I did not try to push the test suites into jar files, so for me this folder is empty. Included this for generic purposes.

lib

Holds all the external libraries required to proceed with execution. I will include my Selenium, Junit, and any other jars in this folder.

testdata

Hard coding test data to your test cases is not a good practice. beacuse changing environment and data can imply potential costs to your automation process. For me this folder Holds test data and data sources likes excel sheets and plain files required for smooth test execution.

testreports

Apache ANT's junitreport tasks give beautiful test reports. I wanted my test reports in a separate folder, so I hold them in this folder.

build.xml

This is where I control everything in your test suite from. While you do most of your testing and test cases in your folder, you can filter, control, run and do a lots more with ANT build file.

Here are the list and Sequence of tasks I perform using my ANT build file.

List of tasks in my Project


  • Set my Projects CLASSPATH.
  • Backup my existing logs.
  • Clean up the existings logs directories.
  • make directories  to collect fresh logs during runs
  • Compile java Source code.
  • Run Junit Test cases
  • Generate Junit reports.

Here is how I do with my ANT build.xml File


<?xml version="1.0" encoding="UTF-8"?>
<!-- ======================================================================                                                        

     project     : Sample Selenium Project
     description : Ant-Build file for sample Selenium Test Automation                  
     author   : raghukiran@recurtrix.com                                                                
     ====================================================================== -->
<project name="Selenium demo" default="main" basedir=".">
 <description>
            Selenium Demo!
    </description>

 <!-- Sets variables which can later be used. -->
 <!-- The value of a property is accessed via ${} -->
 <property name="src.dir" location="src" />
 <property name="build.dir" location="build" />
 <property name="dist.dir" location="dist" />
 <property name="lib.dir" location="lib" />
 <property name="test.report.dir" location="testreport" />
 <property name="testreport.backup.dir" location="backups" />
 <property name="test.xmlreport.dir" location="testreport/xmlreports" />
 <property name="test.htmlreport.dir" location="testreport/htmlreports" />
 <property name="testdata.dir" location="testdata" />
 <property name="models.dir" location="models" />
 
 <!-- Set the below property to be displayed in Logs!!! -->
 <property name="proj.desc.name" value="Selenium Demo Project" />
 
 <!-- Set the below path to JDBC libs in Oracle installation directory -->
 <property name="oracle.dir" location="c:\\ORACLE\\product\\10.2.0.1\\jdbc\\lib" />

 <!-- This is ** very very ** important in case of HTTPS based websites. Get this right -->
 <property name="jsse.dir" location="C:\\Program Files\\Java\\jdk1.6.0_25\\jre\\lib" />

 <!-- Define the classpath which includes the junit.jar and the classes after compiling-->
 <path id="project.class.path">
  <fileset dir="${lib.dir}">
   <include name="**/*.jar" />
  </fileset>
  <fileset dir="${oracle.dir}">
   <include name="**/classes12.jar" />
  </fileset>
  <fileset dir="${jsse.dir}">
   <include name="**/jsse.jar" />
  </fileset>
  <pathelement location="${build.dir}" />
 </path>

 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
          target: backup
           Takes backup of the test reports executed earlier                      
         - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
 <target name="backup">
  <echo level="info" message="Taking backup of previously executed test reports ..." />

  <tstamp>
   <format property="NOW_UK" pattern="yyyy-MM-dd-hh-mm" locale="en,UK" />
  </tstamp>
  <property name="zipFilename" value="backup_${NOW_UK}.zip" />
  <zip destfile="${testreport.backup.dir}/${zipFilename}" basedir="${test.report.dir}" update="true" />
  <echo level="info" message="File ${zipFilename} saved" />
 </target>

 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
          target: clean
           Cleans up the directories                      
         - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
 <target name="clean">
  <delete dir="${test.xmlreport.dir}" quiet="true"/>
  <delete dir="${test.htmlreport.dir}" quiet="true"/>
  <delete dir="${test.report.dir}" quiet="true"/>
 </target>

 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
          target: makedir
           create the build, docs dist etc directories                      
         - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
 <target name="makedir">
  <mkdir dir="${test.report.dir}"/>
  <mkdir dir="${test.xmlreport.dir}"/>
  <mkdir dir="${test.htmlreport.dir}"/>
  <mkdir dir="${dist.dir}"/>
  <mkdir dir="${testdata.dir}"/>
  <mkdir dir="${models.dir}"/>
 </target>

 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
          target:  compile
             Compiles the java code                     
         - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
 <target name="compile" depends="clean, makedir">
  <javac srcdir="${src.dir}" destdir="${build.dir}" includeantruntime="false" debug="on">
   <classpath refid="project.class.path" />
  </javac>
 </target>

 
 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
          target:  junit
            Run the JUnit Tests, Filter out all the cases   
             Output report in XML format                
         - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
 <target name="junit" depends="compile">
  <junit printsummary="on" fork="true" haltonfailure="no">
   <classpath refid="project.class.path" />
   <formatter type="xml" />
   <batchtest todir="${test.xmlreport.dir}">
    <fileset dir="${src.dir}">
     <include name="**/*TestCase*.java" />
    </fileset>
   </batchtest>
  </junit>
 </target>

 <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
          target:  junitreport 
             Generate HTML reports from XML reports
         - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
 <target name="junitreport">
  <junitreport todir="${test.xmlreport.dir}">
   <fileset dir="${test.xmlreport.dir}">
    <include name="TEST-*.xml" />
   </fileset>
   <report todir="${test.htmlreport.dir}" format="frames">
   </report>
  </junitreport>
 </target>

 <!-- =============================================================
          target: main
          Starts with main project.              
         ============================================================= -->
 <target name="main" depends="compile, junit, junitreport">
  <description>Main target</description>
 </target>

</project>

This is how my Selenium Project looks like

Selenium Project Structure Organization
This is how my selenium Project Structure looks.

40 comments

  1. How should one organize positive test cases and negative test cases for a given scenario.

    ReplyDelete
    Replies
    1. I have read your blog its very attractive and impressive. I like it your blog.

      Java Training in Chennai Core Java Training in Chennai Core Java Training in Chennai

      Java Online Training Java Online Training Core Java 8 Training in Chennai Core java 8 online training JavaEE Training in Chennai Java EE Training in Chennai

      Delete
  2. Thanks for your post; selenium is most trusted automation tool to validate web application and browser. This tool provides precise and complete information about a software application or environment. Best Selenium training institute in Chennai

    ReplyDelete
    Replies
    1. I have read your blog its very attractive and impressive. I like it your blog.


      SEO Services in India SEO Company in India SEO Company in India

      Delete
  3. PYTHONPATH=. python tests/user/upload.py
    nosetests tests/user/upload.py
    import unittest
    from tests.user.upload import *
    unittest.main()
    python runtests.py

    This test runner could import more tests or could be particular about what tests it imports. At last, I'd prescribe utilizing nose over composing your own test runner.

    Beginning a test runner at the highest point of your chain of command works on the grounds that Python includes the momentum index of a script to the rundown of ways it hunt down modules.

    Best Selenium Training in Chennai

    ReplyDelete
    Replies
    1. Best Selenium Training institutes in Chennai

      We provide best selenium training in Chennai with Project Support.Join Creating Experts to learn Selenium and become experts in selenium.For more details pls check the below link.

      http://thecreatingexperts.com/software-testing-training-in-chennai/selenium-training-in-chennai/

      Delete
  4. Latest technology have created a greater impact over testing web applications. This vital in identifying important issues that raises in web appplications. Thanks for sharing this information in here. Keep blogging article like this.

    Selenium training in chennai | Best selenium training institute in chennai | Selenium testing course in chennai

    ReplyDelete
  5. We provide best Selenium Training in Chennai,If you want to learn real time Selenium.Click the below link

    http://www.citehr.com/377127-selenium-training-chennai-real-time-projects-ppt.html

    ReplyDelete
  6. Thanks for sharing your ideas. It’s really useful for me. Selenium is an automation testing tool used for web applications. I did Selenium Training in Chennai at besant technologies. It’s useful for me to make a bright career in IT industry.

    ReplyDelete
  7. Excellent post!!! Selenium automation testing tool makes your software validation process lot simpler. Keep on updating your blog with such awesome information. Selenium Training in Chennai | Selenium Course in Chennai

    ReplyDelete
  8. Really awesome blog. Your blog is really useful for me.
    Thanks for sharing this informative blog. Keep update your blog.
    Oracle Training In Chennai

    ReplyDelete
  9. Best Java Training Institute In ChennaiThis information is impressive; I am inspired with your post writing style & how continuously you describe this topic. After reading your post, thanks for taking the time to discuss this, I feel happy about it and I love learning more about this topic..

    ReplyDelete
  10. Great article. I read your post. Keep sharing such a useful post.

    digital marketing training in chennai

    ReplyDelete
  11. Informative post. happy to visit your blog. Thanks for sharing.

    php training in chennai

    ReplyDelete
  12. Hadoop training in hyderabad.All the basic and get the full knowledge of hadoop.
    hadoop training in hyderabad

    ReplyDelete
  13. Great article. happy to visit your blog. Thanks for sharing.

    digital marketing training in chennai

    ReplyDelete
  14. Great post on selenium.Selenium is an advantageous programming testing structure for web applications. Selenium gives a record/playback mechanical assembly to create tests without taking in a test scripting language.
    Regards,
    Selenium Training in Chennai | Selenium Course in Chennai | Best Selenium Training institute in Chennai

    ReplyDelete
  15. Great article. happy to visit your blog. Thanks for sharing.
    Microstrategy training in chennai

    ReplyDelete
  16. Wonderful bloggers like yourself who would positively reply encouraged me to be more open and engaging in commenting.So know it's helpful.

    seo company in chennai

    ReplyDelete
  17. I have own car so now I am back out there trying to show him how to do car repairs. Your blog is an excellent source of info, thanks.

    home spa services in mumbai

    ReplyDelete
  18. Informative post. happy to visit your blog. Thanks for sharing.

    selenium training in chennai

    ReplyDelete

  19. Great content thanks for sharing this informative blog which provided me technical information keep posting.
    Selenium Training in Chennai | Selenium Testing Course in Chennai

    ReplyDelete
  20. Thanks for sharing the information about the Selenium and keep updating us.It is really useful information to me.
    Selenium Training in Chennai
    Selenium Course in Chennai

    ReplyDelete
  21. Wonderful blog.. Thanks for sharing informative blog.. its very useful to me..

    iOS Training in Chennai

    ReplyDelete
  22. There are lots of information about latest technology and how to get trained in them, like this have spread around the web, but this is a unique one according to me. The strategy you have updated here will make me to get trained in future technologies. By the way you are running a great blog. Thanks for sharing this.

    Invisalign Treatment In Chennai

    Best Dental Clinic In Annanagar

    ReplyDelete
  23. Great post. I am actually getting ready to across this information, its very helpful for this blog. Also great with all of the valuable information you have keep up the good work you are doing well. Selenium Training in Chennai

    ReplyDelete
  24. You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...

    Android App Development Company

    ReplyDelete
  25. You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...
    iOS App Development Company
    iOS App Development Company

    ReplyDelete
  26. I wondered upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.

    Fitness SMS
    Fitness Text
    Salon SMS
    Salon Text
    Investor Relation SMS
    Investor Relation Text

    ReplyDelete
  27. The blog gave me idea to organize selenium project structure My sincere thanks for sharing this post please continue to share this post
    Software Testing Training in chennai

    ReplyDelete
  28. nice blog has been shared by you. before i read this blog i didn't have any knowledge about this but now i got some knowledge. so keep on sharing such kind of an interesting blogs.
    softwaretesting training in chennai

    ReplyDelete
  29. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
    Software Testing Training in Chennai
    Selenium Training in Chennai

    ReplyDelete
  30. I love this post.We share give the now amazing post.I understand all fantastic info.We will have shared learning it amazing post.
    Python Online Training
    Learn Python Online

    ReplyDelete
  31. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete
  32. nice blog has been shared by you. before i read this blog i didn't have any knowledge about this but now i got some knowledge. so keep on sharing such kind of an interesting blogs.
    selenium training in chennai

    ReplyDelete
  33. great and nice blog thanks sharing..I just want to say that all the information you have given here is awesome...Thank you very much for this one.
    web design Company
    web development Company
    web design Company in chennai
    web development Company in chennai
    web design Company in India
    web development Company in India

    ReplyDelete
  34. I wondered upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.

    Texting API
    Text message marketing
    Digital Mobile Marketing
    Mobile Marketing Services
    Mobile marketing companies
    Fitness SMS

    ReplyDelete