Script table using SLIM fitNesse tool - fitnesse

If i tried to run a givwenzen script using FitNesse SLIM getting error that givwenzen class is not picked up.
May be some class path error.
If anyone could help me with an example of givwenzen
Even with the addition of two numbers.
Thanks in advance

The project https://github.com/weswilliams/GivWenZen has a number of examples. Here's one:
1) Start with an example fixture actual class found in the givwenzen_test.jar.
2) In a FitNesse table it could look like this.
import and start should go in SetUp or SuiteSetUp
|import|
|org.givwenzen|
|script|
|start|giv wen zen for slim|
this is your test
|script|
| given| a ToDo item is due tomorrow |
| when | the date changes to tomorrow |
| then | a notification exists indicating the ToDo is due |
3) The following is an example step class and test step method ===
package bdd.steps;
#DomainSteps
public class ExampleSteps {
#DomainStep( “a ToDo item is due (.*)” )
public void createToDoWithDueDateOf(CustomDate date) {
// do something
}
#DomainStep( “the date changes to (.*)” )
public void theDateIs(CustomDate date) {
// do something
}
#DomainStep( “a notification exists indicating the ToDo is due” )
public boolean verifyNotificationExistsForDueToDo() {
// do something
return false;
}
}

Related

Parameterizing a specflow step with keyword string from example step

