AdeelM avatar image
AdeelM asked AdeelM posted

Can I use global variable in [query] command?

I have developed a response map for my response. I store the response in a variable using Store Response step property and make it a global variable. Say the variable name is "testcase_data".


How do I access this global variable in my query command. I have tried the following:


[query testcase_data (.//value)] --> This returns an error that variable cannot be found. This is understandable because accessing global variable requires the use of gget command.


[query [gget testcase_data] (.//value)] --> This returns an error "Invalid query".


[query \[gget testcase_data\] (.//value)] --> This returns an error "Unable to evaluate".


Any ideas?



iTestresponse map
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

aswinbh avatar image
aswinbh answered aswinbh posted
Thank you all for the response. We've a design issue here if I use the global variables. I have to use "call" to execute the test cases instead of "run" for my global variables to work. But, If I use "call", I won't get test reports per test case and "summarize" also has the same issue. I do need global variables to share data across all test cases and to create my own test reports using few counters(global variables). At the same time I do want individual test case reports generated by iTest. Please let us know how can I go about..
1 comment
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

KumarS avatar image KumarS commented ·



Variables do not make sense across multiple executions. For example, if you have these two executions performed by tcl (you can replace them with your favourite scripting language like perl):


tclsh a.tcl

tclsh b.tcl


The second tcl shell will have no idea about variables and their state in first tcl shell. You can think of "Run" action in iTest as similar. "Run" starts a new execution as if you manually started the execution from itestcli or iTest UI. That is why you get separate reports for "run" actions.


So only way for you to share data across different runs is to use "parameters" - but remember that "parameters" are readonly. You can set a whole bunch of parameters and then use "run" with testcase A and then run testcase B using the same or another set of parameters.

0 Likes 0 ·
YujieL avatar image
YujieL answered YujieL posted

Have you tried using the Query dialog?  Just put your the cell in edit mode, right click and you should see a Insert-->Query on Store response.

This dialog will help you insert a query with the correct syntax.


I've also attached an example that querys a stored response stored as global variable.

example.fftc (1.4 KiB)
puts__hello.ffrm (1.3 KiB)
10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

aswinbh avatar image aswinbh commented ·


Thanks for the response. But, I've another problem here.

I could get the query using "/data"only if we apply the response map in one of the steps of test case. If I apply the response map in a procedure, call the procedure in the test case and use query with "/data", it says "Invalid query".Please let me know if it's allowed or not.


Our basic requirement is, read the input file of the test-suite once and use the querries across the test cases. Please let me know if there's any other way of doing this.

0 Likes 0 ·
YujieL avatar image YujieL aswinbh commented ·
I've attached an example where a test case can access the global variable created by another test case.  In the child test case example.fftc, I added the procedure to the procedure library by going to the Procedure's General Properties and checking the checkbox "Include this procedure when listing callable procedures".  Now I can call the child test case from the parent test case, and use the same query as before.
Message Edited by YujieL on 12-22-2008 02:25 PM
0 Likes 0 ·
parent.fftc (1.5 KiB)
puts__hello.ffrm (1.3 KiB)
example.fftc (1.3 KiB)
KumarS avatar image KumarS YujieL commented ·

Thanks Yujie.


Ashwin - the important thing to remember is that "query" command works on a variable and a variable is defined by a location in an XML document in iTest. Variables inside procedures are only valid for the duration of the procedure call. So you will have to store the response and its mapping information in a global variable. Once you do that, you can use "query" command with "/data/your_global_var_name_here" to access all the queries produced by response mapping anywhere in your testcase.

0 Likes 0 ·
PaulD avatar image PaulD KumarS commented ·

One extra hint:  If you store responses in global variables, you just need to be careful that you don't put these in a huge loop, or something, with unique names for each variable.  That's because this is like a "memory leak" -- in that you will be asking iTest to store more and more information in memory and eventually you could run out.  This is no different than any programming situation.  Just be careful about unlimited memory use -- especially for large responses.

0 Likes 0 ·
ramarb avatar image ramarb aswinbh commented ·

If you would like to use one or two values in each test case from parent suite, then you may opt for passing arguments to procedures. In this case, no need to enable global variable option. I believe there will be no memory leak or performance issues in this case.


Do the following from your parent suite.

    readfile c:\\test-suite.txt (provide response map and store response as 'response in step properties)

    call :: project:///test_cases/new_testcase2.fftc?main -count [query response hello_pattern()] -value [query response col2(3)]


And, access them in your child script directly as $count or $value

0 Likes 0 ·
KumarS avatar image
KumarS answered KumarS posted

Syntax for accessing global variables in a query is:


[query /data/testcase_data (.//value)]


I think we need to clean up the syntax so that user can simply pass in a flag instead of remembering "/data" syntax.

10 |950

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.