---
title: "Exec PowerShell Test Example"
sidebarTitle: "Exec Pwsh"
description: "Example test demonstrating how to generate dynamic data using PowerShell and use it in test interactions."
icon: "terminal"
mode: "wide"
---

## Demo Test Run

Watch this test execute in a real sandbox environment:

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

## Source Code

```javascript title="exec-pwsh.test.mjs" {20-38}
/**
 * TestDriver SDK - Exec Shell Test (Vitest)
 * Converted from: testdriver/acceptance/exec-shell.yaml
 */

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

describe.skip("Exec PowerShell Test", () => {
  it(
    "should generate random email using PowerShell and enter it",
    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' });

      //
      // Generate random email using PowerShell
      const randomEmail = await testdriver.exec({
        language: "pwsh",
        code: `
# Random email generator in PowerShell

# Arrays of possible names and domains
$firstNames = @("john", "jane", "alex", "chris", "sara", "mike", "lisa", "david", "emma", "ryan")
$lastNames = @("smith", "johnson", "williams", "brown", "jones", "garcia", "miller", "davis", "martin", "lee")
$domains = @("example.com", "testmail.com", "mailinator.com", "demo.org", "company.net")

# Random selection
$first = Get-Random -InputObject $firstNames
$last = Get-Random -InputObject $lastNames
$domain = Get-Random -InputObject $domains
$number = Get-Random -Minimum 1 -Maximum 1000

# Generate the email
$email = "$first.$last$number@$domain".ToLower()

# Output
Write-Output "$email"
    `,
        timeout: 10000,
      });

      // Enter the email in username field
      const usernameField = await testdriver.find(
        "Username, input field for username",
      );
      await usernameField.click();
      await testdriver.type(randomEmail);

      // Assert that the username field shows a valid email address
      const result = await testdriver.assert(
        `the username field contains ${randomEmail} which is a valid email address`,
      );
      expect(result).toBeTruthy();
    },
  );
});
```
