@@ -4,6 +4,7 @@ import { snapshotReporter } from './support/snapshot-reporter'
4
4
const validateSessionsInstrumentPanel = ( sessionIds : Array < string > = [ ] ) => {
5
5
cy . get ( '.sessions-container' )
6
6
. should ( 'contain' , `Sessions (${ sessionIds . length } )` )
7
+ . as ( 'instrument_panel' )
7
8
. click ( )
8
9
9
10
sessionIds . forEach ( ( id ) => {
@@ -142,7 +143,11 @@ describe('runner/cypress sessions.ui.spec', {
142
143
} )
143
144
144
145
it ( 'restores session as expected' , ( ) => {
145
- cy . get ( '.test' ) . each ( ( $el ) => cy . wrap ( $el ) . click ( ) )
146
+ cy . get ( '.test' ) . each ( ( $el , index ) => {
147
+ if ( index < 5 ) { // don't click on failed test
148
+ cy . wrap ( $el ) . click ( )
149
+ }
150
+ } )
146
151
147
152
cy . log ( 'validate new session was created in first test' )
148
153
cy . get ( '.test' ) . eq ( 0 ) . within ( ( ) => {
@@ -153,7 +158,6 @@ describe('runner/cypress sessions.ui.spec', {
153
158
cy . log ( 'validate saved session was used in second test' )
154
159
cy . get ( '.test' ) . eq ( 1 ) . within ( ( ) => {
155
160
validateSessionsInstrumentPanel ( [ 'user1' ] )
156
-
157
161
cy . get ( '.command-name-session' )
158
162
. within ( ( ) => {
159
163
cy . get ( '.command-expander' ) . first ( ) . click ( )
@@ -192,7 +196,7 @@ describe('runner/cypress sessions.ui.spec', {
192
196
cy . get ( '.test' ) . eq ( 3 ) . should ( 'have.class' , 'runnable-passed' )
193
197
cy . get ( '.test' ) . eq ( 4 ) . should ( 'have.class' , 'runnable-passed' )
194
198
cy . get ( '.test' ) . eq ( 5 ) . should ( 'have.class' , 'runnable-failed' )
195
- cy . contains ( 'If you want to specify different options, please use a unique name ' ) . should ( 'exist' )
199
+ cy . contains ( 'This session already exists. ' ) . should ( 'exist' )
196
200
} )
197
201
} )
198
202
@@ -323,7 +327,7 @@ describe('runner/cypress sessions.ui.spec', {
323
327
passCount : 1 ,
324
328
} )
325
329
326
- validateSessionsInstrumentPanel ( [ 'user1 ' , 'user2 ' ] )
330
+ validateSessionsInstrumentPanel ( [ 'spec_session_1 ' , 'spec_session_2' , 'global_session_1 '] )
327
331
// cy.percySnapshot() // TODO: restore when Percy CSS is fixed. See https://github.com/cypress-io/cypress/issues/23435
328
332
} )
329
333
} )
@@ -340,50 +344,91 @@ describe('runner/cypress sessions.open_mode.spec', () => {
340
344
passCount : 1 ,
341
345
} )
342
346
343
- cy . get ( '.command-name-session' ) . should ( 'contain' , 'user1' )
344
- . find ( '.reporter-tag' ) . should ( 'contain' , 'created' )
345
-
346
- cy . get ( '.command-name-session' ) . should ( 'contain' , 'user2' )
347
- . find ( '.reporter-tag' ) . should ( 'contain' , 'created' )
347
+ cy . get ( '.reporter-tag' ) . should ( 'contain' , 'created' ) . should ( 'length' , 3 )
348
348
} )
349
349
350
- it ( 'persists spec sessions when clicking "rerun all tests" button' , ( ) => {
350
+ it ( 'persists global and spec sessions when clicking "rerun all tests" button' , ( ) => {
351
351
cy . get ( '.restart' ) . click ( )
352
352
353
353
cy . waitForSpecToFinish ( {
354
354
passCount : 1 ,
355
355
} )
356
356
357
- cy . get ( '.command-name-session' ) . should ( 'contain' , 'user1' )
358
- . find ( '.reporter-tag' ) . should ( 'contain' , 'restored' )
359
-
360
- cy . get ( '.command-name-session' ) . should ( 'contain' , 'user2' )
361
- . find ( '.reporter-tag' ) . should ( 'contain' , 'restored' )
357
+ cy . get ( '.reporter-tag' ) . should ( 'contain' , 'restored' ) . should ( 'length' , 3 )
362
358
} )
363
359
364
- it ( 'persists spec sessions on refresh' , ( ) => {
360
+ it ( 'persists global and spec sessions on refresh' , ( ) => {
365
361
cy . get ( 'body' ) . type ( 'r' )
366
362
367
363
cy . waitForSpecToFinish ( {
368
364
passCount : 1 ,
369
365
} )
370
366
371
- cy . get ( '.command-name-session' ) . should ( 'contain' , 'user1' )
372
- . find ( '.reporter-tag' ) . should ( 'contain' , 'restored' )
373
-
374
- cy . get ( '.command-name-session' ) . should ( 'contain' , 'user2' )
375
- . find ( '.reporter-tag' ) . should ( 'contain' , 'restored' )
367
+ cy . get ( '.reporter-tag' ) . should ( 'contain' , 'restored' ) . should ( 'length' , 3 )
376
368
} )
377
369
378
- it ( 'does not persists spec sessions when selecting a different spec' , ( ) => {
370
+ it ( 'persists global session and does not persists spec session when selecting a different spec' , ( ) => {
379
371
cy . get ( 'body' ) . type ( 'f' )
380
- cy . get ( 'div[title="new_session .cy.js"]' ) . click ( )
372
+ cy . get ( 'div[title="blank_session .cy.js"]' ) . click ( )
381
373
382
374
cy . waitForSpecToFinish ( {
383
375
passCount : 1 ,
384
376
} )
385
377
386
- cy . get ( '.command-name-session' ) . should ( 'contain' , 'user1 ' )
378
+ cy . get ( '.command-name-session' ) . eq ( 0 ) . should ( 'contain' , 'spec_session ' )
387
379
. find ( '.reporter-tag' ) . should ( 'contain' , 'created' )
380
+
381
+ cy . get ( '.command-name-session' ) . eq ( 1 ) . should ( 'contain' , 'global_session_1' )
382
+ . find ( '.reporter-tag' ) . should ( 'contain' , 'restored' )
383
+ } )
384
+
385
+ it ( 'clears all sessions when selecting "clear all sessions"' , ( ) => {
386
+ cy . get ( 'body' ) . type ( 'r' )
387
+
388
+ cy . waitForSpecToFinish ( {
389
+ passCount : 1 ,
390
+ } )
391
+
392
+ cy . get ( '.reporter-tag' ) . should ( 'contain' , 'restored' ) . should ( 'length' , 3 )
393
+
394
+ cy . contains ( 'Clear All Sessions' ) . click ( )
395
+
396
+ cy . contains ( 'Your tests are loading...' )
397
+
398
+ cy . waitForSpecToFinish ( {
399
+ passCount : 1 ,
400
+ } )
401
+
402
+ cy . get ( '.reporter-tag' ) . should ( 'contain' , 'created' ) . should ( 'length' , 3 )
403
+ } )
404
+ } )
405
+
406
+ describe ( 'global sessions' , ( ) => {
407
+ beforeEach ( ( ) => {
408
+ cy . scaffoldProject ( 'session-and-origin-e2e-specs' )
409
+ cy . openProject ( 'session-and-origin-e2e-specs' )
410
+ cy . startAppServer ( 'e2e' )
411
+ cy . visitApp ( )
412
+
413
+ cy . get ( '[data-cy-row="global_sessions.cy.js"]' ) . click ( )
414
+ cy . waitForSpecToFinish ( {
415
+ passCount : 2 ,
416
+ } )
417
+ } )
418
+
419
+ it ( 'creates global session' , ( ) => {
420
+ cy . contains ( '.test' , 'creates global session' ) . as ( 'creates_global' ) . click ( )
421
+ cy . get ( '@creates_global' ) . within ( ( ) => {
422
+ cy . get ( '.command-name-session' ) . should ( 'contain' , 'global_session_1' )
423
+ . find ( '.reporter-tag' ) . should ( 'contain' , 'created' )
424
+ } )
425
+ } )
426
+
427
+ it ( 'restores global session' , ( ) => {
428
+ cy . contains ( '.test' , 'restores global session' ) . as ( 'restores_global' ) . click ( )
429
+ cy . get ( '@restores_global' ) . within ( ( ) => {
430
+ cy . get ( '.command-name-session' ) . should ( 'contain' , 'global_session_1' )
431
+ . find ( '.reporter-tag' ) . should ( 'contain' , 'restored' )
432
+ } )
388
433
} )
389
434
} )
0 commit comments