---
title: "Launching VS Code Example"
sidebarTitle: "Launch VS Code"
description: "Example test demonstrating how to launch VS Code and install extensions on Linux."
icon: "play"
mode: "wide"
---

## Demo Test Run

Watch this test execute in a real sandbox environment:

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

## Source Code

```javascript title="launch-vscode-linux.test.mjs" {13,27-29}
import { describe, expect, it } from "vitest";
import { TestDriver } from "testdriverai/vitest/hooks";

const isLinux = (process.env.TD_OS || "linux") === "linux";

describe("Launch VS Code on Linux", () => {
  it.skipIf(!isLinux)(
    "should launch VS Code on Debian/Ubuntu",
    async (context) => {
      const testdriver = TestDriver(context, { ip: context.ip || process.env.TD_IP});
      
      // provision.vscode() automatically calls ready() and starts dashcam
      await testdriver.provision.vscode();

      // Wait for VS Code to launch (polls every 5s until found or timeout)
      const vsCodeWindow = await testdriver.find(
        "Visual Studio Code window",
        { timeout: 60000 }
      );
      expect(vsCodeWindow.found()).toBeTruthy();
    },
  );

  it.skipIf(!isLinux)(
    "should install and use a VS Code extension",
    async (context) => {
      const testdriver = TestDriver(context, { ip: context.ip || process.env.TD_IP});
      
      // Launch VS Code with the Prettier extension installed
      await testdriver.provision.vscode({
        extensions: ["esbenp.prettier-vscode"],
      });

      const vsCodeWindow = await testdriver.find(
        "Visual Studio Code window",
        { timeout: 60000 }
      );

      expect(vsCodeWindow.found()).toBeTruthy();

      // Open the extensions panel to verify Prettier is installed
      await testdriver.pressKeys(["ctrl", "shift", "x"]);
      
      // Wait for extensions panel to open
      await new Promise((resolve) => setTimeout(resolve, 2000));

      // Assert that Prettier extension is visible in the installed extensions
      const prettierVisible = await testdriver.assert(
        "Prettier extension is visible in the extensions panel or sidebar",
      );
      expect(prettierVisible).toBeTruthy();
    },
  );
});
```

## Running This Example

```bash
# Clone the TestDriver repository
git clone https://github.com/testdriverai/testdriverai

# Install dependencies
cd testdriverai
npm install

# Run this specific example
npx vitest run examples/launch-vscode-linux.test.mjs
```

<Note>
  Make sure you have `TD_API_KEY` set in your environment. Get one at [testdriver.ai](https://testdriver.ai).
</Note>
