@@ -1085,3 +1085,63 @@ func TestPageActionAfterClose(t *testing.T) {
1085
1085
g .Eq (err , context .Canceled )
1086
1086
}
1087
1087
}
1088
+
1089
+ func TestPageResetNavigationHistory (t * testing.T ) {
1090
+ const (
1091
+ // After resetting history, the record should contain only the current page entry
1092
+ expectedInitialHistoryLength = 1
1093
+ clickHTMLPath = "fixtures/click.html"
1094
+ inputHTMLPath = "fixtures/input.html"
1095
+ )
1096
+
1097
+ g := setup (t )
1098
+
1099
+ // Helper function for navigation
1100
+ navigateTo := func (p * rod.Page , url string ) {
1101
+ wait := p .WaitNavigation (proto .PageLifecycleEventNameDOMContentLoaded )
1102
+ p .MustNavigate (url )
1103
+ wait ()
1104
+ }
1105
+
1106
+ // Initialize page with blank content
1107
+ page := g .page .MustNavigate (g .blank ())
1108
+
1109
+ // Navigate to multiple pages
1110
+ navigateTo (page , g .srcFile (clickHTMLPath ))
1111
+ navigateTo (page , g .srcFile (inputHTMLPath ))
1112
+
1113
+ // Verify navigation back functionality
1114
+ wait := page .WaitNavigation (proto .PageLifecycleEventNameDOMContentLoaded )
1115
+ page .MustNavigateBack ()
1116
+ wait ()
1117
+
1118
+ g .Regex (`/` + clickHTMLPath , page .MustInfo ().URL )
1119
+
1120
+ // Verify history has multiple entries
1121
+ initialHistory , err := page .GetNavigationHistory ()
1122
+ g .E (err )
1123
+ g .NotNil (initialHistory )
1124
+ g .Gt (len (initialHistory .Entries ), expectedInitialHistoryLength )
1125
+
1126
+ // Test resetting navigation history
1127
+ err = page .ResetNavigationHistory ()
1128
+ g .E (err )
1129
+
1130
+ // Verify history is reset to initial state
1131
+ resetHistory , err := page .GetNavigationHistory ()
1132
+ g .E (err )
1133
+ g .NotNil (resetHistory )
1134
+ g .Eq (len (resetHistory .Entries ), expectedInitialHistoryLength )
1135
+
1136
+ // Navigate to another page
1137
+ navigateTo (page , g .srcFile (inputHTMLPath ))
1138
+
1139
+ // Test resetting history again
1140
+ page .MustResetNavigationHistory ()
1141
+
1142
+ // Verify history is reset again
1143
+ finalHistory , err := page .GetNavigationHistory ()
1144
+ g .E (err )
1145
+ g .NotNil (finalHistory )
1146
+ g .Eq (len (finalHistory .Entries ), expectedInitialHistoryLength )
1147
+ }
0 commit comments