[Katalon Profile] Dynamic Profile update upon execution

Hi Team,

Can we update the profile value for a dynamic field during execution please?

Scenario: I have an email address in my profile and after each execution, I want to update that value in my profile to match one used during execution.

Thanks

1 Like

There are many (well, a few) ways you can modify those variables. I think from your description, Test Listeners might be what you’re looking for:

https://docs.katalon.com/pages/viewpage.action?pageId=5126383

GlobalVariable.email = 'execution@email.com'

N.B. GlobalVarable.email needs to be defined prior to test execution.

Hi Russ,
Thanks much for feedback. Yes - I’ve tried with Test Listeners but that does not meet my requirements.

My issue is that I want to write a specific value to one field in my execution profile after each execution. Same manual flow as go to profile and edit field’s value with some new string.

That’s is after test execution, that field (For ex: Email) in my profile will have its value updated with the one used while execution.

Thanks for helping.
Youven

Mate Mrse said:

GlobalVariable.email = 'execution@email.com'

N.B. GlobalVarable.email needs to be defined prior to test execution.

This will update the GlobalVariable.email field, but only for the duration of the test. So, I guess this is not what you were looking for.

Hi Mate,

Yes - unfortunately. I want the updated value to be ‘written’ in my execution profile so that I can know which last value has been used.

For ex: My email field firstly contains (test100@xxx.com) and during execution I updated this value to (test101@xxx.com).

Here, I want value (test101@xxx.com) to be written in my profile used for field email.

Thanks
Youven

There is a way to do that, and I’ve lost the post that explained it. Sorry.

I think it was a post either by Kazurayam or Marek… if they’re reading, perhaps they’ll refresh my memory an help you.

Kazurayam here.

Russ possibly mentioned about the following post of mine:

-----------------------

Youven,

(1) Katalon Studio does NOT support saving the updated GlobalVariable value.

(2) I do not think it is feasible that your custom script modify the Execution Profile files directly on disk because the file format is not publicly documented and looks complicated enough.

(3) Here I propose to you a resolution. You want to prepare a custom file where you write any name=value pairs you want in any format such as Java Properties, JSON, CSV or whatever. You want to write a Groovy Script (possibly in a Test Listener method annotated with @BeforeTestSuite) which reads your custom file on startup. The script will update the Execution Profile (=Global Variables) in process with the values obtained from your custom file. This is the approach I studied in the above mentioned post.

(4) If you want save the values you used and pass them to the next test execution, why not you write a Groovy script (possibly in a Test Listener @AfterTestSuite method) which updates your custom file on disk with new values. This needs to be done for yourself. Katalon Studio does not help but would not disturb you. Once the file is updated, then you go back to the step (3).

1 Like

Hi Kazurayam,

Thanks for above solution - I will proceed with the point 3 above and provide feedback if successful.

One additional solution am thinking of is after each test run, I loop into the profile’s glbl XML file and update the Email field node with the test execution value.

The glbl file will be updated and perform a project refresh to get updated file.

Thanks
Youven

Hi there,

in my tests I need to get the headers (a string) of a specific call to an http endpoint and then pass them onto another http endpoint call. Global variable here useless being conceived as they were (I hope for the moment).
In order to overcome this situation I wrote a groovy keyword which parses the execution profile (glbl/xml) file and saves the new values of the global variable previosuly created.
Everything works smoothly: the parsing is ok and the glbl file is correctly updated.
It seems though the old value is used. Any input here? Any way to refresh it?

Thanks in advance!
Victor

Youven wrote:

One additional solution am thinking of is after each test run, I loop into the profile’s glbl XML file and update the Email field node with the test execution value.
The glbl file will be updated and perform a project refresh to get updated file.

There is one more file you need to look at. That is,

  • /Libs/internal/GlobalVariable.groovy

Katalon Studio updates the GlobalVariable.groovy file from *.glbl when you create/modify the definition of Profiles through GUI interaction. Groovy codes as test cases refers to the Groovy class defined by the GlobalVariable.groovy file, not XML

In order to accomplish what you want to do, your keyword have to update /Libs/internal/GlobalVariable.groovy file as well as profile.glbl file.

1 Like

Victor,

I think that Execution Profile in Katalon Studio is designed read-only for test cases. It is not designed to be updated by test cases runtime.

You can create a json text file in the project directory. I think that a json file would be much easier storage for your dynamic information than modifying Execution Profiles. You can save a json file anywhere in the projectDir; for example /tmp, or /Data Files/. I myself would write it into /Materials folder using my Materials library.

Writing and reading a JSON file is quite easy in Groovy. A sample code from https://gist.github.com/keyle/723181f3a9a59a3f7652

package utils
import groovy.json.JsonBuilder
import groovy.json.JsonSlurper
class HDD {
    static save(Object content, String filePath) {
        new File(filePath).write(new JsonBuilder(content).toPrettyString())
    }
    static Object load(String filePath) {
        return new JsonSlurper().parseText(new File(filePath).text)
    }
}

2 Likes

Hi kazurayam,

thanks a lot for your feedback, at first I had thought of a text file, but a json could be surely better.
I ended up modifying the glbl just not to move much away from the original solution. I hadn’t considered the globalvariable.groovy file though.

Thanks again.

Victor

@Youven_ankiah I think you want to do want I did here in my post mate.

Iterating my email global variable on every time the suit end and upload the profile execution at the finish. So, If I run the suit 3 times, will run the suit with this variable iterated 3 times