TestProject Forum
Powered by leading experts in the test automation community

Secret Project Parameter in Java code

How do you set up a secret parameter in a java project? When I generated the code the ProjectParameters.java file it shows as:

public static String testPassword = "";

But when I upload it to TestProject and run it it looks like it does not type in the entire password and then it fails. I tried putting a pause before it and the same error occurred. Is there something I am doing wrong in my code? Other Test parameters work fine. Only one failing is the secret project parameter I have set up.

Hello @daniela and thanks for reaching out.

When you generate code using secret parameters you have set up through the UI, their values will be removed from the code itself:

  @Parameter(
  description = "This was a SECRET parameter and therefore its value is empty",
  direction = ParameterDirection.INPUT )
  public String MY_SECRET_PARAM;

If you’d like your values to remain hidden when uploading your code to the platform, you can opt out on reporting them explicitly when writing your code and using the TestProject reporter from the SDK, so they won’t appear in your test execution reports.

How about for a parameter that is set up as a project parameter?


On my ProjectParameter.java file this is how my project parameter is set up. How do I get this to connect to the project parameter in TestProject?

A generated coded test is static code.
It will not communicate with parameters in your projects.

So if I generate code for a test and add more code in there. When I upload it and run it it will not be able to interact with the project parameters? I have to just create a regular parameter in the code for it to work?

That’s one approach.

You can also create input parameters for your test using the syntax at the start of this thread, and then use input parameters from your project/test when calling these coded tests as nested tests in recorded tests:

2

3

Another possible approach is to use the TestProject API to retrieve/edit the values of projects parameters from your code (for non-secret parameters).

https://api.testproject.io/docs/v2/#/ProjectParameters/ProjectParameters_GetProjectParameterAsync

I see so you’re saying make a separate test just for logins. Then include that test in the test I’m coding so that I don’t need to worry about affecting the secret password. Is that correct?

But when I upload it won’t I run into the same issue with it not saving the parameter value and then it won’t pick up the project parameter? Can you just explain that resolution a bit further?

Hi @daniela,

What I meant was, you can code your test with input and output parameters, and upload that test onto the platform.

From there, you can use your coded test inside recorded tests, and pass into that coded test, parameters you have defined in your project through the UI.

In the example above, I uploaded my coded test, and defined that test to have an input parameter, and when I use it in my recorded tests as a nested test, I can pass as the input to it, my secret project parameter, same as I would be able to for any other action.

If you would like to change project parameter values, you can create output parameters in your coded test and select the output of the step to be stored in your project parameter.

1 Like