← Back to library
Cypressauthadvancedv12+
OAuth cross-origin flow with cy.origin
Handle an OAuth provider on a separate domain using cy.origin.
1it('logs in via Google OAuth', () => {
2 cy.visit('/login');
3 cy.get('[data-testid="google-login"]').click();
4
5 // cy.origin enables commands to run on a different domain
6 cy.origin('https://accounts.google.com', () => {
7 cy.get('input[type="email"]').type('user@gmail.com');
8 cy.get('#identifierNext').click();
9 cy.get('input[type="password"]', { timeout: 8000 }).type('secret');
10 cy.get('#passwordNext').click();
11 });
12
13 cy.url().should('include', '/dashboard');
14 cy.contains('Welcome').should('be.visible');
15});#oauth#cy.origin#cross-origin#google