Playwright with Typescript|UI Components|Input Fields | 15

Published: 20 September 2025
on channel: AshwaniQA
5
0

1. **Introduction to Mastering UI Elements**:
**Overview**: This section focuses on automating various UI components, starting with input fields.
**Setup**: Create a new spec file `uiComponents.spec.ts` and set up necessary imports and hooks for the test.

2. **Automating Input Fields**:
**Navigating to Form Layouts**: Use the `beforeEach` hook to navigate to the Form Layouts page.
**Locating Input Fields**: Define locators for input fields using `page.locator`.
**Example**: `const UsingTheGridEmailInput = page.locator('nb-card:has-text("Using the Grid")').locator('role=textbox[name="Email"]')`.

3. **Typing into Input Fields**:
**Typing Text**: Use the `fill` method to type text into input fields.
**Example**: `await UsingTheGridEmailInput.fill('test@test.com')`.
**Clearing Text**: Use the `clear` method to clear text from input fields.
**Example**: `await UsingTheGridEmailInput.clear()`.
**Press Sequentially**: Simulate keystrokes with optional delays.
**Example**: `await UsingTheGridEmailInput.press('test2@test.com')`.
**Delays**: Add a delay between keystrokes to simulate slower typing.
**Example**: `await UsingTheGridEmailInput.press('test2@test.com', { delay: 500 })`.

4. **Making Assertions**:
**Generic Assertions**: Extract the text from the input field and assert its value.
**Example**:
```javascript
const inputValue = await UsingTheGridEmailInput.inputValue();
expect(inputValue).toEqual('test2@test.com');
```
**Locator Assertions**: Use the `toHaveValue` method for direct assertions on locators.
**Example**: `await expect(UsingTheGridEmailInput).toHaveValue('test2@test.com')`.

5. **Practical Examples**:
**Typing and Clearing Text**: Demonstrate typing, clearing, and retyping text in input fields.
**Simulating Keystrokes**: Show how to simulate slow typing using the `press` method with delays.
**Assertions**: Perform both generic and locator-specific assertions to validate input field values.

6. **Summary**:
**Typing Text**: Use the `fill` method to input text.
**Clearing Text**: Use the `clear` method to remove text.
**Simulating Keystrokes**: Use the `press` method for keystrokes and add delays as needed.
**Assertions**: Extract values with `inputValue` for generic assertions or use `toHaveValue` for locator assertions.


On this page of the site you can watch the video online Playwright with Typescript|UI Components|Input Fields | 15 with a duration of hours minute second in good quality, which was uploaded by the user AshwaniQA 20 September 2025, share the link with friends and acquaintances, this video has already been watched 5 times on youtube and it was liked by 0 viewers. Enjoy your viewing!