Open
Description
I am trying to sign in to a website that uses a google authentication. I have been able to do the sign in while using cypress but I have not been able to achieve the same behavior using playwright. Please find below the two specs
it('should login', () => {
cy.request({
method: 'POST',
url: 'https://www.googleapis.com/oauth2/v4/token',
body: {
grant_type: 'refresh_token',
client_id: 'client_id',
client_secret: 'client_secret',
refresh_token: 'refresh_token',
},
}).then(({ body }) => {
const { access_token, id_token } = body;
cy.request({
method: 'GET',
url: 'https://www.googleapis.com/oauth2/v3/userinfo',
headers: { Authorization: `Bearer ${access_token}` },
}).then(({ body }) => {
cy.log(body);
const userItem = {
token: id_token,
user: {
googleId: body.sub,
email: body.email,
givenName: body.given_name,
familyName: body.family_name,
imageUrl: body.picture,
},
};
cy.visit(settings.website);
cy.contains('is logged in')
})
With playwrite, I wrote the following spec:
test("should log user in", async ({ page }) => {
// const requestContext = await page.request.newContext();
const response = await page.request.post(
"https://www.googleapis.com/oauth2/v4/token",
{
data: {
grant_type: "grant_type",
client_id:
"client_id",
client_secret: "client_secret",
refresh_token:
"refresh_token",
},
}
);
const content = await response.json();
const { access_token, id_token } = content;
const rawResponse2 = await page.request.get(
"https://www.googleapis.com/oauth2/v3/userinfo",
{
headers: { Authorization: `Bearer ${access_token}` },
}
);
const data = (await rawResponse2.json()) as any;
const userItem = {
token: id_token,
user: {
googleId: data.sub,
email: data.email,
givenName: data.given_name,
familyName: data.family_name,
imageUrl: data.picture,
},
};
console.log("userItem", userItem); // userItem is well displayed in the console
await page.goto(settings.website);
await expect(page).toContain("is logged in"); // test fails, the user is still not logged in
});
An issue has already been created and closed here. But after discussing with @yury-s he asked me to recreate it adding how to reproduce the behavior. Here is a repo where I showcase of a small angular app needing to signin to a google account. I have added all the instructions to configure firebase and get the google credentials. But I can provide my own inbox if necessary as well
https://github.com/kedevked/todos