> ## Documentation Index
> Fetch the complete documentation index at: https://e2e.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# बुनियादी कॉन्सेप्ट

> लक्ष्य, असर्शन और लोकेटर क्या हैं, और इनसे टेस्ट कैसे ऑर्गनाइज़ करें और चलाएँ।

एक टेस्ट में ये तीन तरह के स्टेप मिलाकर लिखे जाते हैं:

| स्टेप | API | मॉडल कॉल |
| --- | --- | --- |
| [लक्ष्य](#goals) | `agent.act` | हाँ, अगर [कैश](https://e2e.com/docs/hi/cache) उसे रीप्ले नहीं करता |
| [असर्शन](#assertions) | `agent.assert`, `agent.waitFor`, `agent.extract` | हाँ |
| [लोकेटर](#locators) | `screen` और `expect` | नहीं |

[कस्टम एक्ज़ीक्यूटर](https://e2e.com/docs/hi/executors) हो, तो `act` और `assert` को मॉडल की ज़रूरत नहीं
पड़ती।

```ts title="tests/todos.e2e.ts"

describe('todos', () => {
  test('the Done filter shows only completed todos', async ({ app, agent, screen }) => {
    await app.open('/todos');
    await agent.act('add todos "Buy milk" and "Walk the dog"');
    await agent.act('complete "Buy milk"');
    await agent.waitFor('"Buy milk" is completed and "Walk the dog" is open');

    await screen.getByRole('tab', 'Done').tap();

    await expect(screen.getByTestId('todo')).toHaveCount(1);
    await agent.assert('the only todo listed is "Buy milk"');
  });
});
```

हर टेस्ट एक बिहेवियर चेक करता है, तीन हिस्सों में: पहले शुरुआती स्थिति तैयार
करें, फिर उस बिहेवियर पर एक्शन लें, और आख़िर में नतीजे पर असर्शन करें।

हर एजेंट कॉल, स्क्रीन कॉल और `expect.poll` को await करें। अगर कोई स्टेप अभी चल
ही रहा हो और टेस्ट रिटर्न हो जाए, तो टेस्ट `STEP_NOT_AWAITED` के साथ फ़ेल हो
जाता है।

## लक्ष्य

`agent.act` एक लक्ष्य लेता है और उसके लिए जो एक्शन चाहिए, वे करता है। लक्ष्य
पूरा होते ही यह रिटर्न करता है। लक्ष्य फ़ेल हो, तो यह थ्रो करता है।

```ts
await agent.act('complete checkout with the test card');
await agent.act('invite {email} as an editor', { params: { email: 'ada@example.test' } });
```

हर लक्ष्य एटॉमिक रखें: एक नतीजा, जिसे एक चेक कन्फ़र्म कर दे। अगर किसी निर्देश
के दो हिस्से अलग-अलग ऐसी स्थिति पर पहुँचते हैं जो चेक करने लायक है, तो वे दो
लक्ष्य हैं। एक टेस्ट में कई लक्ष्य हो सकते हैं।

```ts title="Bad: three goals in one call, no check between them"
await agent.act('open the Pro plan, set the seats to {seats}, and check out', {
  params: { seats: 3 },
});
```

```ts title="Good: one atomic goal per call, arrange, act, assert"
test('checks out the Pro plan', async ({ app, agent, screen }) => {
  await app.open('/plans');
  await agent.act('open the Pro plan');
  await agent.act('set the seats to {seats}', { params: { seats: 3 } });
  await agent.waitFor('the cart shows the Pro plan with 3 seats');

  await agent.act('check out');

  await expect(screen.getByText('Order confirmed')).toBeVisible();
});
```

सेटअप वाले लक्ष्य पहले आते हैं, और उनके आख़िर में उस स्थिति का इंतज़ार होता है
जहाँ वे पहुँचते हैं। फिर वह लक्ष्य आता है जिसे आप टेस्ट कर रहे हैं। उसके नतीजे
पर असर्शन सबसे आख़िर में आते हैं। ऐसा करने से फ़ेलियर उस लक्ष्य का नाम
बताता है जो टूटा। हर लक्ष्य अपनी रिकॉर्डिंग से रीप्ले होता है, और मॉडल कॉल और
एक्शन के लिए उसे अपने अलग [बजट](https://e2e.com/docs/hi/reference/agent#budgets) मिलते हैं। किसी एक
नतीजे तक पहुँचने वाले एक्शन लक्ष्य नहीं होते: जैसे कंट्रोल वाली स्क्रीन या
मेन्यू खोलना, उस तक स्क्रॉल करना, कोई बैनर बंद करना, या एक फ़ॉर्म के फ़ील्ड
भरना।

- लक्ष्यों का ऑर्डर आप तय करते हैं। एक्शन एजेंट चुनता है।
- टेस्ट के आख़िर में नतीजे पर एक `expect` रखें। [रीप्ले कैश](https://e2e.com/docs/hi/cache) किसी लक्ष्य
  को तभी रिकॉर्ड करता है, जब उसके बाद का कोई चेक या इंतज़ार पास हो जाए।
- वही शब्द लिखें जो स्क्रीन पर दिखते हैं।
- टेस्ट डेटा `params` में दें। पासवर्ड के लिए `Secret` दें। मॉडल को उसकी वैल्यू
  टेक्स्ट में कभी नहीं मिलती। [ऑथेंटिकेशन](https://e2e.com/docs/hi/authentication) देखें।
- जो वैल्यू हर रन में बदलती है, उसके लिए `unique()` इस्तेमाल करें, ताकि
  [कैश उस स्टेप को रीप्ले कर सके](https://e2e.com/docs/hi/cache#what-must-match):

```ts

const email = `ada+${Date.now()}@example.test`;
await agent.act('sign up with email {email}', { params: { email: unique(email) } });
```

`act` को जब ज़रूरत होती है, तब उसे स्क्रीनशॉट मिलते हैं। कुछ इंजनों पर यह इमेज
के पॉइंट्स पर टैप और टाइप कर सकता है।

अगर कोई लक्ष्य फ़ेल हो, तो रिपोर्ट पढ़ें और निर्देश को और स्पेसिफ़िक बनाएँ। जो
शब्द कई लक्ष्यों में आते हैं, उन्हें एजेंट के [`context`](https://e2e.com/docs/hi/agents) में डाल दें।

## असर्शन

असर्शन स्क्रीन को परखता है। मॉडल को ये चीज़ें दिखती हैं: स्टेटमेंट, मौजूदा
स्क्रीन का टेक्स्ट स्नैपशॉट (सीक्रेट छिपाकर), स्क्रीन की लोकेशन, और एजेंट का
कॉन्टेक्स्ट। पिछले स्टेप उसे नहीं दिखते, और `act` की समरी भी नहीं।

- `agent.assert` स्क्रीन को अभी इसी वक़्त चेक करता है। स्टेटमेंट गलत हो, तो यह
  `ASSERTION_FAILED` के साथ फ़ेल होता है। सबूत काफ़ी न हों, तो
  `ASSERTION_INCONCLUSIVE` के साथ फ़ेल होता है।
- `agent.waitFor` तब तक रुकता है जब तक कोई शर्त सच न हो जाए। यह मॉडल को तभी
  कॉल करता है जब स्क्रीन या उसकी लोकेशन बदलती है।
- `agent.extract` स्क्रीन से डेटा पढ़कर किसी
  [Standard Schema](https://standardschema.dev) टाइप में देता है, जैसे Zod।

```ts

await agent.assert('the dashboard shows a trial badge');
await agent.waitFor('a download link appears', { timeout: 120_000 });
await agent.assert('the chart trends upward', { vision: true });

const data = await agent.extract('every todo title', {
  schema: z.object({ titles: z.array(z.string()) }),
});
expect(data.titles).toContain('Buy milk');
```

मॉडल का लिखा टेक्स्ट चेक करते समय उसका मतलब देखें, पूरा वाक्य नहीं। जहाँ टेक्स्ट
हूबहू मायने रखता हो, वहाँ [लोकेटर](#locators) इस्तेमाल करें।

विज़ुअल चेक के लिए, जैसे कोई चार्ट या लेआउट, `vision: true` जोड़ें। सिर्फ़
स्क्रीनशॉट से परखना हो, तो `vision: 'only'` इस्तेमाल करें। इमेज से इनपुट टोकन
बढ़ते हैं। [एजेंट रेफ़रेंस](https://e2e.com/docs/hi/reference/agent#vision) देखें।

## लोकेटर

लोकेटर किसी जाने-पहचाने कंट्रोल को बिना मॉडल कॉल के ढूँढता है। जब आपको पक्का
पता हो कि कौन सा एक्शन करना है या कौन सी वैल्यू चाहिए, तब इसे इस्तेमाल करें।

```ts
// Role and name first, label second, test ID last.
await screen.getByRole('button', 'Sign in').tap();
await screen.getByLabel('Email').fill('ada@example.test');

// Scope into a row.
const row = screen.getByRole('listitem').filter({ hasText: 'Design review' });
await row.getByRole('button', 'Archive').tap();

// Gestures and coordinates.
await screen.swipe({ direction: 'up' });
await screen.getByRole('image', 'Seat map').tap({ position: { x: 120, y: 48 } });

// Assertions retry until they pass or time out.
await expect(screen.getByRole('status')).toHaveText('2 remaining');
```

- अगर क्वेरी को एक से ज़्यादा नोड मिलें, तो एक्शन, रीड या सिंगल-नोड असर्शन फ़ेल
  हो जाता है। एक ही नोड तक पहुँचने के लिए `.filter()`, `.first()` या `.nth()`
  इस्तेमाल करें।
- `textContent()` जैसा डायरेक्ट रीड पहले अपने मैच का इंतज़ार करता है, फिर एक बार
  पढ़ता है। किसी वैल्यू के लिए यह रीट्राई नहीं करता।

[screen रेफ़रेंस](https://e2e.com/docs/hi/reference/screen) और
[expect रेफ़रेंस](https://e2e.com/docs/hi/reference/expect#locator-matchers) देखें। रूट, कुकी, डायलॉग और
डाउनलोड के लिए [ब्राउज़र के साथ काम करना](https://e2e.com/docs/hi/reference/web) देखें।

## टेस्ट ऑर्गनाइज़ करें

```ts

describe('billing', { tags: ['billing'] }, () => {
  beforeEach(async ({ app }) => { await app.open('/billing'); });

  test('upgrades', { retries: 2, timeout: 60_000 }, async ({ agent }) => {
    await agent.act('upgrade to Pro');
  });
});

test('needs two organizations', async ({ app }) => {
  test.skip((await countOrganizations()) < 2, 'nothing to switch to');
  await app.open('/organizations');
});
```

- हर टेस्ट अपने अलग अटेम्प्ट में चलता है। उसे उसी स्क्रीन के पास से शुरू करें
  जिसे वह चेक करता है, ताकि हर रन में वहाँ तक पहुँचने वाले क्लिक बच जाएँ। उसका
  डेटा फ़िक्स्चर या हुक में बनाएँ। ब्राउज़र में
  [सेव किया हुआ सेशन](https://e2e.com/docs/hi/authentication) रिस्टोर करें और स्क्रीन को उसके पाथ से
  खोलें। डिवाइस पर [डीप लिंक](https://e2e.com/docs/hi/mobile#the-device-fixture) खोलें।
- `test.skip(condition, reason)` शर्त सच होने पर टेस्ट को `skipped` के रूप में
  रोक देता है।
- कई टेस्ट में फैले फ़्लो के लिए ग्रुप पर `{ serial: true }` सेट करें। तब टेस्ट
  एक ही वर्कर पर एक के बाद एक चलते हैं, और रीट्राई भी साथ में होते हैं।
- सेटअप और क्लीनअप के लिए `test.extend` इस्तेमाल करें।
  [फ़िक्स्चर लिखना](https://e2e.com/docs/hi/fixtures) देखें।
- `browser`, `device` या `desktop` फ़िक्स्चर का टाइप पाने के लिए `test` को
  `@e2e-dev/web`, `@e2e-dev/mobile` या `@e2e-dev/desktop` से इंपोर्ट करें।

सारे ऑप्शन [test रेफ़रेंस](https://e2e.com/docs/hi/reference/test) में हैं।

## एक टेस्ट चलाएँ

<CodeGroup>
```bash npm
npx e2e run tests/signup.e2e.ts:12   # the test at line 12
npx e2e run --grep checkout          # tests with a matching title
npx e2e run --target web             # one target
```

```bash pnpm
pnpm exec e2e run tests/signup.e2e.ts:12   # the test at line 12
pnpm exec e2e run --grep checkout          # tests with a matching title
pnpm exec e2e run --target web             # one target
```

```bash bun
bunx e2e run tests/signup.e2e.ts:12   # the test at line 12
bunx e2e run --grep checkout          # tests with a matching title
bunx e2e run --target web             # one target
```
</CodeGroup>

सारे फ़्लैग [CLI रेफ़रेंस](https://e2e.com/docs/hi/reference/cli#e2e-run) में हैं।

## आगे

<CardGroup cols={2}>
  <Card title="कैशिंग" icon="box-archive" href="/cache">
    पास हुए लक्ष्यों को बिना मॉडल कॉल के रीप्ले करें।
  </Card>
  <Card title="एजेंट स्टेप कैसे काम करते हैं" icon="list-check" href="/agent-steps">
    फ़ैसले, एग्ज़िट कोड, और मॉडल को क्या दिखता है।
  </Card>
</CardGroup>
