Skip to content

Commit 7109367

Browse files
authored
Merge pull request #42 from AutomateThePlanet/releases/v1.2.0
Added retry for attaching a window
2 parents 32dc094 + b5261d4 commit 7109367

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/commands/app.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,16 @@ export async function attachToApplicationWindow(this: NovaWindowsDriver, process
203203
this.log.debug(`Detected the following native window handles for the given process IDs: ${nativeWindowHandles.map((handle) => `0x${handle.toString(16).padStart(8, '0')}`).join(', ')}`);
204204

205205
if (nativeWindowHandles.length !== 0) {
206-
const elementId = await this.sendPowerShellCommand(AutomationElement.rootElement.findFirst(TreeScope.CHILDREN, new PropertyCondition(Property.NATIVE_WINDOW_HANDLE, new PSInt32(nativeWindowHandles[0]))).buildCommand());
206+
let elementId = '';
207+
for (let i = 1; i <= 20; i++) {
208+
elementId = await this.sendPowerShellCommand(AutomationElement.rootElement.findFirst(TreeScope.CHILDREN, new PropertyCondition(Property.NATIVE_WINDOW_HANDLE, new PSInt32(nativeWindowHandles[0]))).buildCommand());
209+
if (elementId) {
210+
break;
211+
}
212+
this.log.info(`The window with handle 0x${nativeWindowHandles[0].toString(16).padStart(8, '0')} is not yet available in the UI Automation tree. Sleeping for 500 milliseconds and retrying... (${i}/20)`); // TODO: make a setting for the number of retries or timeout
213+
await sleep(500); // TODO: make a setting for the sleep timeout
214+
}
215+
207216
await this.sendPowerShellCommand(/* ps1 */ `$rootElement = ${new FoundAutomationElement(elementId).buildCommand()}`);
208217
if ((await this.sendPowerShellCommand(/* ps1 */ `$null -ne $rootElement`)).toLowerCase() === 'true') {
209218
const nativeWindowHandle = Number(await this.sendPowerShellCommand(AutomationElement.automationRoot.buildGetPropertyCommand(Property.NATIVE_WINDOW_HANDLE)));

0 commit comments

Comments
 (0)