Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Using variable preceded by backslash

PBeland
PBeland Posts: 14
edited April 2017 in SOAtest

I'm trying to assert on a xml tag that should contain a file path. I configure a String Comparison Assertion "Element must contain/Expected value/Fixed" with the following value:
${rootfolder}\${variablefolder}\filename.xml.

This gives an error message like "should contain expected value: C:\source${variablefolder}\filename.xml".
--> stripping one backslash and not interpreting the variable.

If I double the preciding backslash, I get an error mesasge like "should contain expected value: C:\source\${variablefolder}\filename.xml".
--> the backslash is there but the variable is still not interpreted.

Putting any other character in front of the variable makes it interpreted but now there is an extra charater in my path...

Is there an escape character for that?

Tagged:

Comments

  • jakubiak
    jakubiak Posts: 810 admin

    Backslash before "${" is used to tell SOAtest not to treat it as a variable - and there is no way to do special escaping to do what you are trying to do. However, there is another way to do it. Instead of a String Comparison Assertion, create a Custom Assertion. Assuming the variables are environment variables, you can use the following Groovy script:

    import com.parasoft.api.*;
    
    public boolean doAssertion(String str, ScriptingContext context) {
        return str.equals(context.getEnvironmentVariableValue("rootfolder") + "\\" + context.getEnvironmentVariableValue("variablefolder") + "\\filename.xml");
    }
    

    Assuming the variables are data source values, the script would look like:

    import com.parasoft.api.*;
    
    public boolean doAssertion(String str, ScriptingContext context) {
        return str.equals(context.getValue("DS Name", "rootfolder") + "\\" + context.getValue("DS Name", "variablefolder") + "\\filename.xml");
    }
    

Tagged