---
title: "Pressing Keys Test"
sidebarTitle: "Pressing Keys"
description: "Example test demonstrating keyboard shortcuts and key combinations for browser navigation."
icon: "keyboard"
mode: "wide"
---

## Demo Test Run

Watch this test execute in a real sandbox environment:

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

## Source Code

```javascript title="press-keys.test.mjs" {17,24,36}
/**
 * TestDriver SDK - Press Keys Test (Vitest)
 * Converted from: testdriver/acceptance/press-keys.yaml
 */

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

describe("Press Keys Test", () => {
  it("should create tabs and navigate using keyboard shortcuts", 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' });

    const signInButton = await testdriver.find(
      "Sign In, black button below the password field",
    );
    await signInButton.click();

    // Open new tab
    await testdriver.pressKeys(["ctrl", "t"]);

    // Poll for "Learn more" to appear
    let imagesLink = await testdriver.find("Images", {timeout: 5000});

    expect(imagesLink.found()).toBeTruthy();

    // Open DevTools
    await testdriver.pressKeys(["ctrl", "shift", "i"]);

    // Poll for "Elements" to appear
    let elements = await testdriver.find("Elements", {timeout: 5000});
    expect(elements.found()).toBeTruthy();

    // Open another tab and navigate
    await testdriver.pressKeys(["ctrl", "t"]);
    await testdriver.type("google.com");
    await testdriver.pressKeys(["enter"]);

    // Assert Google appears
    const result = await testdriver.assert("google appears");
    expect(result).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/press-keys.test.mjs
```

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