0

I'd like to set the baseUrl for a table based on the outcome of another test (on the same page). I tried following these pages of Fitnesse's docs (and other resources) : smartrics blog post, fitnesse symbols page, but I can't seem to get it working. So far I've tried with the following syntaxes :

| Fit Rest Fixture | %emailLink% | | GET | / | 200 |Content-Type: text/plain|Email Verified|

| Fit Rest Fixture | emailLink= | | GET | / | 200 |Content-Type: text/plain|Email Verified|

| Fit Rest Fixture | $emailLink | | GET | / | 200 |Content-Type: text/plain|Email Verified|

but none of those work. I know that the emailLink symbol is not null because I'm testing it in another table, but I can't seem to inject it into the RestFixture. I always get an IllegalArgumentException indicating that the symbol name has not been resolved against its value, e.g. java.lang.IllegalArgumentException: Malformed base URL: $emailLink

Any help would be appreciated.

francesco foresti
  • 2,004
  • 20
  • 24
  • I believe you are using Fit (not Slim) as test system. Is this correct? Do you have the option to switch to Slim (this will affect all fixtures you can use)? I don't know how to do (without custom code in fixtures) what you want using Fit. – Fried Hoeben Nov 17 '16 at 13:16

2 Answers2

0

Are you using slim?

http://www.fitnesse.org/FitNesse.UserGuide.WritingAcceptanceTests.SliM.SymbolsInTables

I have used symbols in this way a few time with Slim, but not the REST Fixture specifically.

Jim Weaver
  • 983
  • 5
  • 15
  • Hi, thanks for your answer. Unfortunately I've already tried that syntax (see the 3rd example in the question) and it doesn't work. – francesco foresti Nov 16 '16 at 08:20
  • When you test it in another table, what does the output look like on test results page? If you test the value in a decision table then you should be able to see the evaluated result in the test output. – Jim Weaver Nov 16 '16 at 10:48
  • Given the name of the fixture '*Fit* Rest Fixture' I believe his test is using Fit, which explains why the Slim approach does not work. – Fried Hoeben Nov 17 '16 at 13:14
  • Yes, if he is using fit rather than slim this syntax should work: http://www.fitnesse.org/FitNesse.UserGuide.WritingAcceptanceTests.FitFramework.SymbolsInTestTables, but the examples provided use column fixture cells to both set the key value and render it. I'm not sure about including the "key=" type syntax in a table header as a parameter to the fixture. – Jim Weaver Nov 18 '16 at 03:25
0

By taking a look at the code of FitRestFixture and fiddling with it, I've come up with something that works for me. It seems that the feature I was looking for is not supported out of the box, but can be easily achieved (although this way is not the cleanest) with a simple mod such as the following :

/**
 * @return Process args ({@link fit.Fixture}) for Fit runner to extract the
 * baseUrl of each Rest request, first parameter of each RestFixture
 * table.
 */
protected String getBaseUrlFromArgs() {
    String arg = null;
    if (args.length > 0) {
        arg = args[0];
        /* mod starts here */
        if (isSymbol(arg)) {
            String symbolName = stripSymbolNotation(arg);
            arg = resolveSymbol(symbolName);
        }
        /* mod ends here */
    }
    return arg;
}

private boolean isSymbol(String arg) {
    // notice that I've used the '<<' notation convention to extract the 
    // the value from a symbol, while in RestFixture the conventional 
    // notation is %symbolName%
    return null != arg && arg.startsWith("<<");
}

private String stripSymbolNotation(String arg) {
    return arg.substring(2);
}

private String resolveSymbol(String arg) {
    String symbolValue = (String) Fixture.getSymbol(arg);
    LOG.warn(String.format("resolved symbol %s to value %s", arg, symbolValue));
    return symbolValue;
}
francesco foresti
  • 2,004
  • 20
  • 24