@@ -256,7 +256,8 @@ describe('cy.session', { retries: 0 }, () => {
256
256
const sessionStorageData = consoleProps . groups [ 0 ] . groups [ 0 ]
257
257
258
258
expect ( sessionStorageData . name ) . to . contain ( 'Session Storage - (1)' )
259
- expect ( sessionStorageData . items ) . to . deep . eq ( { cypressAuthToken : '{"body":{"username":"tester"}}' } )
259
+ expect ( sessionStorageData . items ) . to . have . property ( 'cypressAuthToken' )
260
+ expect ( sessionStorageData . items . cypressAuthToken ) . to . contains ( '"username":"tester"' )
260
261
} )
261
262
} )
262
263
@@ -839,29 +840,39 @@ describe('cy.session', { retries: 0 }, () => {
839
840
let clearPageCount = 0
840
841
let sessionGroupId
841
842
let setup
843
+ let slowSetup
842
844
let validate
843
845
844
- const handleSetup = ( ) => {
846
+ const handleSetup = ( slowLogin = false ) => {
845
847
// create session clears page before running
846
848
cy . contains ( 'Default blank page' ) . should ( 'not.exist' )
847
849
848
850
cy . visit ( '/fixtures/auth/index.html' )
849
851
cy . contains ( 'You are not logged in' )
850
- cy . window ( ) . then ( ( win ) => {
851
- win . sessionStorage . setItem ( 'cypressAuthToken' , JSON . stringify ( { body : { username : 'tester' } } ) )
852
- } )
852
+ cy . get ( '[data-cy=login-same-origin]' ) . click ( )
853
+ cy . get ( 'input' ) . type ( 'tester' )
854
+ if ( slowLogin ) {
855
+ cy . get ( '[data-cy=slow-login]' ) . click ( )
856
+ } else {
857
+ cy . get ( '[data-cy=login]' ) . click ( )
858
+ }
853
859
}
854
860
861
+ const handleSlowSetup = ( ) => handleSetup ( true )
862
+
855
863
const handleValidate = ( ) => {
856
- // both create & restore session clears page after running
864
+ // both create & restore session clears page after running
857
865
cy . contains ( 'Default blank page' ) . should ( 'not.exist' )
858
866
859
- cy . visit ( '/fixtures/auth/index.html' )
860
- cy . contains ( 'Welcome tester' )
867
+ cy . window ( )
868
+ . its ( 'sessionStorage' )
869
+ . its ( 'cypressAuthToken' , { timeout : 5000 } )
870
+ . should ( 'contain' , '"username":"tester"' )
861
871
}
862
872
863
873
before ( ( ) => {
864
874
setup = cy . stub ( ) . callsFake ( handleSetup ) . as ( 'setupSession' )
875
+ slowSetup = cy . stub ( ) . callsFake ( handleSlowSetup ) . as ( 'setupSlowSession' )
865
876
validate = cy . stub ( ) . callsFake ( handleValidate ) . as ( 'validateSession' )
866
877
} )
867
878
@@ -879,7 +890,7 @@ describe('cy.session', { retries: 0 }, () => {
879
890
resetMocks ( )
880
891
clearAllSavedSessions ( )
881
892
cy . on ( 'log:added' , ( attrs , log ) => {
882
- if ( attrs . name === 'session' || attrs . name === 'sessions_manager' || attrs . name === 'page load' || attrs . alias ?. includes ( 'setupSession ' ) || attrs . alias ?. includes ( 'validateSession' ) ) {
893
+ if ( attrs . name === 'session' || attrs . name === 'sessions_manager' || attrs . alias ?. includes ( 'setupSession' ) || attrs . alias ?. includes ( 'setupSlowSession ' ) || attrs . alias ?. includes ( 'validateSession' ) ) {
883
894
logs . push ( log )
884
895
if ( ! sessionGroupId ) {
885
896
sessionGroupId = attrs . id
@@ -974,7 +985,8 @@ describe('cy.session', { retries: 0 }, () => {
974
985
const sessionStorageData = consoleProps . groups [ 0 ] . groups [ 0 ]
975
986
976
987
expect ( sessionStorageData . name ) . to . contain ( 'Session Storage - (1)' )
977
- expect ( sessionStorageData . items ) . to . deep . eq ( { cypressAuthToken : '{"body":{"username":"tester"}}' } )
988
+ expect ( sessionStorageData . items ) . to . have . property ( 'cypressAuthToken' )
989
+ expect ( sessionStorageData . items . cypressAuthToken ) . to . contains ( '"username":"tester"' )
978
990
} )
979
991
} )
980
992
@@ -985,15 +997,15 @@ describe('cy.session', { retries: 0 }, () => {
985
997
setupTestContext ( )
986
998
cy . log ( 'Creating new session with validation to test against' )
987
999
sessionId = `session-${ Cypress . state ( 'test' ) . id } `
988
- cy . session ( sessionId , setup , { validate } )
1000
+ cy . session ( sessionId , slowSetup , { validate } )
989
1001
} )
990
1002
991
1003
it ( 'does not clear the page after command' , ( ) => {
992
1004
cy . url ( ) . should ( 'contain' , '/fixtures/auth/index.html' )
993
1005
} )
994
1006
995
1007
it ( 'successfully creates new session and validates it' , ( ) => {
996
- expect ( setup ) . to . be . calledOnce
1008
+ expect ( slowSetup ) . to . be . calledOnce
997
1009
expect ( validate ) . to . be . calledOnce
998
1010
expect ( clearPageCount , 'total times session cleared the page' ) . to . eq ( 0 )
999
1011
} )
@@ -1024,7 +1036,7 @@ describe('cy.session', { retries: 0 }, () => {
1024
1036
} )
1025
1037
1026
1038
expect ( logs [ 3 ] . get ( ) ) . to . deep . contain ( {
1027
- alias : [ 'setupSession ' ] ,
1039
+ alias : [ 'setupSlowSession ' ] ,
1028
1040
group : createNewSessionGroup . id ,
1029
1041
} )
1030
1042
@@ -1040,6 +1052,24 @@ describe('cy.session', { retries: 0 }, () => {
1040
1052
group : validateSessionGroup . id ,
1041
1053
} )
1042
1054
} )
1055
+
1056
+ it ( 'has session details in the consoleProps' , ( ) => {
1057
+ const consoleProps = logs [ 0 ] . get ( 'consoleProps' ) ( )
1058
+
1059
+ expect ( consoleProps . Command ) . to . eq ( 'session' )
1060
+ expect ( consoleProps . id ) . to . eq ( sessionId )
1061
+ expect ( consoleProps . Domains ) . to . eq ( 'This session captured data from localhost.' )
1062
+
1063
+ expect ( consoleProps . groups ) . to . have . length ( 1 )
1064
+ expect ( consoleProps . groups [ 0 ] . name ) . to . eq ( 'localhost data:' )
1065
+ expect ( consoleProps . groups [ 0 ] . groups ) . to . have . length ( 1 )
1066
+
1067
+ const sessionStorageData = consoleProps . groups [ 0 ] . groups [ 0 ]
1068
+
1069
+ expect ( sessionStorageData . name ) . to . contain ( 'Session Storage - (1)' )
1070
+ expect ( sessionStorageData . items ) . to . have . property ( 'cypressAuthToken' )
1071
+ expect ( sessionStorageData . items . cypressAuthToken ) . to . contains ( '"username":"tester"' )
1072
+ } )
1043
1073
} )
1044
1074
1045
1075
describe ( 'create session with failed validation flow' , ( ) => {
0 commit comments