How to access environment variable in Databank

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

  • Any update on this??

  • benken_parasoftbenken_parasoft Posts: 343 ✭✭✭

    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.

  • ParasofttoudayaParasofttoudaya Posts: 164
    edited September 2017


    Hope this image helps for better understanding

  • grigorbgrigorb Posts: 13

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

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

  • benken_parasoftbenken_parasoft Posts: 343 ✭✭✭
    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.)


  • 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_parasoftbenken_parasoft Posts: 343 ✭✭✭

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

  • Yes it is..

  • benken_parasoftbenken_parasoft Posts: 343 ✭✭✭

    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.

  • OmarROmarR Posts: 177 admin
    edited September 2017

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

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

  • 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.

  • jakubiakjakubiak Posts: 215 ✭✭✭

    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.

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

  • OmarROmarR Posts: 177 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.

Sign In or Register to comment.