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:
- Download FitNesse from here.
- Once its downloaded, create a folder called FitNesse in C or D drive and move the downloaded file(fitnesse.jar) into this folder.
- Go to command prompt and open this folder C:\FitNesse
- 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
- 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
- Now open your browser and go to http://localhost. You will see the FitNesse environment.
- 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:
- !path C:\Fitnesse\FitNesseRoot\files\classes
- !path C:\Fitnesse\lib\*.jar
- 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
- 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.
- 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.
- 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|
- 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”
- Remember that we are passing the value for the variable searchString from FitNesse, but the variable should be declared in your java code.
- If you want to pass number of parameters, you need to include as follows:
- 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
- I have created a test script with Same class and test method. You can try this example: