TestNG Integration and Execution

Test Execution Flow

Learning Outcome

5

Validate inputs and debug test failures.

4

Explain the role of browser, context, and page during execution.

3

Understand how hooks, test methods, and assertions are executed.

2

Identify the sequence from test setup to test completion.

1

Understand the test execution flow in Playwright.

Recall / Revisit

1

Playwright Architecture – Browser, BrowserContext, and Page.

2

TestNG Basics – @Test, @BeforeMethod, and @AfterMethod.

3

Locators and Actions – Finding elements and performing actions.

4

Assertions – Verifying expected and actual results.

5

Page Object Model (POM) – Separating test logic from page actions.

6

Hooks – Understanding setup and cleanup activities before and after tests.

7

Test Configuration – Running tests through TestNG and Maven.

Recall / Revisit

1

Playwright Architecture – Browser, BrowserContext, and Page.

2

TestNG Basics – @Test, @BeforeMethod, and @AfterMethod.

3

Locators and Actions – Finding elements and performing actions.

4

Assertions – Verifying expected and actual results.

5

Page Object Model (POM) – Separating test logic from page actions.

6

Hooks – Understanding setup and cleanup activities before and after tests.

7

Test Configuration – Running tests through TestNG and Maven.

Why Do We Need  State Validation?

A web element may be visible but still not be ready for interaction.

For example:

A button may be disabled.

A textbox may be read-only.

A checkbox may be unchecked.

An input field may contain an unexpected value.

State Validation verifies that the element is in the expected condition before continuing the test.

 

Engine

Is it ON?

Brake

Is it released?

Seat belt

Is it fastened?

Controls

Are they working?

Seeing the car does not mean it is ready to drive.

Imagine driving a car.

Before driving, you check:

Car

Car Control

Engine ON

Control Locked

Seat Belt Fastened

Adjustable Control

Dashboard Check

Web Application

Textbox Editable

State Validation

Checkbox Checked

Element Disabled

Element Enabled

Web Element

 Just as a driver checks the condition of a car before driving, Playwright validates the state of web elements before or after interaction.

Common State Validations

ValidationPlaywright AssertionPurpose
EnabledisEnabled()Element can be interacted with
DisabledisDisabled()Element cannot be interacted with
CheckedisChecked()Checkbox/radio is selected
EditableisEditable()Input can be modified
EmptyisEmpty()Input contains no value
ValuehasValue()Input contains expected value

Practical Assertions

Enabled

Verifies that the button is available for interaction.

assertThat(loginButton).isEnabled();

Disabled

assertThat(loginButton).isDisabled();

Verifies that the button is unavailable.

Checked

assertThat(checkbox).isChecked();

Verifies that the checkbox is selected.

Practical Assertions

Checks whether the textbox can be modified. 

Empty

Checks whether the input field contains no value. 

Editable

assertThat(searchBox).isEmpty();
assertThat(username).isEditable();

Practical Scenario

Login Form Validation

Imagine a login page where the Login button becomes enabled only after entering credentials.

Username → Editable?

Password → Editable?

Enter Credentials

Verify Values

Login Button → Enabled?

Click Login

This combines state validation + element interaction in a realistic workflow.

assertThat(username).isEditable();
assertThat(password).isEditable();
username.fill("Admin");
password.fill("Admin123");
assertThat(username).hasValue("Admin");
assertThat(loginButton).isEnabled();
loginButton.click();

Example:-

Summary

4

Close Resources and complete the test execution

3

Use isEnabled() and isDisabled() for buttons.

2

Create Context & Page and perform test actions.

1

Initialize Playwright and launch the browser.

Quiz

Which component is initialized first in a Playwright test?

A. Page

B. Browser Context

C. Playwright

D. Assertion

Quiz-Answer

Which component is initialized first in a Playwright test?

A. Page

B. Browser Context

C. Playwright

D. Assertion