> ## 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/browser) देखें।

## टेस्ट व्यवस्थित करें

```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');
});
```

- हर टेस्ट अपने अलग प्रयास (attempt) में चलता है। उसे उस स्क्रीन के पास से शुरू करें जिसे वह
  जाँचता है, ताकि हर रन वहाँ तक ले जाने वाले क्लिक छोड़ दे। उसका डेटा फ़िक्स्चर या
  हुक में बनाएँ। ब्राउज़र में [सेव किया हुआ सेशन](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` फ़िक्स्चर को टाइप करने के लिए `test` को `@e2e-dev/web` या
  `@e2e-dev/mobile` से इंपोर्ट करें।

[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>
