I am trying to write a POST request, which works in Postman, as a Playwright test.
During various test runs I have noticed that it does not authenticate my user (no matter if the login is correct or wrong).
I expect a redirect URL, which logs me in on the target page, instead I always get the same default URL back. Furthermore, I only get 2 out of 3 cookies that I receive in Postman.
Does anyone know what the problem is?
import { test, expect, request } from '@playwright/test';
import { json } from 'stream/consumers';
test('IDS POST-Request', async ({}) => {
// New instance
const apiRequest = await request.newContext();
const headers: Headers = new Headers()
headers.set('Cookie', '##########')
headers.set('Content-Type', 'multipart/form-data')
headers.set('Host', '')
headers.set('Accept', '*/*')
headers.set('Accept-Encoding', 'gzip, deflate, br')
headers.set('Connection', 'keep-alive')
headers.set('Content-Type', 'multipart/form-data; boundary=<calculated when request is sent>')
// xml body payload
const payloadXml = `<?xml version="1.0" encoding="UTF-8"?>
#####`;
const form = new FormData()
form.append("name_kunde","#####")
form.append("pw_kunde","#####")
form.append("hookurl","#####")
form.append("action","#####")
form.append("warenkorb",payloadXml)
form.append("version","#####")
const requestOptions: RequestInit = {
method: 'POST',
headers: headers,
body: form,
redirect: 'manual'
};
await fetch(`##### URL #####`, requestOptions)
.then(response => {
// Response status
console.log('Status', response.status)
const responseHeaders = response.headers // for each constante
responseHeaders.forEach((value, key) => {
console.log(`${key}: ${value}`);
})
})
.catch(error => console.log("error", error));
})
I tried to authenticate myself incorrectly, create new users and use a body instead of a form and repeated the process several times in Postman. In Postman the query works and I get the expected results.
Marc is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1