Using a test case variable in setupTestCase()?


I have a variable called foo defined for a test case, which the test case can access and use as expected. It is bound to a data source (SQL) and populates the right value on each test case executed by a test suite.

Now, there is a setupTestCase() handler in test suite script that can do stuff before each test case is run. In my situation, I want to be able to access foo within this setupTestCase() method to do some stuff to set up my test. Is this possible, or can foo only be referenced from within the test case itself? (I tried a few ideas but the test suite method is looking for some foo variable as a property of the test suite and errors out).

@mcavagnaro I believe you can pass Global Variables between Test Suite and Test Case if import statement is in both.

import internal.GlobalVariable as GlobalVariable

Like user @helpdesk suggests, you could use a GlobalVariable. Your Test Case variables are not available during suite setup, since no test is available yet.

You might consider using a @BeforeTestSuite (listener) instead and use a Custom Keyword to retrieve your DB data into a global variable OR define a static var which is available everywhere.

You need to do a little reading to understand the options. Write back if you have more questions.

See under the heading Test Listeners (Test Hooks)

For Custom Keywords…