Selenium with FitNesse – Acceptance testing Framework
RSSS

Selenium Integration with FitNesse Acceptance testing framework

FitNesse is a web server, a wiki, and an automated testing tool for software. FitNesse is a software development collaboration tool. FitNesse is designed to support acceptance testing rather than unit testing in that it facilitates detailed readable description of system function.

FitNesse enables customers, testers, and programmers to learn what their software should do, and to automatically compare that to what it actually does do. It compares customers’ expectations to actual results.
In other words,
FitNesse is a lightweight, open-source framework that makes it easy for software teams to:
1. Collaboratively define Acceptance Tests
2. Run those tests and see the results

Working of FitNesse


Getting started:

  • We can easily create and edit pages
  • It requires no configuration or setup.
  • Just run it and then direct your browser to the machine where it is running

The Overview of Integrating the Selenium Remote Control with FitNesse:

  • Create an object for Selenium in a code.
  • Pass the required parameters
  • Start the selenium server and run the script by using FitNesse tool

Now we will get started in preparing the test environment for both FitNesse as well as Selenium

FitNesse

  1. Get the latest version of the jar file “FitNesse jar” from the below site
  2. Download Here.

  3. Place it in your local drive and consider it as Base location
  4. Unpack jar by typing the below command after navigating to the Base location via command prompt
    Java –jar fitNesse.jar
  5. Once we got the folder “FitNesseRoot” and unpack process is over, close the command prompt.
  6. Create a new folder “Libraries” in the Base location (it is used to place our selenium stuff related jars)

Selenium part:
Create a new project in Eclipse. You can also refer my post on creating a new project structure

package SamplePackage;

import com.thoughtworks.selenium.DefaultSelenium;

public class FirstClass
{
  DefaultSelenium selenium;
//Constructor method
public FirstClass(String host, int port, String browser, String baseURL)
{
    this.selenium = new DefaultSelenium(host, port, browser, baseURL);
    this.selenium.start(); 
}

public boolean open(String URL) {
    this.seleniumInstance.open(URL);
    return true;
}

public boolean type(String locator, String value) {
    boolean elementFound = this.seleniumInstance.isElementPresent(locator);
    if (elementFound) {
      this.seleniumInstance.type(locator, value);
    }
    return elementFound;
}
public boolean click(String locator) {
    boolean elementFound = this.seleniumInstance.isElementPresent(locator);
    if (elementFound) {
      this.seleniumInstance.click(locator);
    }
    return elementFound;
}
public boolean verifyResultPage(String locator) {
    boolean elementFound = this.seleniumInstance.isElementPresent(locator);
    return elementFound;
}

public boolean close() {
    this.seleniumInstance.close();
    return true;
}
public boolean stop() {
    this.seleniumInstance.stop();
    return true;
}


}

Convert the program files as Jar file with name “SampleJarFile” using Eclipse IDE export option

Integration of FitNesse and Selenium

1) Place the jar files “SampleJarFile.jar” and “Selenium-Server.jar” in the folder “Libraries” which is in the FitNesse Base location

2) Start the FitNesse Server from the base location by using below command in the command prompt
java -cp fitnesse.jar fitnesseMain.FitNesseMain -p 8080 -e 0 -o %1 %2 %3 %4 %5

Here, I have given the port no as 8080. If you are getting any message like “Port 8080 is already in use.”
Then use some other ports. Say 8081, 8082, 8083…

3) Open the browser and type the below address url to view the FitNesse wiki page

http://localhost:8080

4) You can see the FrontPage of the wiki page.

5) Click on “add child” next to the text “FrontPage” and you will get the light box to create the page.

6) Enter our first wiki page with the name as “FirstWikiPage” and select “Normal” option from the left pane. (Note: you have use camel letter to name the wiki pages)

7) Click on “Add” button

8) Click on the “FirstWikiPage” link and Navigate to that page

9) To get the Tree Hierarchy structure for our test execution, we are going to create Test suite and Tests

10) First Click on the “add child” link next to the text “FirstWikiPage”

11) Enter the Test suite name as “FirstTestSuite” and select “Suite” option from the left pane

12) Click on “Add” button

13) Now, the Test suite will be listed under “FirstWikiPage”

14) In the Test suite page “FirstTestSuite”, we have to define the Test system of the FitNesse framework and also we need to mention Class path of the selenium scripts.

15) Click on the link “FirstTestSuite” and it will open the corresponding page

16) Click on “Edit” button from the left page and Paste the below comments
!contents -R3 -g -p -f -h

!define TEST_SYSTEM {slim}

Class Path
!path Libraries *.jar

17) Now inside the page “FirstTestSuite” we have to create
a. Tests page (activites which we need to verify in the application)
b. SetUp page (Initial step to perform before Tests page execution)
c. TearDown page (Final step to perform after Tests page execution)
Note: Once we created the SetUp and TearDown page. It will display for all the tests by default.

18) Create the test page with the name “FirstTestCase”, SetUp page with the name “SetUp” and TearDown page with the name “TearDown”

19) When creating the test page you have to select the“test” option and when creating the “SetUp” & “TearDown” page you have select the “Normal” option.

20) Write the comments as below with respect to the pages
a) Set Up page
!|import |
| SamplePackage |

!define BrowserType1 {*iexplore}

#!|script|
|start|First Class|localhost|4444|${BrowserType1}|http://www.google.com |

b) TearDown page
#!|script|
|stop|

c) FirstTestCase page

#!|script|
|open;|http://www.google.co.in/|
|type;| id=gbqfq|Test |
|click;| id=gbqfba|
|verifyResultPage;| css=em|
|close|

And Save it. That’s all now you have created the sample scripts which open the browser, type the searchkeyword, click the Search button and verify the result is displayed or not

How to Execute Selenium tests via FitNesse ?

After completing the creation of the page, navigate to the page “FirstTestCase”.
The page will be looked like below,


Start the selenium server and Click on “Test” button from the left pane of the page “FirstTestCase”.
It will automatically invoke the browser and it performs action defined in the fitNesse page.

5 thoughts on “Selenium with FitNesse – Acceptance testing Framework

  1. Sam
    November 19, 2012 at 6:08 am

    Great stuff, thanks.

  2. shan
    December 11, 2012 at 12:30 pm

    hi manoj.. great stuff and thanks for sharing it…
    can we integrate selenium webdriver with Fitnesse?
    if yes can u please share some code with webdriver

    1. December 11, 2012 at 3:54 pm

      Yes, you can. I dont have anything right now. But you can try as the same as what you do for Selenium RC.

      1. Rakesh M
        October 15, 2013 at 10:08 am

        Hi, Yes we can integrate with selenium webdriver, but the problem could be handling the dependencies, we have used a maven project and maven shade plugin to create a big Jar(a bundle including all dependent Jars together) and kept it in the home folder of Fitnesse. This solved the problem.

  3. Ravinder reddy
    January 23, 2014 at 11:01 am

    Hi
    At 3rd Step I am getting this Error…
    Unable to connect
    Firefox can’t establish a connection to the server at localhost:8080.
    The site could be temporarily unavailable or too busy. Try again in a few
    moments.
    If you are unable to load any pages, check your computer’s network
    connection.
    If your computer or network is protected by a firewall or proxy, make sure
    that Firefox is permitted to access the Web.

Leave a Reply

Your email address will not be published. Required fields are marked *