Can you help me with sample code to pass http post request in session..?

Hello All,
I have a requirement to handle dynamic pop-ups to continue the flow of web application, there are few dynamic values in the dynamic pop-up which needs to be handled properly.
So, could you help me with a sample code to pass an HTTP post request in session?
/Thanks
Srini

Hello Srini,

Welcome to the Gatling Community! As a bit of background we require a bit more information for posts and generally don’t provide code samples. What we ask you to do is try it yourself by using your best understanding of the documentation first and then help correct any errors if there are any. This way you’ll learn instead of someone else providing code for you.

I recommend starting in the Gatling documentation here: Gatling - HTTP Request, as it sounds like what you’re looking for and includes examples in code in Java Scala and Kotlin.

Thanks and have a great day,
Pete

The Gatling documentation here: Gatling - HTTP Request is availble for Scala and Java.

Regards,

Thank you for your response.!

I actually tried and here is my code sample.

POST Request#1

POST Request#2

POST Request#3 (dynamic pop-up while filling the SAP form)

POST Request#4

Request Sample,
the SAPEVENTQUEUE has dynamic values that must be extracted from run time and passed on to the next request.

.exec(
      http("request_41")
        .post("/sap/bc/webdynpro/SAP/BS_OVP_BP?sap-contextid=#{sapcontextid86}")
        .headers(headers_27)
        .formParam("sap-charset", "utf-8")
        .formParam("sap-wd-secure-id", "#{sapwdsecureid86}")
        .formParam("fesrAppName", "BS_OVP_BP")
        .formParam("fesrUseBeacon", "true")
        .formParam("SAPEVENTQUEUE", "ComboBox_ListAccess~E002Id~E004WD05E4~E005ItemListBoxId~E004WD05E5~E005FilterValue~E004YFLCU0~E005OptimalNumberOfItems~E00410~E005Explicit~E004false~E003~E002ResponseData~E004delta~E005ClientAction~E004submitAsync~E003~E002~E003~E001Form_Request~E002Id~E004sap.client.SsrClient.form~E005Async~E004true~E005FocusInfo~E004~0040~007B~0022iSelectionStart~0022~003A6~002C~0022iSelectionEnd~0022~003A6~002C~0022iCursorPos~0022~003A6~002C~0022sValue~0022~003A~0022YFLCU0~0022~002C~0022bEditMode~0022~003Atrue~002C~0022sFocussedId~0022~003A~0022WD05E4~0022~002C~0022sApplyControlId~0022~003A~0022WD05E4~0022~007D~E005Hash~E004~E005DomChanged~E004false~E005IsDirty~E004true~E003~E002ResponseData~E004delta~E003~E002~E003")
     //  

Here is my session code

.exec(
                    session->
                    {
                     String Response42;
                      if (session.getString("Response_42").contains("Duplicates Found")) {
                        System.out.println("Enterred into the loop");
                        exec(
                                http("duplicate")
                                        .post("/sap/bc/webdynpro/SAP/BS_OVP_BP?sap-contextid=#{sapcontextid86}")
                                        .headers(headers_77)
                                        .formParam("sap-charset", "utf-8")
                                        .formParam("sap-wd-secure-id", "#{sapwdsecureid86}")
                                        .formParam("fesrAppName", "BS_OVP_BP")
                                        .formParam("fesrUseBeacon", "true")
                                        .formParam("SAPEVENTQUEUE", "Button_Press~E002Id~E004#{duplicate}~E003~E002ResponseData~E004delta~E005ClientAction~E004submit~E003~E002~E003~E001Form_Request~E002Id~E004sap.client.SsrClient.form~E005Async~E004false~E005FocusInfo~E004~0040~007B~0022sFocussedId~0022~003A~0022#{duplicate}~0022~007D~E005Hash~E004~E005DomChanged~E004false~E005IsDirty~E004true~E003~E002ResponseData~E004delta~E003~E002~E003")
                                        //   .check(bodyBytes().is(RawFileBody("qm1/nrc28responsebody/0077_response.dat")))
                                        .check(bodyString().saveAs("duplicateResponse"))
                        );
                        System.out.println("duplicateResponse          " + session.getString("duplicateResponse"));

I have trouble with POST requests inside the session ->.

Could you help me this…? Is my above code is correct…?

Hi @Srini,

Your exec inside a custom function won’t work.

As stated in the first alert in the DSL concepts:

The components of this DSL are mere definitions of the desired effect. They don’t generate the desired effect where you invoke them in your own code. Only when chained with other components so they are ultimately passed to the setUp, can the Gatling engine interpret them and produce the desired effect.

In your case, I think that doIf may be the solution.

Cheers!

Thank you.!
I will try with “doIf”

And the soluce is? :blush:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.