Wait after launching appsGive applications time to open before focusing:
Copy
await testdriver.exec('pwsh', 'Start-Process notepad', 5000);await new Promise(r => setTimeout(r, 1000)); // Wait for launchawait testdriver.focusApplication('Notepad');
Use exact application names
Copy
// ✅ Correctawait testdriver.focusApplication('Google Chrome');// ❌ May not workawait testdriver.focusApplication('Chrome');await testdriver.focusApplication('chrome.exe');
Application must be runningThe application must already be running. focusApplication() won’t launch applications, only bring existing windows to the foreground.
// Test workflow across multiple appsawait testdriver.focusApplication('Google Chrome');const data = await testdriver.remember('the order number');await testdriver.focusApplication('Notepad');await testdriver.type(data);await testdriver.pressKeys(['ctrl', 's']);await testdriver.focusApplication('Google Chrome');const nextButton = await testdriver.find('next button');await nextButton.click();
Browser Switching
Copy
// Compare behavior in different browsersawait testdriver.focusApplication('Google Chrome');await testdriver.assert('page loaded correctly in Chrome');await testdriver.focusApplication('Microsoft Edge');await testdriver.assert('page loaded correctly in Edge');
Desktop Application Testing
Copy
// Launch and focus desktop appawait testdriver.exec('pwsh', 'Start-Process notepad', 5000);await new Promise(r => setTimeout(r, 1000));await testdriver.focusApplication('Notepad');await testdriver.type('Test content');
Window Management
Copy
// Show desktop firstawait testdriver.pressKeys(['winleft', 'd']);// Click desktop iconconst icon = await testdriver.find('Chrome icon on desktop');await icon.click();await new Promise(r => setTimeout(r, 2000));// Focus the opened windowawait testdriver.focusApplication('Google Chrome');