Skip to content

Commit 22586a2

Browse files
committed
feat: add "none" session option to start without attaching to any element
1 parent 5a581ae commit 22586a2

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/commands/app.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,24 @@ import {
2323
const GET_PAGE_SOURCE_COMMAND = pwsh$ /* ps1 */ `
2424
$el = ${0}
2525
26+
if ($el -eq $null) {
27+
$dummy = [xml]'<DummyRoot></DummyRoot>'
28+
return $dummy.OuterXml
29+
}
30+
2631
Get-PageSource $el |
2732
ForEach-Object { $_.OuterXml }
2833
`;
2934

3035
const GET_SCREENSHOT_COMMAND = pwsh /* ps1 */ `
36+
if ($rootElement -eq $null) {
37+
$bitmap = New-Object Drawing.Bitmap 1,1
38+
$stream = New-Object IO.MemoryStream
39+
$bitmap.Save($stream, [Drawing.Imaging.ImageFormat]::Png)
40+
$bitmap.Dispose()
41+
return [Convert]::ToBase64String($stream.ToArray())
42+
}
43+
3144
$rect = $rootElement.Current.BoundingRectangle
3245
$bitmap = New-Object Drawing.Bitmap([int32]$rect.Width, [int32]$rect.Height)
3346

lib/commands/powershell.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const ADD_NECESSARY_ASSEMBLIES = /* ps1 */ `Add-Type -AssemblyName UIAutomationC
88
const USE_UI_AUTOMATION_CLIENT = /* ps1 */ `using namespace System.Windows.Automation`;
99
const INIT_CACHE_REQUEST = /* ps1 */ `($cacheRequest = New-Object System.Windows.Automation.CacheRequest).TreeFilter = [AndCondition]::new([Automation]::ControlViewCondition, [NotCondition]::new([PropertyCondition]::new([AutomationElement]::FrameworkIdProperty, 'Chrome'))); $cacheRequest.Push()`;
1010
const INIT_ROOT_ELEMENT = /* ps1 */ `$rootElement = [AutomationElement]::RootElement`;
11+
const NULL_ROOT_ELEMENT = /* ps1 */ `$rootElement = $null`;
1112
const INIT_ELEMENT_TABLE = /* ps1 */ `$elementTable = New-Object System.Collections.Generic.Dictionary[[string]\`,[AutomationElement]]`;
1213

1314
export async function startPowerShellSession(this: NovaWindowsDriver): Promise<void> {
@@ -49,11 +50,15 @@ export async function startPowerShellSession(this: NovaWindowsDriver): Promise<v
4950
await this.sendPowerShellCommand(PAGE_SOURCE);
5051
await this.sendPowerShellCommand(FIND_CHILDREN_RECURSIVELY);
5152

52-
if ((!this.caps.app && !this.caps.appTopLevelWindow) || (!this.caps.app || this.caps.app.toLowerCase() === 'root')) {
53+
if ((!this.caps.app && !this.caps.appTopLevelWindow) || (!this.caps.app || this.caps.app.toLowerCase() === 'none')) {
54+
await this.sendPowerShellCommand(NULL_ROOT_ELEMENT);
55+
}
56+
57+
if (this.caps.app && this.caps.app.toLowerCase() !== 'none' && this.caps.app.toLowerCase() === 'root') {
5358
await this.sendPowerShellCommand(INIT_ROOT_ELEMENT);
5459
}
5560

56-
if (this.caps.app && this.caps.app.toLowerCase() !== 'root') {
61+
if (this.caps.app && this.caps.app.toLowerCase() !== 'none' && this.caps.app.toLowerCase() !== 'root') {
5762
const envVarsSet: Set<string> = new Set();
5863
const matches = this.caps.app.matchAll(/%([^%]+)%/g);
5964

0 commit comments

Comments
 (0)