Skip to content

Commit b252c76

Browse files
committed
feat: add --no-incognito option to disable incognito mode in browser execution
1 parent 8641c9e commit b252c76

File tree

4 files changed

+65
-10
lines changed

4 files changed

+65
-10
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Id": "a088fcfb-b0ee-48b7-8ba7-0351c5cb08be",
3+
"IssueId": "",
4+
"Prefix": "Added",
5+
"Tag": "",
6+
"Message": "Added --no-incognito option to disable incognito mode in browser execution",
7+
"CreatedAt": "2025-08-11T18:08:50.077361+00:00",
8+
"CreatedBy": "thomasduft"
9+
}

src/testr.Cli/Commands/RunCommand.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ private static readonly Gauge<int> TestCaseGauge
2020
private readonly CommandOption<string> _outputDirectory;
2121
private readonly CommandOption<bool> _headless;
2222
private readonly CommandOption<bool> _continueOnFailure;
23+
private readonly CommandOption<bool> _noIncognito;
2324
private readonly CommandOption<int> _slow;
2425
private readonly CommandOption<int> _timeout;
2526
private readonly CommandOption<BrowserType> _browserType;
@@ -77,6 +78,14 @@ public RunCommand()
7778
true
7879
);
7980

81+
_noIncognito = Option<bool>(
82+
"--no-incognito",
83+
"Disables incognito mode for the browser.",
84+
CommandOptionType.NoValue,
85+
cfg => cfg.DefaultValue = false,
86+
true
87+
);
88+
8089
_slow = Option<int>(
8190
"-s|--slow",
8291
"Slows down the execution by the specified amount of milliseconds.",
@@ -275,7 +284,8 @@ private ExecutorConfig GetExecutorConfiguration()
275284
_slow.ParsedValue,
276285
_timeout.ParsedValue,
277286
_browserType.ParsedValue,
278-
_recordVideoDir.ParsedValue
287+
_recordVideoDir.ParsedValue,
288+
_noIncognito.ParsedValue
279289
);
280290
}
281291
}

src/testr.Cli/Domain/ExecutorConfig.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ public record ExecutorConfig(
55
int Slow = 500,
66
int Timeout = 30000,
77
BrowserType BrowserType = BrowserType.Chrome,
8-
string? RecordVideoDir = null
9-
);
8+
string? RecordVideoDir = null,
9+
bool NoIncognito = false
10+
);

src/testr.Cli/Domain/TestCaseExecutor.cs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,49 @@ CancellationToken cancellationToken
2323
)
2424
{
2525
using var playwright = await Playwright.CreateAsync();
26-
await using var browser = await GetBrowserType(playwright)
27-
.LaunchAsync(new BrowserTypeLaunchOptions
28-
{
29-
Headless = _config.Headless,
30-
SlowMo = _config.Slow // by N milliseconds per operation,
31-
});
3226

33-
var context = await GetBrowserContext(browser);
27+
var browserType = GetBrowserType(playwright);
28+
if (_config.NoIncognito)
29+
{
30+
await using var browserContext = await browserType.LaunchPersistentContextAsync(
31+
string.Empty,
32+
new BrowserTypeLaunchPersistentContextOptions
33+
{
34+
Headless = _config.Headless,
35+
SlowMo = _config.Slow
36+
});
37+
38+
return await RunBrowserAsync(
39+
domain,
40+
executionParam,
41+
preconditionExecutionParam,
42+
browserContext
43+
);
44+
}
45+
46+
await using var incognitoBrowser = await browserType.LaunchAsync(new BrowserTypeLaunchOptions
47+
{
48+
Headless = _config.Headless,
49+
SlowMo = _config.Slow
50+
});
51+
52+
var incognitoContext = await GetBrowserContext(incognitoBrowser);
53+
54+
return await RunBrowserAsync(
55+
domain,
56+
executionParam,
57+
preconditionExecutionParam,
58+
incognitoContext
59+
);
60+
}
61+
62+
private async Task<IEnumerable<TestStepResult>> RunBrowserAsync(
63+
string domain,
64+
TestCaseExecutionParam executionParam,
65+
TestCaseExecutionParam? preconditionExecutionParam,
66+
IBrowserContext context
67+
)
68+
{
3469
var page = await context.NewPageAsync();
3570

3671
// execute precondition instructions if available

0 commit comments

Comments
 (0)