Monday, January 2, 2012

FitNesse and Selenium

When we create our Selenium tests in Java normally we use JUnit or TestNG frameworks to execute our test scripts. We can also use FitNesse tool as a framework for our Selenium tests. FitNesse can be used when we have the below scenarios:

  • When we need to pass number of parameters to the script
  • When we need to run the same script with different parameters
  • When we need to run the same script with different URLs as parameters (functionality will be same).

You might have this question running in your mind!! Can't we use JUnit or TestNG to achieve the above things. Answer to this question will be, YES, we can use. But, we need to go for the concepts like Data Providers and JXL (Read data from Excel sheet) while using JUnit or TestNG.

When we use FitNesse, we can simply achieve the above things without Data Provider and JXL. Also, we doesn't require any technical person to execute our scripts. Once the test scripts are configured with FitNesse, any one can execute the scripts from there.

Just to give a try, follow these steps:
  1. Download FitNesse from here.
  2. Once its downloaded, create a folder called FitNesse in C or D drive and move the downloaded file(fitnesse.jar) into this folder. 
  3. Go to command prompt and open this folder C:\FitNesse
  4. Type java -jar fitnesse.jar and press enter. FitNesse jar file will be unpacked and you will find a additional folder called FitNesseRoot which will be having all the supporting files
  5. Again type java -jar fitnesse.jar and press enter. This time your FitNesse server will be started. If it ask you to choose the different port, use -p argument with the above command: java -jar fitnesse.jar -p 8081
  6. Now open your browser and go to http://localhost. You will see the FitNesse environment.
  7. You will see some introduction notes on the home page. Click on Edit from left navigation and remove all the notes and configure your Java test scripts and jar files. You need to include the below things: 
    • !contents
    • !path C:\Fitnesse\FitNesseRoot\files\classes
    • !path C:\Fitnesse\lib\*.jar
  8. Make sure you have created the folder called "classes" under C:\Fitnesse\FitNesseRoot\files location and included all your test scripts (Java class files). Also make sure you have created lib folder under C:\FitNesse and included all the necessary jar files: FitNesse.jar, selenium-java-client-driver-2.x.jar, selenium-server-standalone.jar
  9. Once you have configured your test scripts and jar files, click on save to update the changes. Now you can only see your test script and jar file configuration paths on your FitNesse home page. Whenever you open FitNesse, you will see this path.
  10. Now click on Add Child on the top of the home page to create a Test Suite and Test and enter a name. Make sure you have minimum two words in the name and each word should start with capital letter. For Example, TestSuite - SampleSuite and Test - SearchCheck.
  11. Now you can see your suite on the home page. Click on that, you will find your Test. When you open that, you will get Edit option in the left navigation. Click on that and call your test script. Follow the below format: 
    • !|package name.class name|
    • |parameter name|method name|
    • |parameter value|Expected Outcome|
  12. For Example, if you have created a class SampleClass under the package Sample in Java. Assume that you have a test method "firstMethod()" and a parameter "searchString"
    • !|Sample.SampleClass|
    • |searchString|firstMethod()?|
    • |Sachin|True|
  13. Remember that we are passing the value for the variable searchString from FitNesse, but the variable should be declared in your java code. 
  14. If you want to pass number of parameters, you need to include as follows:
    • !|Sample.SampleClass|
    • |searchString|firstMethod()?|
    • |Sachin|True|
    • |Yuvraj|True|
    • |Dravid|True|
    • |Dhoni|True|
  15. After adding all your parameters, save the changes and click on Test on the left navigation. But, make sure you test script is created and the class file has been stored in this location: C:\Fitnesse\FitNesseRoot\files\classes
  16. I have created a test script with Same class and test method. You can try this example: 
package Sample;

import com.thoughtworks.selenium.DefaultSelenium;

import fit.ColumnFixture;

public class SampleClass extends ColumnFixture {
public DefaultSelenium selenium;
public String searchString;
public SampleClass()
{
selenium = new  DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com/");
selenium.start();
}
public boolean firstMethod() throws Exception
{
selenium.open("/");
selenium.waitForPageToLoad("30000");
selenium.type("name=q", searchString);
selenium.click("btnG");
Thread.sleep(5000);
return selenium.isTextPresent("News for "+searchString);
}
}

Screenshot of FitNesse test environment:


