TestProject Forum

Set variable in a subtest, use it everywhere

What I want to do:
Having a “test“ that never gets executed standalone. It contains all definitions, like:

// This is ‘_config.test’
set ‘johndoe’ into name
set ‘topsecret’ into password

Then, in my “real test“, I want to use that variables:
include_test ‘_config.test’
document.querySelector(’#username’).value=’{name}’;
document.querySelector(’#password’).value=’{password}’;
document.querySelector(’#submitButton’).click();

But, whatever I do, the parameters from the config-test don’t get exported to outside that test to “real test”. When I want to use a parameter in “real Test“, I always only get offered the local “ApplicationURL“, but not my variables from the subtest.

How do I deal with variables that are global to a test execution?

This is a very basic example. In real testing I want to set a variable not only constant, but use something like “running 20 lines of Javascript to find an invoice number in the displayed text and return it in a variable so I later can use it in an URL fragment“ or similar complicated.

Hello @joerg.rossdeutscher
I do not quite understand your example, first, are you writing a coded test or using the recorder?
If you can provide some actual screenshots as well can help.

I am writing tests manually.
I am not allowed to post 2 screenshots in a single post here :frowning: so I have to describe it:

The test “_config“ contains only 1 Step:

ACTION: Set value to a parameter
Value: “PDP“
OutputParameter: “query“

I expected to export the value “PDP“ to the parameter “query“ to use it in any other test by including the test “_config“.

This is my test:2021-02-16 at 16.37

Expectation: Empty page, containing the word “PDP“, because that’s the value of {query}.
Is: Page contains the plain text “{query}“

In _cnofig test, you can set the parameter to be output, that way, the main test can use the output from that test:
image

Thanks alot, I’ll try that out.
I didn’t find documentation what “Input“ and “Output“ means, can you turn me in the right direction?

Sure, here you go
https://docs.testproject.io/getting-started/create-a-test-step/using-parameters-in-test-steps#input-and-output-parameters