I am attempting to access a google service embedded into my website which uses accounts.google.com for the login.
I’m trying to use the session/origin commands to do this, but it’s failing as if I’m doing nothing at all. I use this with success to login to my application (non google login), but google seems to require something more. I have spent a great deal of time browsing for answers with no luck
Code leading up to login:
cy.get('div [class="active carousel-item"]').find('button').first().click()
cy.loginGoogle(Cypress.env("GoogleUsername"),Cypress.env("GooglePassword"))
Login code:
Cypress.Commands.add('loginGoogle', (username, password) => {
const args = { username, password }
cy.session(args, () =>
{
cy.origin('https://accounts.google.com', { args }, ({ username, password }) => {
cy.visit('https://accounts.google.com/')
cy.get('input[type="email"]').type(username)
cy.get('div[id="identifierNext"]').find('button').click()
cy.get('#login-password').type(password)
cy.get('#btn-login').click()
})
cy.visit('/')
cy.url().should('contain', 'mydomain.com')
})
})