Playwright interview questions and answers: Part1

1. What is Playwright ?

A free and open-source tool for testing automation of web applications and API.

 

2. What are the benefits of using Playwright ?

- it is a free and open-source tool.

- It supports multiple languages: Java, Python, JavaScript, TypeScript, and .NET (including C#).

- supports multiple browsers: Chromium (Google Chrome and Microsoft Edge), WebKit (Safari), and Firefox. 

- supports multiple testing platforms/operating systems: Windows, MacOS, Linux

- It has easy setup and configuration

- It includes built-in reporting options and supports custom reporters.

- it has its own locators/selectors, such as getByRole(), getByText(), and getByTestId().

- It supports screenshots, visual snapshot comparisons, and video recording when configured.

- it has auto wait 

- it supports recording and replaying. Codegen records user interactions and generates test code; traces can help you inspect and debug executions.

- it provides easy debug and re-running of failed tests. It offers debugging tools, Trace Viewer, and test retries when configured.

- it allows testing multiple tabs(contexts) and multiple browser instances.

- it supports mobile testing. It supports mobile browser/device emulation, but it is not a native mobile app automation tool like Appium.

- it supports API testing

- it is faster than other test automation tools in general.

- allows running the test in headed and headless modes

- supports parallel execution. Tests can run in parallel using workers and across multiple CI jobs.

- supports CICD and Docker. It integrates with CI pipelines and provides official Docker images.

 

3. How you run a playwright test in a particular browser from command line ?

npx playwright test --project=chromium

npx playwright test --project=firefox

npx playwright test --project=webkit

 

4. What are the steps to install and configure Playwright?
1. Downlaod and Intall Node.js
2. Download and install VS Code
3. Create a project folder in your computer
4. Open the folder in VS Code
5. Initialize Playwright:
npm init playwright@latest --> this will install latest version of playwright.
6. While configuring the playwright, select JavaScript or TypeScript, the test folder, and whether to add a CI workflow.
7. Install browsers, run:
npx playwright install 
npx playwright install — Installs the supported browser binaries.
npx playwright install chromium — Installs only Chromium.
 

5. What is a fixture in Playwright ?

A fixture is a reusable setup mechanism that provides the objects or resources a test needs and manages their lifecycle, including setup before the test and cleanup afterward.

Let’s compare with a resturant:

·        Before the customer arrives: The restaurant prepares the table, cutlery, napkins, and water.

·        When the customer arrives: Everything is ready to use.

·        After the customer leaves: The restaurant cleans the table and prepares it for the next customer.

Similarly, in Playwright, fixtures prepare resources before a test and clean them up when the test finishes.

"Fixtures do setup before running the test and cleanup afterward."

For example, the page fixture provides a browser page and manages its lifecycle, including closing it after the test.

Can we override fixtures and create custom fixtures?

Yes! We can extend built-in fixtures or override them to customize their behavior.

 

6. How does the “page” fixture work?

Consider this example:

javascript

test('this is a test', async ({ page }) => {
  await page.goto('https://example.com');
});

Here is what happens behind the scenes:

  1. Playwright starts or reuses a browser instance as needed.
  2. It creates an isolated browser context for the test.

3. It creates a page within that context and injects it into your test through { page }.

4. Your test uses page to navigate and interact with the website.

  1. After the test finishes, Playwright cleans up the page and its context automatically.

You don't need to manually create or close these resources when using the standard Playwright Test fixtures.

 

 7. What is the difference between NPM and NPX?

  • NPM (Node Package Manager): It is used to install, update, and manage JavaScript packages and their dependencies. For example, we use

npm init playwright@latest to set up a Playwright project.

  • NPX (Node Package Executor): It is used to execute packages or commands without necessarily installing them globally. For example, we use

npx playwright test to execute Playwright tests.

 

 8. What are "async" and "await" in Playwright ?

"async" represents an asynchronous function. It makes the function return a promise.
"await" makes the async function wait for the promise to settle. The promise could settle with the result as fulfilled or rejected. After the promise is settled, the function moves with the next step. It throws an error if the promise is rejected, as per the error handling methods applied.


In Playwright, we use async and await to ensure the browser actions such as navigation, clicking, filling etc.
For example:

test('Login to the account page.', async ({ page }) => {
  await page.goto('https://example.com');
await page.fill('#username', 'user123');
await page.locator().fill('password', '*********');
  await page.click('#login');
});

Here's what happens:

    async allows the test function to use await.

    await page.goto(...) waits for the navigation operation to complete according to Playwright's navigation rules.

    await page.fill(...) waits for Playwright to complete the fill operation.

    await page.click(...) waits for Playwright to complete the click operation.
    The next statement executes after the click Promise fulfills. If an awaited operation throws an error, execution jumps to error handling or the test fails.

What happens while await is waiting?
Suppose you execute:

await page.goto('https://example.com');

JavaScript does not freeze the entire program while waiting. Instead, the async function pauses at that line, allowing the JavaScript event loop to process other available work. Once the Promise settles, the function resumes.

 

 9. How you manage the failed test cases in Playwright? 

In Playwright, we use the retries option to rerun failed test cases a specified number of times.

There are two ways to configure retries:

    Configuration file: Set retries in playwright.config.js.
    Command line: Use npx playwright test --retries=1 to retry failed tests once.

If retries are configured in both places, the command-line option overrides the configuration file setting.

One important note: Retries apply to failed tests, not every test. By default, retries are set to 0.

 

 


AEM – Adobe Experience manager, Interview questions and answers - Part 1

1.     What is AEM – Adobe Experience Manager?

AEM (Adobe Experience Manager) is a content management system (CMS) or tool used to create, manage, and deliver digital content and web pages. It uses templates, containers, components, assets, and content to build web pages.

 

2.     What are the roles in AEM ?

There are mainly two roles in AEM: Author and Publisher.

·                  Author: Creates and manages pages, components, assets, and other content in the Author instance.

·                  Publisher: Makes the approved content available to end users on the Publish instance.

·                  Admin: Manages users, groups, permissions, and access.

 

3.     What is DAM in AEM ?

DAM (Digital Asset Management) is a section in AEM used to store, organize, manage, and reuse digital assets such as images, videos, and documents. Authors can use these assets while creating or editing pages.

 

4.     What is template in AEM ?

A template is the basic layout or structure of a page. The author uses the template to create a page and adds containers, components, headers, footers, images, videos, and other content as required. A template acts as a blueprint for creating pages.

 

5.     What is container in AEM ?

A container is a section or area on an AEM page where authors can add and arrange components. The author can add components such as carousels, forms, images, text, videos, and other content inside the container as required. A page can have multiple containers, each containing different components.

 

6.     What is component in AEM ?

A component is a reusable building block in AEM. The author adds components to containers while creating a page. Different components are used for different purposes, such as displaying text, images, videos, links, buttons, forms, carousels, page header, page footer and other content. Each component provides specific fields and options that the author can use based on the requirement.

 

So, the relationship of Template, Container and Components can be mentioned like this:

·                  Template → Blueprint/structure of the page

·                  Container → Area where components are placed

·                  Component → Building block that displays specific content or functionality

So you can explain it as:

Template → Container → Component → Content.

    

7.     What is a Core Component in AEM?

Core Components are standard, reusable components provided by Adobe with AEM. They provide common functionality such as Text, Image, Button, Title, Navigation, Breadcrumb, Carousel, and more.

Developers can use these components as they are or customize/extend them according to the project requirements.

 

8.     What is Experience Fragment in AEM ?

An Experience Fragment (XF) is a reusable group of components and content in AEM that can be reused across multiple pages, sites, and channels.

 

Examples of Experience Fragments include page headers, page footers, banners, sales promotions, contact sections, etc.

 

If we need to make an update, we can make the change in the Experience Fragment, and the updated content will be reflected wherever that Experience Fragment is being used.

 

9.     What is banner in AEM ?

A banner is a section on a webpage used to display important or promotional information. It can be used on one or multiple pages. A banner may contain announcements, sales promotions, public notifications, or other important information. It can include text, title, heading, links, buttons, images, videos, and other content.

 

10.  What is Carousel component in AEM ?

A Carousel is a component that contains multiple slides. An author can configure each slide with content such as a title, heading, text, links, buttons, images, videos, and other content. Users can navigate between the slides using navigation arrows, icons, or other controls.