0

I sent a post request with a payload as per below, and when I printed requestContext, its value was com.microsoft.playwright.impl.APIRequestContextImpl@771a660.

I just want to print exact request with payload , for tracking purposes.

import com.microsoft.playwright.APIRequest;
import com.microsoft.playwright.APIRequestContext;
import com.microsoft.playwright.APIResponse;
import com.microsoft.playwright.Playwright;
import com.microsoft.playwright.options.RequestOptions;
import org.json.JSONObject;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.IOException;

public class PostJSONObjectSimple {
    Playwright playwright;
    APIRequest request;
    APIRequestContext requestContext;

    @BeforeClass
    public void setup() {
        playwright = Playwright.create();
        request = playwright.request();
        requestContext = request.newContext();

    }




    @Test
    public void createUserTest() throws IOException {

        // Create a JSON object to store the payload
        JSONObject payloadJson = new JSONObject();

        // Add fields to the JSON object
        payloadJson.put("name", "John Doe");
        payloadJson.put("job", "IT Manager");

        // Create a request options object

        APIResponse apiPostResponse = requestContext.post("https://reqres.in/api/users",
                RequestOptions.create()
                        .setHeader("Content-Type", "application/json")
                        .setData(payloadJson)
        );
        // Check the response status code
        Assert.assertEquals(apiPostResponse.status(), 201);
        System.out.println(requestContext.toString());
Sameera De Silva
  • 1,722
  • 1
  • 22
  • 41

0 Answers0