Skip to content
Merged
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
31 changes: 28 additions & 3 deletions lib/commands/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import { sleep } from '../util';
import { errors, W3C_ELEMENT_KEY } from '@appium/base-driver';
import {
getWindowAllHandlesForProcessIds,

Check warning on line 19 in lib/commands/app.ts

View workflow job for this annotation

GitHub Actions / build

'getWindowAllHandlesForProcessIds' is defined but never used
keyDown,
keyUp,
trySetForegroundWindow,
Expand Down Expand Up @@ -64,6 +64,24 @@
return await this.sendPowerShellCommand(GET_PAGE_SOURCE_COMMAND.format(AutomationElement.automationRoot));
}

export async function maximizeWindow(this: NovaWindowsDriver): Promise<void> {
const automationRoot = new FoundAutomationElement(AutomationElement.automationRoot.buildGetPropertyCommand(Property.RUNTIME_ID));
try {
await this.sendPowerShellCommand(automationRoot.buildMaximizeCommand());
} catch {
throw new errors.UnknownError('Failed to maximize the window.');
}
}

export async function minimizeWindow(this: NovaWindowsDriver): Promise<void> {
const automationRoot = new FoundAutomationElement(AutomationElement.automationRoot.buildGetPropertyCommand(Property.RUNTIME_ID));
try {
await this.sendPowerShellCommand(automationRoot.buildMinimizeCommand());
} catch {
throw new errors.UnknownError('Failed to minimize the window.');
}
}

export async function getScreenshot(this: NovaWindowsDriver): Promise<string> {
const automationRootId = await this.sendPowerShellCommand(AutomationElement.automationRoot.buildCommand());

Expand Down Expand Up @@ -287,10 +305,17 @@
let attempts = 0;

while (Date.now() - start < timeout) {
const handles = getWindowAllHandlesForProcessIds([pid]);
// const handles = getWindowAllHandlesForProcessIds([pid]);

// if (handles.length > 0) {
// return handles[handles.length - 1];
// }

if (handles.length > 0) {
return handles[handles.length - 1];
const elements = await this.sendPowerShellCommand(AutomationElement.rootElement.findAll(TreeScope.CHILDREN, new PropertyCondition(Property.PROCESS_ID, new PSInt32(pid))).buildCommand());
const elementIds = elements.split('\n').map((id) => id.trim()).filter(Boolean);
if (elementIds.length > 0) {
const nativeWindowHandle = await this.sendPowerShellCommand(new FoundAutomationElement(elementIds[0]).buildGetPropertyCommand(Property.NATIVE_WINDOW_HANDLE));
return Number(nativeWindowHandle);
}

this.log.debug(`Waiting for the process window to appear... (${++attempts}/${Math.floor(timeout / SLEEP_INTERVAL_MS)})`);
Expand Down