@@ -144,19 +144,11 @@ Next, we'll write a custom command called `loginToAuth0` to perform a login to
144
144
``` js
145
145
// cypress/support/auth-provider-commands/auth0.ts
146
146
147
- Cypress .Commands .add (' loginToAuth0' , (username : string , password : string ) => {
148
- const log = Cypress .log ({
149
- displayName: ' AUTH0 LOGIN' ,
150
- message: [` 🔐 Authenticating | ${ username} ` ],
151
- // @ts-ignore
152
- autoEnd: false ,
153
- })
154
- log .snapshot (' before' )
155
-
147
+ function loginViaAuth0Ui (username : string , password : string ) {
156
148
// App landing page redirects to Auth0.
157
149
cy .visit (' /' )
158
150
159
- // Login on Auth0 (we'll add caching later) .
151
+ // Login on Auth0.
160
152
cy .origin (
161
153
Cypress .env (' auth0_domain' ),
162
154
{ args: { username, password } },
@@ -169,6 +161,18 @@ Cypress.Commands.add('loginToAuth0', (username: string, password: string) => {
169
161
170
162
// Ensure Auth0 has redirected us back to the RWA.
171
163
cy .url ().should (' equal' , ' http://localhost:3000/' )
164
+ }
165
+
166
+ Cypress .Commands .add (' loginToAuth0' , (username : string , password : string ) => {
167
+ const log = Cypress .log ({
168
+ displayName: ' AUTH0 LOGIN' ,
169
+ message: [` 🔐 Authenticating | ${ username} ` ],
170
+ // @ts-ignore
171
+ autoEnd: false ,
172
+ })
173
+ log .snapshot (' before' )
174
+
175
+ loginViaAuth0Ui (username, password)
172
176
173
177
log .snapshot (' after' )
174
178
log .end ()
@@ -221,26 +225,10 @@ Cypress.Commands.add('loginToAuth0', (username: string, password: string) => {
221
225
})
222
226
log .snapshot (' before' )
223
227
224
- const args = { username, password }
225
228
cy .session (
226
229
` auth0-${ username} ` ,
227
230
() => {
228
- // App landing page redirects to Auth0.
229
- cy .visit (' /' )
230
-
231
- // Login on Auth0.
232
- cy .origin (
233
- Cypress .env (' auth0_domain' ),
234
- { args },
235
- ({ username, password }) => {
236
- cy .get (' input#username' ).type (username)
237
- cy .get (' input#password' ).type (password, { log: false })
238
- cy .contains (' button[value=default]' , ' Continue' ).click ()
239
- }
240
- )
241
-
242
- // Ensure Auth0 has redirected us back to the RWA.
243
- cy .url ().should (' equal' , ' http://localhost:3000/' )
231
+ loginViaAuth0Ui (username, password)
244
232
},
245
233
{
246
234
validate : () => {
0 commit comments