Submit and vote on feature ideas.

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.

How to access environment variable in Databank

Parasofttoudaya
Parasofttoudaya Posts: 232 ✭✭

Hi Team

I am using concat function in databank xpath evaluation, where i need to fetch the environment variable value. How to do it?

These are the below things i tried.

${soa_env:Environment}
${Environment}
Note: Environment is a environment variable. ( I was able to refer in all the test clients.)

Comments

  • Parasofttoudaya
    Parasofttoudaya Posts: 232 ✭✭

    Any update on this??

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    To the best of my understanding, variables do work in XPaths used for extractions. You may want to contact Parasoft support if you need further help. Otherwise, you may want to provide more detail in case you are looking for an answer from someone in the community.

  • Parasofttoudaya
    Parasofttoudaya Posts: 232 ✭✭
    edited September 2017


    Hope this image helps for better understanding

  • grigorb
    grigorb Posts: 17

    I can see you miss a closing } in environment variable.
    concat(${variable}, "")

  • Parasofttoudaya
    Parasofttoudaya Posts: 232 ✭✭

    That was a typo, still i am getting the error.
    Cannot evaluate. Not a valid XPath expression.
    Have you tried this option?

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭
    edited September 2017

    Two things:

    First, your XPath is not valid. The concat function takes a string. Put your variable reference in double quotes since you are passing it as an argument to concat.

    Second, the UI won't resolve the variable, like when clicking Evaluate XPath. However, the variable will be resolved at runtime when your test suite is actually being executed. In other words, there may still be cases where clicking Evaluate XPath may show an error when the XPath will be valid at test suite execution when variables can be resolved. However, as mentioned, I suspect you probably want your variable in double quotes to make it a proper string unless the variable's value already happens to be quoted.

    This works for any type of variable (environment variable, test suite variable, data bank column, data source column, etc.)

  • Parasofttoudaya
    Parasofttoudaya Posts: 232 ✭✭


    I tried all the possibilities and run time option as well.. it was not working..

    After the error is gone, I tried printing to console using extension tool and got nothing. :(

    Have you tried accessing in this way??

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    Are you sure the variable is spelled correctly? Your active environment has a variable name "Environment"?

  • Parasofttoudaya
    Parasofttoudaya Posts: 232 ✭✭

    Yes it is..

  • benken_parasoft
    benken_parasoft Posts: 1,228 ✭✭✭

    After the error is gone, I tried printing to console using extension tool and got nothing.

    You mentioned "error is gone". I assume you mean the XPath error is not being reported, right? If this is the case then perhaps you are doing something wrong in your extension tool.

  • OmarR
    OmarR Posts: 233 admin
    edited September 2017

    Okay.....lets try this again. Can you please confirm this setup on your end?

    concat( ' {"${myEnv}": ' , ' " ' , /root/pennywise[1]/text() , ' " ', ' } ' )

  • Parasofttoudaya
    Parasofttoudaya Posts: 232 ✭✭

    Your setup is correct.. But my expectation result after the evaluation is

    {"pennywise":"pennywise"}

    I need the value of myEnv variable to be replaced here in evaluation.

  • jakubiak
    jakubiak Posts: 795 admin

    As stated by @benken_parasoft, the environment variable does not get resolved when you click "Evaluate XPath". But it will still get resolved at runtime if you have specified it correctly.

  • Parasofttoudaya
    Parasofttoudaya Posts: 232 ✭✭

    OOPS, Its working as expected.
    There was a problem with extension tool.
    I am terribly Sorry about it.

  • OmarR
    OmarR Posts: 233 admin

    Yes, the xpath may not evaluate successfully in the result window, but it will parameterize as expected during run time. Run your test with this updated setup and verify the result.