views:

312

answers:

2

Hi, I need to pass an object (my own business object) between two tables in one page. The value is got from the getter call in one fixture and then should be used as field in another fixture (both ColumnFixtures). Please note that the object to be passed is neither primitive nor String and the conversion is not that simple. Is it even possible? If so, then how?

+1  A: 

Supposing you have two column fixture tables such as:

|TableOne            |
|inputOne|outputOne()|
|7       |14         |

and

|TableTwo            |
|inputTwo|outputTwo()|
|6       |20         |

then in the corresponding code you can store the object you wish to pass in a static variable (I'm using an int here but any type will work):

public class TableOne extends fit.ColumnFixture {
    public static int result;
    public int inputOne;
    public int outputOne() {
        result = inputOne * 2;
        return result;
    }
}

public class TableTwo extends fit.ColumnFixture {
    public int inputTwo;
    public int outputTwo() {
        return TableOne.result + inputTwo;
    }
}

Instead of using ColumnFixtures, however, I recommend that you look into Rick Mugridge's fitlibrary (in particular DoFixture) which allows fixtures to communicate in a more elegant way.

Matthew Murdoch
A: 

I'll check the fitlibrary, thanks. In the meantime, I have just found different and possibly better way:

use the fit API and save the value into the symbols map. You can just set the key for the map via regular field and then retrieve it like this: Fixture.setSymbol(...) and then Fixture.getSymbol(...). The above mentioned methods are static as well, but this approach offers a bit more flexibility, because the variable value is not hard wired in the code, but rather indexed in a map:-)

Petr Macek