How to save a string coming from a HTML response

Hi everyone,

i’m here to ask you if there’s a way to store in a variable a dynamic string that is generated in the response of a rest API (POST) in HTML format. I have to use the saved string in the body of another request.
How can i do?
Thank You :slight_smile:

You need to achieve the following 3 tasks:

  1. pick up a string value from the response of a REST API.
  2. put a string into an INPUT element in a HTML page.

and then

  1. combine the1 and 2 above.

So, I would ask you

Can you write a code that achieves the task1? If yes, please show your code here.

Can you write a code that achieves the task2? If yes, please show your code here.

hi, i’m not able to write any code since i’m not a programmer. I have to use the string extracted from the reponse of the first post api in the body of another post request. Thank you :slight_smile:

Katalon Studio, and any other tools possibly, does not provide a solution out of box.

If you want to achieve what you want to do, you need to be a programmer.

Possibly now is the time for you to start studying programming.

Why not you try to write a code that does:

  1. pick up a string value from the response of a REST API.

If you encounter error, then show us your code, error log, and the JSON/XML response to us. Possibly somebody would give you advices.

Please keep this in mind — No code, no advice.

The response is in HTML format, is there any parser that i can use? Json slurper only works with Json i think.

You can use getText(TestObject) keyword.

I am curious what it is: a REST API response in … HTML? neither Json nor XML?

Is it a page which tells you “Bad request. Unable to accept your request” ?

It is a post request that gives a html response. Its a radlogin software page that gives infos on authentication. Some of that info must be reused in another post request to make an accounting start (on Radius Server).

since i’m using the webservice part, how can i use the GetText fkeyword?

You can call WebUI.* keywords and WS.* keywords mixed in a Test Case. No problem.

You want

WebUI.openBrowser(“starting url “)
WebUI.verifyElementPresent(findTestObject(“name of the Test Object which points the element of your interest”, timeout))
String s = WebUI.getText(findTestObject(”…”))
// pass value of the variable “s” into the REST Request, and then
Response res = WS.sendRequest(…)

Just try to write your test case manually in the Script mode.
Please mind, you need to write the required import statements.

Thank you, i tried you solution but katalon gives me an error:

Test Cases/Prova_ACCT_id FAILED.
Reason:
groovy.lang.MissingMethodException: No signature of method: Script1657186951485.string() is applicable for argument types: (java.lang.String) values: [“1657204950L12tsw”]
Possible solutions: toString(), toString(), print(java.lang.Object), print(java.io.PrintWriter), sprintf(java.lang.String, java.lang.Object), print(java.lang.Object)
at Prova_ACCT_id.run(Prova_ACCT_id:48)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:442)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:433)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:412)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:404)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:281)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1657204877622.run(TempTestCase1657204877622.groovy:25)

i ended up writing result = WebUI.getText(findTestObject(”…”)) and it works but it extract the id between the “”. How can i extract only the value without the “”?

You want to get started with WebUI testing in Katalon Studio. See

Recorder tool will let you get started, but not enough.

You, a programmer, should change the test case editor from “Manual mode” to “Script mode”, edit the test case script in the Script mode, so that the test case can deal with the URL of your target application.

In order to write appropriate code, you are required to read and understand HTML source code of your target web page.

In order to read HTML source, you should learn how to use DevTools of web browser.
Have a look at the following tutorial.

As for XPath, the following tutorial would be good:

As for CSS Selector, … well, there are hundreds and thousands of tutorials for CSS on the Internet. Whichever you like will do.

Enjoy!