testdriver:focus-application

SkillDev tools

Bring an application window to the foreground

Available today. Use it from your connected AI after setup.

Connect ahel once, and every AI you use reads what you have installed.

Then ask your AI: use the testdriver:focus-application skill

What this skill tells your AI

The instructions your AI receives, as published by testdriverai/testdriverai in ai/skills/testdriver-focus-application/SKILL.md and read by ahel’s review.

Overview

Move a specific application window to the front. Make it the active window for interactions.

Syntax

await testdriver.focusApplication(name)

Parameters

Returns

Promise<string> - The result message

Examples

Common Applications

// Focus Chrome browser
await testdriver.focusApplication('Google Chrome');

// Focus Edge browser
await testdriver.focusApplication('Microsoft Edge');

// Focus Notepad
await testdriver.focusApplication('Notepad');

// Focus File Explorer
await testdriver.focusApplication('File Explorer');

// Focus Visual Studio Code
await testdriver.focusApplication('Visual Studio Code');

After Opening Applications

// Open Chrome and focus it
await testdriver.exec('pwsh', `
  Start-Process "C:/Program Files/Google/Chrome/Application/chrome.exe" -ArgumentList "https://example.com"
`, 5000);

await new Promise(r => setTimeout(r, 2000)); // Wait for launch

// Focus the Chrome window
await testdriver.focusApplication('Google Chrome');

Best Practices

Always focus the target application before interacting with its UI:

await testdriver.focusApplication('Google Chrome');

const button = await testdriver.find('submit button');
await button.click();

Give applications time to open before focusing:

await testdriver.exec('pwsh', 'Start-Process notepad', 5000);
await new Promise(r => setTimeout(r, 1000)); // Wait for launch
await testdriver.focusApplication('Notepad');
// ✅ Correct
await testdriver.focusApplication('Google Chrome');

// ❌ May not work
await testdriver.focusApplication('Chrome');
await testdriver.focusApplication('chrome.exe');

The application must already be running. focusApplication() won't launch applications, only bring existing windows to the foreground.

Use Cases

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();
```
await testdriver.focusApplication('Microsoft Edge');
await testdriver.assert('page loaded correctly in Edge');
```
await testdriver.focusApplication('Notepad');
await testdriver.type('Test content');
```
// Click desktop icon
const icon = await testdriver.find('Chrome icon on desktop');
await icon.click();

await new Promise(r => setTimeout(r, 2000));

// Focus the opened window
await testdriver.focusApplication('Google Chrome');
```

Common Application Names

Browsers

  • 'Google Chrome'
  • 'Microsoft Edge'
  • 'Mozilla Firefox'
  • 'Safari' (macOS)

Office Applications

  • 'Microsoft Word'
  • 'Microsoft Excel'
  • 'Microsoft PowerPoint'
  • 'Microsoft Outlook'

Development Tools

  • 'Visual Studio Code'
  • 'Visual Studio'
  • 'IntelliJ IDEA'
  • 'Sublime Text'

System Applications

  • 'Notepad'
  • 'File Explorer'
  • 'Command Prompt'
  • 'Windows PowerShell'
  • 'Task Manager'

Communication

  • 'Microsoft Teams'
  • 'Slack'
  • 'Discord'
  • 'Zoom'

Complete Example

import { beforeAll, afterAll, describe, it } from 'vitest';
import TestDriver from 'testdriverai';

describe('Multi-Application Workflow', () => {
  let testdriver;

  beforeAll(async () => {
    client = new TestDriver(process.env.TD_API_KEY);
    await testdriver.auth();
    await testdriver.connect();
  });

  afterAll(async () => {
    await testdriver.disconnect();
  });

  it('should work across multiple applications', async () => {
    // Start in browser
    await testdriver.focusApplication('Google Chrome');

    // Get data from web page
    const orderNumber = await testdriver.extract('the order number');
    console.log('Order:', orderNumber);

    // Open Notepad
    await testdriver.exec('pwsh', 'Start-Process notepad', 5000);
    await new Promise(r => setTimeout(r, 1500));

    // Focus Notepad and save data
    await testdriver.focusApplication('Notepad');
    await testdriver.type(`Order Number: ${orderNumber}`);
    await testdriver.type('\n');
    await testdriver.type(`Date: ${new Date().toISOString()}`);

    // Save file
    await testdriver.pressKeys(['ctrl', 's']);
    await new Promise(r => setTimeout(r, 500));

    await testdriver.type('C:\\order-info.txt');
    await testdriver.pressKeys(['enter']);

    // Return to browser
    await testdriver.focusApplication('Google Chrome');

    const confirmButton = await testdriver.find('confirm order button');
    await confirmButton.click();

    await testdriver.assert('order confirmed');
  });

  it('should switch between browser tabs', async () => {
    await testdriver.focusApplication('Google Chrome');

    // Open new tab
    await testdriver.pressKeys(['ctrl', 't']);
    await new Promise(r => setTimeout(r, 500));

    // Navigate to URL
    await testdriver.pressKeys(['ctrl', 'l']);
    await testdriver.type('https://example.com');
    await testdriver.pressKeys(['enter']);

    await new Promise(r => setTimeout(r, 2000));

    // Ensure Chrome is still focused
    await testdriver.focusApplication('Google Chrome');

    await testdriver.assert('example.com page is loaded');
  });

  it('should handle dialog boxes', async () => {
    await testdriver.focusApplication('Google Chrome');

    const deleteButton = await testdriver.find('delete account button');
    await deleteButton.click();

    await new Promise(r => setTimeout(r, 500));

    // Dialog appears - make sure it's focused
    await testdriver.focusApplication('Google Chrome');

    const confirmBtn = await testdriver.find('confirm deletion button');
    await confirmBtn.click();
  });
});

Related Methods

  • exec() - Launch applications with PowerShell
  • pressKeys() - Use Alt+Tab to switch windows
  • find() - Locate elements in the focused window

Signals

GitHub stars
242
Forks
35
Last commit
Sep 2026
Advanced
Catalog kind
skill
Gateway key
testdriver-focus-application
Source
github.com/testdriverai/testdriverai