Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/cli/callbacks/ci-mode/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ function formatAction(action: Action): string {
return `${action.type} ${chalk.gray(action.selector)}`;
case "navigate":
return `navigate ${chalk.gray(action.url)}`;
case "waitForNavigation":
return `wait for navigation`;
case "screenshot":
return `screenshot ${chalk.gray(action.name)}`;
default: {
Expand Down
2 changes: 2 additions & 0 deletions src/cli/callbacks/existing-story/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ function formatAction(action: Action): string {
return `${action.type} ${chalk.gray(action.selector)}`;
case "navigate":
return `navigate ${chalk.gray(action.url)}`;
case "waitForNavigation":
return `wait for navigation`;
case "screenshot":
return `screenshot ${chalk.gray(action.name)}`;
default: {
Expand Down
2 changes: 2 additions & 0 deletions src/cli/callbacks/run-multiple-stories/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ function formatAction(action: Action): string {
return `${action.type} ${chalk.gray(action.selector)}`;
case "navigate":
return `navigate ${chalk.gray(action.url)}`;
case "waitForNavigation":
return `wait for navigation`;
case "screenshot":
return `screenshot ${chalk.gray(action.name)}`;
default: {
Expand Down
5 changes: 5 additions & 0 deletions src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export interface NavigateAction extends BaseAction {
url: string;
}

export interface WaitForNavigationAction extends BaseAction {
type: "waitForNavigation";
}

export interface ScreenshotAction extends BaseAction {
type: "screenshot";
name: string;
Expand All @@ -57,6 +61,7 @@ export type Action =
| SelectAction
| CheckAction
| NavigateAction
| WaitForNavigationAction
| ScreenshotAction;

export interface Story {
Expand Down
23 changes: 19 additions & 4 deletions src/recorder/event-capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class EventCapture {
private pendingActions: Action[] = [];
private inputTracking = new Map<string, string>();
private lastUrl = "";
private lastInteractionTime = 0;

constructor(page: Page) {
this.page = page;
Expand Down Expand Up @@ -61,10 +62,22 @@ export class EventCapture {
if (frame === this.page.mainFrame()) {
const newUrl = this.page.url();
if (newUrl !== this.lastUrl) {
this.pendingActions.push({
type: "navigate",
url: newUrl,
});
// Check if navigation occurred within 1 second of last interaction
const timeSinceInteraction = Date.now() - this.lastInteractionTime;

if (timeSinceInteraction <= 1000) {
// Automatic redirect (likely caused by previous action)
this.pendingActions.push({
type: "waitForNavigation",
});
} else {
// Manual navigation
this.pendingActions.push({
type: "navigate",
url: newUrl,
});
}

this.lastUrl = newUrl;

// Re-inject listeners after navigation
Expand All @@ -89,6 +102,7 @@ export class EventCapture {
switch (event.type) {
case "click":
if (event.selector) {
this.lastInteractionTime = Date.now();
this.pendingActions.push({
type: "click",
selector: event.selector,
Expand All @@ -105,6 +119,7 @@ export class EventCapture {

case "change":
if (event.selector) {
this.lastInteractionTime = Date.now();
if (event.inputType === "select" && event.value !== undefined) {
this.pendingActions.push({
type: "select",
Expand Down
12 changes: 12 additions & 0 deletions src/runner/action-executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ export async function executeAction(page: Page, action: Action): Promise<void> {
break;
}

case "waitForNavigation": {
// Wait for navigation that was triggered by a previous action
// This is used for automatic redirects (e.g., post-login redirects)
// The previous action (click/input) already triggered the navigation
// We just need to wait for it to complete to preserve cookies
await page.waitForNavigation({
waitUntil: "networkidle2",
timeout: DEFAULT_TIMEOUT,
});
break;
}

case "screenshot": {
// Screenshot actions are handled externally by the runner
// This should not be called directly through executeAction
Expand Down