Reputation: 11
POSTMAN request:
TokenEndPoint - https://api.dev.aa.com//token
Authorization: username: 'fadsfadf353423',
password: 'ZurbhG3kjZ'
Body: grant_type: 'client_credentials'
CURL:
curl --location --request POST 'https://api.dev.aa.com/edgemicro-auth/token' \
--header 'Authorization: Basic UkdZZUxSVUpobk5iRkR1QXJ4dzBnV1JNYXY3QmRxS==' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Cookie: _abck=D615B497E043C6F7E72E5F9AB4A34B5E~-1~YAAQDPs7FyzSrg+HAQAAwuC2NwmgIuawZv+zP3GhCafLPgqXpwKMPc9pjZ1IQ1kkIaWLFigGwzSfbIV6Y0cA/octAN264XvJR7IQHlVWNKSW64iR3bKb/4cTCCoKtNVyX3V7O+ekwHo/MhiK2Ie3vzGIw5qXpeqX7VQLSshZ4Tn+YvWCoARgFpSh0H6WhJQqPoKlvl3JJkMogFubx6csEfoHvShZaOdi2E0ddNxQOV2bmSnBtHuN5ntsIskySSqI1NvdXquXIZxyq+ghkDxgCWHaW9uFdLsZChBHZb7MhwSEfXvAeuBC4gSEhg5T8dHltZpYR+DvJQlZPdGh2fccOE8jb07ypbEU+FK5djoEk0qZJypQ6mJyGKqwYnBw6XvdRbBl~-1~-1~1675889701' \
--data-urlencode 'grant_type=client_credentials'
Playwright: I tried:
import { expect, request, test } from "@playwright/test";
const apiUrlEndPoint = 'https://api.dev.aa.com/token'
test('authendPoin', async ({request}) => {
const response = await request.post(apiUrlEndPoint, {
headers: {
//grant_type: 'client_credentials',
grant_type: 'password',
username: 'RGYeLRUJhnNbFDuArxw0gWRMav7BdqJu',
password: 'ZurbhG3kjZviG4xV'
}
//data:processRefundBodyPayload
//data: JSON.stringify(postBody),
})
expect(response.ok()).toBeTruthy
console.log("===================Status Text==============")
console.log(response.statusText())
expect(response.status()).toBe(200)
})
I am getting response 401 instead of 200; however, in POSTMAN, it is working as expected status code is 200
Upvotes: 1
Views: 724
Reputation: 11
Here is the solution: Playwright config file:
use: {
baseURL: 'https://api.dev.aa.com',
extraHTTPHeaders: {
'content-Type': 'application/x-www-form-urlencoded',
'Authorization': `Basic ${postman_curl_auth}`,
},
}
Playwright spec file
import { test as setup } from '@playwright/test';
setup('authenticate', async ({ request, baseURL }) => {
const response = await request.post(`${baseURL}/auth/token`, {
form: {
username: "RGYeLRUJh35346474DFGDGEDDG",
password: "ZurbhDHGDFTR4545G4xV",
grant_type: 'password'
},
});
console.log(response.statusText())
const content = await response.json();
console.log(content)
const {access_token, id_token} = content;
});
Upvotes: 0