---
title: "Focus Window Test Example"
sidebarTitle: "Focus Window"
description: "Example test demonstrating how to switch focus between application windows."
icon: "window-maximize"
mode: "wide"
---

## Demo Test Run

Watch this test execute in a real sandbox environment:

{/* focus-window.test.mjs output */}
<iframe 
  src="https://api-test.testdriver.ai/api/v1/testdriver/testcase/69c5d042e8a04db4b705cbf2/replay" 
  width="100%" 
  height="390" 
  style={{ border: "1px solid #333", borderRadius: "8px" }}
  allow="fullscreen"
/>

## Source Code

```javascript title="focus-window.test.mjs" {23-25}
/**
 * TestDriver SDK - Focus Window Test (Vitest)
 * Converted from: testdriver/acceptance/focus-window.yaml
 */

import { describe, expect, it } from "vitest";
import { TestDriver } from "testdriverai/vitest/hooks";

describe("Focus Window Test", () => {
  it.skip(
    "should click Microsoft Edge icon and focus Google Chrome",
    async (context) => {
      const testdriver = TestDriver(context, { ip: context.ip || process.env.TD_IP, headless: true });
      await testdriver.provision.chrome({ url: 'http://testdriver-sandbox.vercel.app/login' });

      //
      // Show desktop
      await testdriver.pressKeys(["winleft", "d"]);

      // Click on the Microsoft Edge icon
      const edgeIcon = await testdriver.find(
        "a blue and green swirl icon on the taskbar representing Microsoft Edge",
      );
      await edgeIcon.click();

      // Focus Google Chrome
      await testdriver.focusApplication("Google Chrome");

      // Assert Chrome is focused (implicit through successful focus)
      const result = await testdriver.assert(
        "Google Chrome is the focused application",
      );
      expect(result).toBeTruthy();
    },
  );
});
```