38 comments:

  1. Thanks
    it Was very useful.........

    ReplyDelete
  2. Thanks for the great information in your blog Selenium Training

    ReplyDelete
  3. The blog that you shared regarding the FitNesse become very easy to download. But, tell me that the primary difference in using JBehave other than FitNesse in component testing.
    Selenium Training in Chennai

    ReplyDelete
  4. Once you write this Java class, write an Ant script to compile the code and package it into a Java Archive Resource (JAR) file. Most Selenium users will run their Selenium tests from the Ant script itself.
    Read more: Selenium Training in Chennai
    Selenium Training in Velachery
    Selenium Training Institute in Chennai

    ReplyDelete
  5. Good work! I have to read search for some blog related to Selenium Automation Tools Fitness across that I See this blog link, In these blog site information, helped to us, we share it marvelous Quality of content Great Job Doing Well Done.
    Selenium Training in Chennai

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information... Java Training in Chennai | Blue prism Training in Chennai

    ReplyDelete
  8. Those rules moreover attempted to wind up plainly a decent approach to perceive that other individuals online have the indistinguishable enthusiasm like mine to get a handle on incredible arrangement more around this condition
    safety course in chennai

    ReplyDelete
  9. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us. Do check | Get trained by an expert who will enrich you with the latest updates.
    Web Designing Course in chennai
    Java Training in Chennai
    Web Designing Course in Chennai with placement
    website design courses
    Java Classes in Chennai
    Core Java Training in Chennai

    ReplyDelete
  10. In the beginning, I would like to thank you much about this great post. Its very useful and helpful for anyone looking for tips to help him learn and master in Angularjs. I like your writing style and I hope you will keep doing this good working.
    Angularjs Training in Bangalore
    Angularjs Training Institute In Bangalore
    Angularjs Course in Bangalore
    Android Institute in Bangalore
    Android Coaching in Bangalore
    Android Coaching Center in Bangalore

    ReplyDelete
  11. Nice post. I learned some new information. Thanks for sharing.

    chocolatesanddreams
    Guest posting sites

    ReplyDelete
  12. Amazing information,thank you for your ideas.after along time i have studied an interesting information's.we need more updates in your blog.
    angularjs tutorial in bangalore
    angularjs institutes in bangalore
    Angular JS Training in chennai
    AngularJS Training Institutes in Vadapalani

    ReplyDelete
  13. This is a terrific article, and that I would really like additional info if you have got any. I’m fascinated with this subject and your post has been one among the simplest I actually have read.
    Data Science Course in Indira nagar
    Data Science Course in btm layout
    Python course in Kalyan nagar
    Data Science course in Indira nagar
    Data Science Course in Marathahalli
    Data Science Course in BTM Layout

    ReplyDelete
  14. Hello! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done an outstanding job.
    Advanced AWS Training in Chennai | Best Amazon Web Services Training in Chennai
    AWS Training in Bangalore Reviews | AWS Training in Bangalore Cost
    AWS Online Training India | AWS Online Training Fees

    ReplyDelete
  15. Some us know all relating to the compelling medium you present powerful steps on this blog and therefore strongly encourage
    contribution from other ones on this subject while our own child is truly discovering a great deal.
    Have fun with the remaining portion of the year.

    Selenium training in bangalore | best selenium training in bangalore

    ReplyDelete
  16. After reading your blog I was amazed. The blog was explained clearly. And I hope all other readers will understand and experience how I felt after reading such a wonderful blog.
    IELTS Coaching in chennai

    German Classes in Chennai

    GRE Coaching Classes in Chennai

    TOEFL Coaching in Chennai

    spoken english classes in chennai | Communication training



    ReplyDelete
  17. This is a terrific article, and that I would really like additional info if you have got any. I’m fascinated with this subject and your post has been one among the simplest I actually have read.
    acte reviews

    acte velachery reviews

    acte tambaram reviews

    acte anna nagar reviews

    acte porur reviews

    acte omr reviews

    acte chennai reviews

    acte student reviews

    ReplyDelete
  18. Awesome! Education is the extreme motivation that open the new doors of data and material. So we always need to study around the things and the new part of educations with that we are not mindful.


    python training in bangalore

    python training in hyderabad

    python online training

    python training

    python flask training

    python flask online training

    python training in coimbatore


    ReplyDelete
  19. Yes, it is hard, compared to other small desktop or web programming projects. ... If you have prior experience in programming than android dev will be very easy to pick up, especially if you're familiar in Java.thanks lot!!



    Android Training in Chennai

    Android Online Training in Chennai

    Android Training in Bangalore

    Android Training in Hyderabad

    Android Training in Coimbatore

    Android Training

    Android Online Training

    ReplyDelete
  20. I have bookmarked your blog, the articles are characteristic expanded than substitute related websites.. gratitude for a warm blog! Quick Heal Crack

    ReplyDelete
  21. Very secure message. I just staggered concerning your blog and wanted to broadcast that i've as a general rule cherished concentrating on your blog entries. Any pomposity i'll buy in on your feed and I slant you announce again rapidly. colossal gratitude for the helpful information. Kaspersky Antivirus Crack

    ReplyDelete