<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Russell Hudson</title>
    <description>The latest articles on DEV Community by Russell Hudson (@russellhudson).</description>
    <link>https://dev.to/russellhudson</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F926095%2F7c341a8d-bc5e-4092-8e53-22fbc01b293f.jpeg</url>
      <title>DEV Community: Russell Hudson</title>
      <link>https://dev.to/russellhudson</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/russellhudson"/>
    <language>en</language>
    <item>
      <title>Laravel/Cypress Google SSO Test</title>
      <dc:creator>Russell Hudson</dc:creator>
      <pubDate>Wed, 14 Sep 2022 10:28:21 +0000</pubDate>
      <link>https://dev.to/russellhudson/laravelcypress-google-sso-test-4ppa</link>
      <guid>https://dev.to/russellhudson/laravelcypress-google-sso-test-4ppa</guid>
      <description>&lt;p&gt;This is a working Google SSO Cypress Test. Your mileage may vary.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;describe('Login', () =&amp;gt; {
    it('Login through Google', () =&amp;gt; {
        const username = Cypress.env('googleSocialLoginUsername')
        alert(username)
        const password = Cypress.env('googleSocialLoginPassword')
        const loginUrl = Cypress.env('loginUrl')
        const cookieName = Cypress.env('cookieName')
        const socialLoginOptions = {
            username: username,
            password: password,
            loginUrl: loginUrl,
            headless: true,
            logs: false,
            loginSelector: '[href="http://127.0.0.1:8000/auth/google"]',
            postLoginSelector: '.bg-scholarpath-500'
        }

        return cy.task('GoogleSocialLogin', socialLoginOptions).then(({cookies}) =&amp;gt; {
            cy.clearCookies()

            const cookie = cookies.filter(cookie =&amp;gt; cookie.name === cookieName).pop()
            if (cookie) {
                cy.setCookie(cookie.name, cookie.value, {
                    domain: cookie.domain,
                    expiry: cookie.expires,
                    httpOnly: cookie.httpOnly,
                    path: cookie.path,
                    secure: cookie.secure
                })

                Cypress.Cookies.defaults({
                    preserve: cookieName
                })
            }
        })
    })
})

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: the following 2 lines are critical:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;loginSelector: '[href="http://127.0.0.1:8000/auth/google"]',
postLoginSelector: '.bg-somestyle-500'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Make sure this url matches the url for your google auth route.&lt;br&gt;
Also, &lt;em&gt;postLoginSelector&lt;/em&gt; is a class on your "Log in with Google" button. &lt;/p&gt;

&lt;p&gt;You will also need the following plugin:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/cypress-social-logins"&gt;cypress-social-logins&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Add the following to your plugins/index.js file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const {GoogleSocialLogin} = require('cypress-social-logins').plugins

module.exports = (on, config) =&amp;gt; {
    on('task', {
        GoogleSocialLogin: GoogleSocialLogin
    })
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it! Now try to run it:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npx cypress open&lt;/code&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>googlesso</category>
      <category>cypress</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