I am new to specflow, want help with a specflow scenario like the one below.
Scenario Outline: Error messages validation for maximum allowed term rule
Given a <product>
When term exceeds the max allowed term
Then this <errormessage> is displayed
Examples:
| product | errormessage |
| ProductA | This is an error message 1 |
| ProductB | This is an error message 2 |
| ProductC | This is an error message 3 |
For the last step definition "*Then this errormessage is displayed " step, I want to reuse an existing binding method
"Then this (.) is displayed"
This existing binding method takes a string as a parameter (expected error message) and asserts it against the actual message picked form the app under test.
But when I use the method as is - its unable to pass the error message content as an array of strings . Would someone be able to help me to understand what do I need to do to make it work ?
Binding method example below . The step Then this is displayed is not able to recognize this binding, its asking me to write another method.
[Then(#"this ""(.*)"" is displayed")]
public void ThenErrorMessageIsDisplayed(string errorMessage)
{
var msg = uServiceSupport.GetMessages(responseData);
var found = new JObject();
// due to multiple error and warning messages
foreach (var elem in msg)
{
if (elem["message"].ToString().Contains(errorMessage))
found = (JObject)elem;
}
try
{
Assert.IsTrue(found.HasValues, "Check if response has warning/error message");
Assert.AreEqual(errorMessage, found["message"].ToString(), "Check if the error message is {0}", errorMessage);
}
catch (AssertionException)
{
Helper.LogInfo(string.Format("Response:\n {0}", JObject.Parse(responseData)));
throw;
}
}
The problem is in your step regex. you have this:
[Then(#"this ""(.*)"" is displayed")]
but you try and call it like this:
Then this <errormessage> is displayed
you do not have consistent usage of the ". you either need:
[Then(#"this (.*) is displayed")]
or
Then this "<errormessage>" is displayed

How to write fitnesse code for a method which accepts 2 parameters

I'm newbie to fitnesse and trying to run a simple calculator class which has "add" method accepting 2 parameters and returning the result. Can anyone help me to write the firnesse code for this, my method is as below
public int add(int a, int b) {
return a+b;
}
I believe you are trying to get a table like:
|AddFixtureTest |
|left|right|sum?|
|1 |1 |2 |
|2 |4 |6 |
This requires a java class like:
import fit.ColumnFixture;
public class AddFixtureTest extends ColumnFixture {
public int left;
public int right;
public int sum(){
return add(left, right);
}
private int add(int a, int b) {
return a+b;
}
}
See http://fitnesse.org/FitNesse.UserGuide.FixtureGallery.BasicFitFixtures.ColumnFixture
I assume Slim is fine by you and I'm gonna use script table for this (more out of habit):
|script| <class name> |
|add;| <variable1> | <variable2> |
As simple as that. And, make sure you are using the right libraries and pointing to the location of the where the class file is.
Example:
|import|
fitnesse.slim.test |
If you are interested in knowing why I have placed a semi-colon after "add", and how script table works, please go through this:
http://www.fitnesse.org/FitNesse.UserGuide.WritingAcceptanceTests.SliM.ScriptTable
You can get the FitNesse tutorial there for .Net code. I tried to describe how to use FitNesse for different types of testing.
If you want to check two parameters on the output you can do the following:
Return IEnumerable implementation with classes, which contains get
and set properties (see here). NetRunner will use get properties
if it can, otherwise it will use set properties. As a result, it will
set all available data first and then compare items left.
You can use out parameters in the tests, so you can return several different values and check them
The correct answer is:
|script:<classPackage>.<ClassName>|
|check|add;|8|8|16|
First tell the script to navigate to the correct class. In the next line you have to call either a method or a constructor. You can call the method by it's name (or fancy smansy digibetic words that vaguely match) and tack on a semicolon. But anything put into the pipe-blocks after that will be interpreted as parameters for that method. So how do you put the expected output?
The trick is to tell the FitNesse engine you need a result, with the keyword 'check'.
This will make the final pipe-block be the field for the expected result, in this case 16.
Here is a picture of the java code
Here is a picture of the text input and the FitNesse sceen result

FitNesse: Comparing data in Slim Test system

Table example:
!script|SomeTest |
|Goto |$Url |
|check |IsAt|IndexPage|true|
|Index |CheckUserOrder? |
|0 |Name1 |
|1 |Name2 |
Code example:
public class SomeTest {
public string index;
public bool IsAt(string pageTitle){
//function for checking title of page
}
public string CheckUserOrder{
return username(index); // will get name of user for list which is other class
}
}
An exception is thrown: method name '0' not found in SomeTest...
I don't know why FitNesse is considering '0' as a method and not a parameter.
Are you working with the Slim test system? ColumnFixture requires the Fit test system. http://fitnesse.org/FitNesse.UserGuide.TestSystems
With Slim test system, use the DecisionTable http://fitnesse.org/FitNesse.UserGuide.SliM.DecisionTable
So your test will look like:
!|script|SomeTest|
|Goto|$Url|
|check|IsAt|IndexPage|true|
!|SomeTest|
|Index|CheckUserOrder?|
|0|Name1|
|1|Name2|
You are trying to combine a script and a decission table. If you are doing a script table, I expect you would have:
!|script|SomeTest|
|Goto|$Url|
|check|IsAt|IndexPage|true|
|check|CheckUserOrder|0|Name1|
|check|CheckUserOrder|1|Name2|

Multiple fitnesse fixtures possible

Is it possible to use multiple fitnesse fixture classes in one testtable (a scriptable i.e.) as in something like the following?
|script|FixtureClassOne,FixtureClassTwo|
|AMethodInFixtureClassOne|2|
|AMethodInFixtureClassTwo|2|
This is possible. You should load the fixture as a library. E.g.:
| import |
| my.fixtures.classpath |
| library |
| fixture 1 |
| another fixture |
| script |
| etc. |
No need to provide a fixture after the 'script' identifier anymore.
You do have to be aware that if the fixtures share non-unique method names you get into trouble
Objective: To have Multiple Fixtures associated with a single HTML Test Case
How: As you are working with fitnesses HTML Test case, you probably have at least a single fixture associated with it, which we will call default Fixture.
But in order to access another fixture (where control of execution passes to the other fixture), write a method in the default fixture class:
public Fixture run(String str) {
try {
Fixture fixture = Fixture.loadFixture(str);
return fixture;
} catch (Throwable e) {
// put your error handling here
e.printStackTrace();
}
return null;
}
From the Test case, pass the fully specified location with the project to the run() method. When the run() method returns the fixture to the HTML test case, it passes its execution via the new Fixture.

Using new Groovy Grape capability results in "unable to resolve class" error

I've tried to use the new Groovy Grape capability in Groovy 1.6-beta-2 but I get an error message;
unable to resolve class com.jidesoft.swing.JideSplitButton
from the Groovy Console (/opt/groovy/groovy-1.6-beta-2/bin/groovyConsole) when running the stock example;
import com.jidesoft.swing.JideSplitButton
#Grab(group='com.jidesoft', module='jide-oss', version='[2.2.1,)')
public class TestClassAnnotation {
public static String testMethod () {
return JideSplitButton.class.name
}
}
I even tried running the grape command line tool to ensure the library is imported. Like this;
$ /opt/groovy/groovy-1.6-beta-2/bin/grape install com.jidesoft jide-oss
which does install the library just fine. How do I get the code to run/compile correctly from the groovyConsole?
There is still some kinks in working out the startup/kill switch routine. For Beta-2 do this in it's own script first:
groovy.grape.Grape.initGrape()
Another issue you will run into deals with the joys of using an unbounded upper range. Jide-oss from 2.3.0 onward has been compiling their code to Java 6 bytecodes, so you will need to either run the console in Java 6 (which is what you would want to do for Swing anyway) or set an upper limit on the ranges, like so
import com.jidesoft.swing.JideSplitButton
#Grab(group='com.jidesoft', module='jide-oss', version='[2.2.1,2.3.0)')
public class TestClassAnnotation {
public static String testMethod () {
return JideSplitButton.class.name
}
}
new TestClassAnnotation().testMethod()
I finally got it working for Groovy Shell (1.6.5, JVM: 1.6.0_13). This should be documented better.
First at the command line...
grape install org.codehaus.groovy.modules.http-builder http-builder 0.5.0-RC2
Then in groovysh...
groovy:000> import groovy.grape.Grape
groovy:000> Grape.grab(group:'org.codehaus.groovy.modules.http-builder', module:'http-builder', version:'0.5.0-RC2')
groovy:000> def http= new groovyx.net.http.HTTPBuilder('http://rovio')
===> groovyx.net.http.HTTPBuilder#91520
The #grab is better used in a file than the shell.
Ok. Seems like this a short working demo (running from the groovyConsole)
groovy.grape.Grape.initGrape()
#Grab(group='com.jidesoft', module='jide-oss', version='[2.2.1,2.3.0)')
public class UsedToExposeAnnotationToComplier {}
com.jidesoft.swing.JideSplitButton.class.name
When run it produces
Result: "com.jidesoft.swing.JideSplitButton"
Very cool!!
The import statement must appear after the grabs.
Ps. At least one import statement must exists after the grabs
#Grab(group='com.jidesoft', module='jide-oss', version='[2.2.1,)')
import com.jidesoft.swing.JideSplitButton
public class TestClassAnnotation {
public static String testMethod () {
return JideSplitButton.class.name
}
}
Different example using latest RC-2 (note: Grab annotates createEmptyInts):
// create and use a primitive array
import org.apache.commons.collections.primitives.ArrayIntList
#Grab(group='commons-primitives', module='commons-primitives', version='1.0')
def createEmptyInts() { new ArrayIntList() }
def ints = createEmptyInts()
ints.add(0, 42)
assert ints.size() == 1
assert ints.get(0) == 42
Another example (note: Grab annotates getHtml):
// find the PDF links in the Java 1.5.0 documentation
#Grab(group='org.ccil.cowan.tagsoup', module='tagsoup', version='0.9.7')
def getHtml() {
def parser = new XmlParser(new org.ccil.cowan.tagsoup.Parser())
parser.parse("http://java.sun.com/j2se/1.5.0/download-pdf.html")
}
html.body.'**'.a.#href.grep(~/.*\.pdf/).each{ println it }
Another example (note: Grab annotates getFruit):
// Google Collections example
import com.google.common.collect.HashBiMap
#Grab(group='com.google.code.google-collections', module='google-collect', version='snapshot-20080530')
def getFruit() { [grape:'purple', lemon:'yellow', orange:'orange'] as HashBiMap }
assert fruit.inverse().yellow == 'lemon'

Resources