I am trying to learn Playwright for api and web testing using Java. So far with api testing I am getting a weird issue where I am getting the following errors for all of my requests:
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>
Here is my code:
Playwright playwright = Playwright.create();
APIRequestContext request;
Map<String, String> headers = new HashMap<>();
headers.put("Content-Type", "application/json");
request = playwright.request()
.newContext(new APIRequest.NewContextOptions()
.setBaseURL("https://petstore.swagger.io/v2/store")
.setExtraHTTPHeaders(headers)
);
Map<String, String> body = new HashMap<>();
body.put("id","400");
body.put("petId","731368479");
body.put("quantity", "4");
body.put("status","placed");
body.put("complete", "true");
APIResponse addNewPet = request.post("/order",
RequestOptions.create().setData(body));
System.out.println(addNewPet.text());
// assertTrue(addNewPet.ok());
// assertEquals(200, addNewPet.status());
playwright.close();
I am not sure where and what I am doing wrong. Thanks in advance.
CodePudding user response:
Seems to be working if you add the slash at the end of the baseURL and remove it from the post url:
...
.setBaseURL("https://petstore.swagger.io/v2/store/")
...
APIResponse addNewPet = request.post("order",
...