-->

Featured

DSA Interview Question

Question: Various S orting algorithms Answer: There are various sorting algorithms, each with its own advantages and disadvantages in terms ...

Playwright Quiz

 Question : Which Playwright locator is generally recommended for locating a button by its user-facing role and accessible name?

page.getByRole('button', { name: 'Submit' })

page.locator('button.submit')

page.getByTestId('submit-button')

page.locator('#submit')

Correct Answer : page.getByRole('button', { name: 'Submit' })

Question : What does Playwright automatically check before performing a standard locator.click() action?

The element is visible, stable, receives events, and is enabled

The element has a unique CSS class and an ID

The element has a specific HTML tag and text content

The element has been present in the DOM for a fixed amount of time

Correct Answer : The element is visible, stable, receives events, and is enabled

Question : What happens when a strict Playwright locator used for a single-element action matches multiple elements?

Playwright automatically clicks the first matching element

Playwright automatically clicks the last matching element

Playwright throws a strict mode violation

Playwright clicks all matching elements

Correct Answer : Playwright throws a strict mode violation

Question : Which Playwright assertion automatically retries until the locator has the expected number of matching elements?

expect(locator).toHaveCount()

expect(locator).toBeVisible()

expect(locator).toHaveAttribute()

expect(locator).toBeEnabled()

Correct Answer : expect(locator).toHaveCount()

Question : What does locator.nth(0) select in Playwright?

The last matching element

The first matching element

A random matching element

All matching elements

Correct Answer : The first matching element

Question : Which method can be used to mock a network request for a page in Playwright?

page.route()

page.mock()

page.intercept()

page.network()

Correct Answer : page.route()

Question : What is the default test ID attribute used by page.getByTestId()?

data-test

data-testid

test-id

data-pw

Correct Answer : data-testid

Question : Which Playwright feature allows tests to inspect steps, logs, errors, network requests, and DOM snapshots interactively?

UI Mode

Codegen

Trace Viewer only

Browser Console

Correct Answer : UI Mode

Question : Which locator method filters matching elements based on text contained within them?

locator.filter({ hasText: 'Product 2' })

locator.matchText('Product 2')

locator.whereText('Product 2')

locator.findText('Product 2')

Correct Answer : locator.filter({ hasText: 'Product 2' })

Question : Which API can configure a custom attribute for Playwright test IDs?

selectors.setTestIdAttribute()

selectors.setTestAttribute()

page.setTestIdAttribute()

locator.setTestIdAttribute()

Correct Answer : selectors.setTestIdAttribute()

Question : Which Playwright method is used to navigate a page to a URL?

page.goto()

page.navigate()

page.open()

page.url()

Correct Answer : page.goto()

Question : Which Playwright method is commonly used to enter text into an input field?

locator.fill()

locator.write()

locator.enter()

locator.input()

Correct Answer : locator.fill()

Question : Which Playwright locator is used to find an element by its visible text?

page.getByText()

page.getByValue()

page.getByContent()

page.getByString()

Correct Answer : page.getByText()

Question : Which Playwright locator is designed to find a form control using its associated label?

page.getByLabel()

page.getByForm()

page.getByField()

page.getByInput()

Correct Answer : page.getByLabel()

Question : Which Playwright method is used to click an element?

locator.click()

locator.tapClick()

locator.select()

locator.activate()

Correct Answer : locator.click()

Question : Which Playwright locator can be used to find an input by its placeholder text?

page.getByPlaceholder()

page.getByHint()

page.getByInputText()

page.getByPlaceholderText()

Correct Answer : page.getByPlaceholder()

Question : Which Playwright method returns the current URL of a page?

page.url()

page.currentUrl()

page.getUrl()

page.location()

Correct Answer : page.url()

Question : Which Playwright method is used to take a screenshot of a page?

page.screenshot()

page.capture()

page.takeScreenshot()

page.image()

Correct Answer : page.screenshot()

Question : Which Playwright locator is commonly used to locate an image by its alt text?

page.getByAltText()

page.getByImage()

page.getByImageText()

page.getByDescription()

Correct Answer : page.getByAltText()

Question : Which Playwright locator is used to locate an element by its title attribute?

page.getByTitle()

page.getByAttribute()

page.getByTooltip()

page.getByElementTitle()

Correct Answer : page.getByTitle()

Question : What is the main purpose of a Playwright BrowserContext?

To provide an isolated browser session with its own cookies, local storage, and session storage

To configure the browser's executable path for every test

To define the default timeout for all Playwright assertions

To store all test results in a shared browser session

Correct Answer : To provide an isolated browser session with its own cookies, local storage, and session storage

Question : Which Playwright method waits for a page to navigate to a URL matching a specified URL pattern?

page.waitForURL()

page.waitForNavigationUrl()

page.waitForLocation()

page.waitForRoute()

Correct Answer : page.waitForURL()

Question : Which Playwright method can be used to wait for a new page opened by an action such as clicking a link?

context.waitForPage()

page.waitForPopup()

page.waitForNewPage()

browser.waitForPage()

Correct Answer : page.waitForPopup()

Question : Which Playwright method is used to handle a JavaScript dialog such as alert, confirm, or prompt?

page.on('dialog', handler)

page.on('popup', handler)

page.on('alert', handler)

page.handleDialog()

Correct Answer : page.on('dialog', handler)

Question : Which Playwright API can be used to provide a mocked response for a matched network request?

route.fulfill()

route.respond()

route.mockResponse()

route.send()

Correct Answer : route.fulfill()

Question : Which Playwright API can be used to continue a network request without modifying its URL, method, or headers?

route.continue()

route.resume()

route.proceed()

route.forward()

Correct Answer : route.continue()

Question : What does the storageState option commonly allow Playwright tests to reuse?

Authentication state such as cookies and local storage

Browser executable binaries

Test screenshots and videos

Locator definitions

Correct Answer : Authentication state such as cookies and local storage

Question : Which Playwright method can be used to save the current browser context's storage state to a file?

context.storageState({ path: 'state.json' })

context.saveState('state.json')

context.exportStorage('state.json')

context.saveStorageState('state.json')

Correct Answer : context.storageState({ path: 'state.json' })

Question : Which Playwright API is used to interact with content inside an iframe?

frameLocator()

iframeLocator()

page.frameElement()

page.iframe()

Correct Answer : frameLocator()

Question : Which assertion is appropriate for verifying that an input contains a specific value?

expect(locator).toHaveValue('John')

expect(locator).toContainValue('John')

expect(locator).toEqualValue('John')

expect(locator).toMatchInput('John')

Correct Answer : expect(locator).toHaveValue('John')

Question : Which Playwright assertion verifies that an element contains the specified text?

expect(locator).toHaveText('Welcome')

expect(locator).toHaveContent('Welcome')

expect(locator).toContainTextValue('Welcome')

expect(locator).toMatchContent('Welcome')

Correct Answer : expect(locator).toHaveText('Welcome')

Question : Which Playwright method can be used to execute JavaScript in the page context?

page.evaluate()

page.executeScript()

page.runJavaScript()

page.browserEvaluate()

Correct Answer : page.evaluate()

Question : What is the purpose of the Playwright test fixture named page?

It provides an isolated Page instance for a test

It stores the test's HTML source code

It configures the browser executable

It defines the test project's retry count

Correct Answer : It provides an isolated Page instance for a test

Question : Which Playwright configuration property controls how many times a failed test is retried?

retries

retryCount

testRetries

attempts

Correct Answer : retries

Question : Which Playwright configuration property controls the number of parallel worker processes used to run tests?

workers

parallelTests

processes

concurrencyLevel

Correct Answer : workers

Question : What is the purpose of Playwright projects in the test configuration?

To run the same tests with different configurations such as browsers or environments

To create multiple browser tabs within a single page

To define multiple assertions for one test

To store screenshots separately from test results

Correct Answer : To run the same tests with different configurations such as browsers or environments

Question : Which Playwright method waits for an element to reach a specified state such as visible, hidden, attached, or detached?

locator.waitFor()

locator.waitUntil()

locator.awaitState()

locator.waitForState()

Correct Answer : locator.waitFor()

Question : Which Playwright method can be used to select an option from a standard HTML select element?

locator.selectOption()

locator.chooseOption()

locator.pickOption()

locator.select()

Correct Answer : locator.selectOption()

Question : Which Playwright method is used to upload files through a file input?

locator.setInputFiles()

locator.uploadFiles()

locator.attachFiles()

locator.setFiles()

Correct Answer : locator.setInputFiles()

Question : Which Playwright API is used to emulate a device configuration such as viewport, user agent, and device scale factor?

devices

deviceProfile()

emulateDevice()

browserDevices()

Correct Answer : devices

Question : When a Playwright locator is used with locator.all(), what does the method return?

An array of Locator objects representing the elements currently matching the locator

An array of ElementHandle objects that automatically wait for each element to appear

A single Locator that represents all matching elements

An array of DOM elements from the browser context

Correct Answer : An array of Locator objects representing the elements currently matching the locator

Question : What is a key difference between locator.all() and locator.allTextContents()?

locator.all() returns locators, while locator.allTextContents() returns the text content of matching elements

locator.all() returns text strings, while locator.allTextContents() returns locators

locator.all() waits for all elements to become visible, while locator.allTextContents() does not

locator.all() returns ElementHandle objects, while locator.allTextContents() returns DOM elements

Correct Answer : locator.all() returns locators, while locator.allTextContents() returns the text content of matching elements

Question : What happens when locator.filter({ has: anotherLocator }) is used?

It keeps elements that contain at least one descendant matching anotherLocator

It keeps elements whose own text exactly matches anotherLocator

It replaces the original locator with anotherLocator

It selects only the first element matching anotherLocator

Correct Answer : It keeps elements that contain at least one descendant matching anotherLocator

Question : In Playwright, what does expect.poll() primarily allow you to do?

Retry an arbitrary function until its returned value satisfies an assertion

Retry only locator actions until an element becomes visible

Retry a test from the beginning until it passes

Poll network requests until a response is received

Correct Answer : Retry an arbitrary function until its returned value satisfies an assertion

Question : When using page.route() with a URL pattern, which statement about route handlers is correct?

A matching request is intercepted and passed to the route handler before it continues or is fulfilled

The request is permanently blocked unless page.unroute() is called

The browser automatically retries the request before the route handler runs

The route handler is executed only after the server has returned a response

Correct Answer : A matching request is intercepted and passed to the route handler before it continues or is fulfilled

Question : What does browser.newContext({ storageState: 'auth.json' }) primarily do?

Creates a new isolated context initialized with the cookies and local storage state saved in auth.json

Launches a browser using auth.json as its executable configuration

Restores the complete browser process, including open pages, from auth.json

Creates a new context containing only the session cookies from auth.json

Correct Answer : Creates a new isolated context initialized with the cookies and local storage state saved in auth.json

Question : Which statement correctly describes Playwright's locator-based web-first assertions?

They automatically retry until the expected condition is met or the assertion timeout is reached

They execute only once and require explicit waits for dynamic elements

They wait indefinitely until the condition becomes true

They retry the entire test whenever an assertion fails

Correct Answer : They automatically retry until the expected condition is met or the assertion timeout is reached

Question : When a Playwright test creates multiple BrowserContext instances, what is the primary isolation provided between those contexts?

Each context has its own cookies, local storage, session storage, and other browser-level session data

Each context must use a different browser executable

Each context automatically runs in a separate operating-system process

Each context automatically uses a different network connection

Correct Answer : Each context has its own cookies, local storage, session storage, and other browser-level session data

Question : What does page.waitForResponse() wait for when supplied with a URL or predicate?

A network response that matches the specified URL or predicate

A page navigation that matches the specified URL or predicate

A request that has completed before the response is received

A browser context that has finished loading the specified URL

Correct Answer : A network response that matches the specified URL or predicate

Question : Why is it generally safer to start waiting for a popup before triggering the action that opens it?

It prevents a fast-opening popup from being missed by the test

It forces the popup to use the same BrowserContext as the opener

It prevents the popup from loading until the assertion completes

It guarantees that the popup will contain the expected URL

Correct Answer : It prevents a fast-opening popup from being missed by the test

Question : A login test passes locally but sometimes fails in CI because the page loads more slowly. What is the best Playwright approach?

Use a fixed page.waitForTimeout() before every action

Use web-first assertions or locator actions that automatically wait for the required state

Increase page.waitForTimeout() to several seconds

Add multiple identical clicks to ensure the action completes

Correct Answer : Use web-first assertions or locator actions that automatically wait for the required state

Question : A test needs to verify that a user is redirected to /dashboard after clicking Login. Which approach is most appropriate?

Click Login and immediately read page.url() without waiting

Click Login and use expect(page).toHaveURL(//dashboard/)

Wait for five seconds and then check page.url()

Use locator('body').toHaveText('/dashboard')

Correct Answer : Click Login and use expect(page).toHaveURL(//dashboard/)

Question : A shopping cart displays several products, and you need to click the Remove button for the product named "Laptop". What is the most reliable approach?

Click the first Remove button on the page

Use a locator for the product container and filter it by the product name, then locate its Remove button

Use page.getByRole('button', { name: 'Remove' }).first()

Use page.locator('button').nth(2)

Correct Answer : Use a locator for the product container and filter it by the product name, then locate its Remove button

Question : During a test, clicking "Export Report" opens a new browser tab. What is the appropriate way to capture that tab?

Call page.waitForTimeout() and then use browser.newPage()

Start page.waitForEvent('popup') before clicking "Export Report"

Call page.url() immediately after clicking the button

Create a second BrowserContext after clicking the button

Correct Answer : Start page.waitForEvent('popup') before clicking "Export Report"

Question : A test must verify that an API request returns HTTP status 201 when a user creates an account. Which Playwright approach is appropriate?

Use page.waitForResponse() around the action that creates the account

Use page.waitForTimeout() and inspect the browser title

Use locator.waitFor() on the API endpoint

Use page.waitForURL() with the API URL

Correct Answer : Use page.waitForResponse() around the action that creates the account

Question : A web application displays a cookie banner only for new sessions. How can a test reliably handle it without failing when it is already absent?

Check for the banner with a locator and conditionally dismiss it when present

Always click the banner's Accept button

Wait five seconds before checking the banner

Use page.reload() until the banner appears

Correct Answer : Check for the banner with a locator and conditionally dismiss it when present

Question : A test needs to verify that a downloaded PDF was created after clicking "Download". Which Playwright feature should be used?

page.waitForEvent('download')

page.waitForEvent('file')

page.waitForResponse('download')

browser.waitForFile()

Correct Answer : page.waitForEvent('download')

Question : A dashboard contains an iframe with a button named "Refresh Data". The button cannot be found using page.getByRole(). What is the likely reason and solution?

The button is inside an iframe, so use frameLocator() to locate it

The button is disabled, so use page.evaluate()

The button is hidden, so use page.waitForTimeout()

The button is outside the browser context, so create a new BrowserContext

Correct Answer : The button is inside an iframe, so use frameLocator() to locate it

Question : A test needs to verify that a user's name appears after submitting a form, but the name is loaded asynchronously. Which approach is most appropriate?

Use expect(locator).toHaveText() so the assertion can automatically retry

Use locator.textContent() immediately after submitting the form

Use page.waitForTimeout() for a fixed number of milliseconds

Read the text before submitting the form

Correct Answer : Use expect(locator).toHaveText() so the assertion can automatically retry

Question : A test suite needs to run the same tests against Chromium, Firefox, and WebKit. What is the recommended Playwright Test approach?

Create separate test files containing duplicate tests for each browser

Configure multiple Playwright projects with the required browser settings

Run all browsers manually from inside every test

Create three BrowserContexts inside every test and duplicate all assertions

Correct Answer : Configure multiple Playwright projects with the required browser settings

Question : Which code correctly verifies that a login button is visible?

expect(page.getByRole('button', { name: 'Login' })).toBeVisible()

expect(page.getByRole('button', { name: 'Login' })).visible()

page.getByRole('button', { name: 'Login' }).expectVisible()

assert(page.getByRole('button', { name: 'Login' })).isVisible()

Correct Answer : expect(page.getByRole('button', { name: 'Login' })).toBeVisible()

Question : Which code correctly fills an email input and submits a login form?

await page.getByLabel('Email').fill('user@example.com')
await page.getByRole('button', { name: 'Login' }).click()

await page.getByLabel('Email').type('user@example.com')
await page.getByRole('button', { name: 'Login' }).submit()

await page.getByLabel('Email').input('user@example.com')
await page.getByRole('button', { name: 'Login' }).click()

await page.getByLabel('Email').fill('user@example.com')
await page.getByRole('button', { name: 'Login' }).submit()

Correct Answer : await page.getByLabel('Email').fill('user@example.com')
await page.getByRole('button', { name: 'Login' }).click()

Question : Which code correctly checks that a page contains the text "Welcome"?

await expect(page.getByText('Welcome')).toBeVisible()

await page.getByText('Welcome').expectVisible()

expect(page.getByText('Welcome')).visible()

await expect(page.getByText('Welcome')).exists()

Correct Answer : await expect(page.getByText('Welcome')).toBeVisible()

Question : Which code correctly selects "India" from a standard HTML select element?

await page.locator('select#country').selectOption('India')

await page.locator('select#country').choose('India')

await page.locator('select#country').fill('India')

await page.locator('select#country').select('India')

Correct Answer : await page.locator('select#country').selectOption('India')

Question : Which code correctly waits for an API response while clicking a Save button?

const responsePromise = page.waitForResponse('**/api/save')
await page.getByRole('button', { name: 'Save' }).click()
const response = await responsePromise

const response = await page.waitForResponse('**/api/save')
await page.getByRole('button', { name: 'Save' }).click()

const responsePromise = page.waitForURL('**/api/save')
await page.getByRole('button', { name: 'Save' }).click()
const response = await responsePromise

const responsePromise = page.waitForRequest('**/api/save')
await page.getByRole('button', { name: 'Save' }).click()
const response = await responsePromise

Correct Answer : const responsePromise = page.waitForResponse('**/api/save')
await page.getByRole('button', { name: 'Save' }).click()
const response = await responsePromise

Question : Which code correctly mocks a GET request and returns a JSON response?

await page.route('**/api/products', async route => {
await route.fulfill({ status: 200, json: { products: [] } })
})

await page.mock('**/api/products', { status: 200, json: { products: [] } })

await page.route('**/api/products', async route => {
await route.respond({ status: 200, json: { products: [] } })
})

await page.intercept('**/api/products', async request => {
await request.fulfill({ status: 200, json: { products: [] } })
})

Correct Answer : await page.route('**/api/products', async route => {
await route.fulfill({ status: 200, json: { products: [] } })
})

Question : Which code correctly verifies that an input contains the value "John"?

await expect(page.getByLabel('Name')).toHaveValue('John')

await expect(page.getByLabel('Name')).toHaveText('John')

await expect(page.getByLabel('Name')).toContainText('John')

await expect(page.getByLabel('Name')).toHaveAttribute('value', 'John')

Correct Answer : await expect(page.getByLabel('Name')).toHaveValue('John')

Question : Which code correctly handles a browser popup opened by clicking a link?

const popupPromise = page.waitForEvent('popup')
await page.getByRole('link', { name: 'Open Report' }).click()
const popup = await popupPromise

const popup = await page.waitForEvent('popup')
await page.getByRole('link', { name: 'Open Report' }).click()

const popupPromise = page.waitForURL('**/report')
await page.getByRole('link', { name: 'Open Report' }).click()
const popup = await popupPromise

const popupPromise = page.waitForEvent('page')
await page.getByRole('link', { name: 'Open Report' }).click()
const popup = await popupPromise

Correct Answer : const popupPromise = page.waitForEvent('popup')
await page.getByRole('link', { name: 'Open Report' }).click()
const popup = await popupPromise

Question : Which code correctly uploads a file using a file input?

await page.locator('input[type="file"]').setInputFiles('tests/files/report.pdf')

await page.locator('input[type="file"]').upload('tests/files/report.pdf')

await page.locator('input[type="file"]').fillFile('tests/files/report.pdf')

await page.locator('input[type="file"]').setFile('tests/files/report.pdf')

Correct Answer : await page.locator('input[type="file"]').setInputFiles('tests/files/report.pdf')

Question : Which code correctly verifies that a successful login redirects the user to the dashboard?

await page.getByRole('button', { name: 'Login' }).click()
await expect(page).toHaveURL(//dashboard$/)

await page.getByRole('button', { name: 'Login' }).click()
expect(page.url()).toBe('/dashboard')

await page.getByRole('button', { name: 'Login' }).click()
await expect(page).toBeURL('/dashboard')

await page.getByRole('button', { name: 'Login' }).click()
await page.waitForURL('/dashboard')
expect(page.url()).toEqual('/dashboard')

Correct Answer : await page.getByRole('button', { name: 'Login' }).click()
await expect(page).toHaveURL(//dashboard$/)

Question : Which Playwright assertion correctly verifies that a locator contains the exact text "Order placed"?

await expect(page.getByRole('status')).toHaveText('Order placed')

await expect(page.getByRole('status')).toContainTextExact('Order placed')

await expect(page.getByRole('status')).toBeText('Order placed')

await expect(page.getByRole('status')).toHaveContent('Order placed')

Correct Answer : await expect(page.getByRole('status')).toHaveText('Order placed')

Question : Which Playwright assertion correctly verifies that a checkbox is checked?

await expect(page.getByRole('checkbox')).toBeChecked()

await expect(page.getByRole('checkbox')).toHaveCheckedState()

await expect(page.getByRole('checkbox')).toBeSelected()

await expect(page.getByRole('checkbox')).toHaveState('checked')

Correct Answer : await expect(page.getByRole('checkbox')).toBeChecked()

Question : Which Playwright assertion correctly verifies that a button is disabled?

await expect(page.getByRole('button', { name: 'Submit' })).toBeDisabled()

await expect(page.getByRole('button', { name: 'Submit' })).toHaveDisabled()

await expect(page.getByRole('button', { name: 'Submit' })).toBeInactive()

await expect(page.getByRole('button', { name: 'Submit' })).toHaveState('disabled')

Correct Answer : await expect(page.getByRole('button', { name: 'Submit' })).toBeDisabled()

Question : Which Playwright assertion correctly verifies that an input has the placeholder "Enter email"?

await expect(page.getByLabel('Email')).toHaveAttribute('placeholder', 'Enter email')

await expect(page.getByLabel('Email')).toHavePlaceholder('Enter email')

await expect(page.getByLabel('Email')).toHaveProperty('placeholder', 'Enter email')

await expect(page.getByLabel('Email')).toContainAttribute('placeholder', 'Enter email')

Correct Answer : await expect(page.getByLabel('Email')).toHaveAttribute('placeholder', 'Enter email')

Question : Which Playwright assertion correctly verifies that exactly three rows match a locator?

await expect(page.locator('table tbody tr')).toHaveCount(3)

await expect(page.locator('table tbody tr')).toHaveRows(3)

await expect(page.locator('table tbody tr')).toContainCount(3)

await expect(page.locator('table tbody tr')).toHaveLength(3)

Correct Answer : await expect(page.locator('table tbody tr')).toHaveCount(3)

Question : Which locator correctly finds a button using its accessible role and name?

page.getByRole('button', { name: 'Save' })

page.getByElement('button', 'Save')

page.findByRole('button', 'Save')

page.locatorRole('button', { name: 'Save' })

Correct Answer : page.getByRole('button', { name: 'Save' })

Question : Which locator correctly finds an input associated with the label "Username"?

page.getByLabel('Username')

page.getByText('Username')

page.getByRole('input', { label: 'Username' })

page.getByField('Username')

Correct Answer : page.getByLabel('Username')

Question : Which locator correctly finds a textbox using its placeholder?

page.getByPlaceholder('Enter username')

page.getByRole('textbox', { placeholder: 'Enter username' })

page.getByInputPlaceholder('Enter username')

page.locatorPlaceholder('Enter username')

Correct Answer : page.getByPlaceholder('Enter username')

Question : Which locator correctly targets the second matching element?

page.getByRole('button').nth(1)

page.getByRole('button').second()

page.getByRole('button').index(2)

page.getByRole('button').at(2)

Correct Answer : page.getByRole('button').nth(1)

Question : Which locator correctly finds a list item containing the text "Product A"?

page.getByRole('listitem').filter({ hasText: 'Product A' })

page.getByRole('listitem').contains('Product A')

page.getByRole('listitem', { text: 'Product A' })

page.getByText('Product A').parent('listitem')

Correct Answer : page.getByRole('listitem').filter({ hasText: 'Product A' })

Question : Which Playwright configuration option specifies the directory where test files are located?

testDir

testPath

testsDirectory

specDir

Correct Answer : testDir

Question : Which Playwright configuration option sets the base URL used by page.goto() when a relative URL is provided?

baseURL

baseUrlPath

urlBase

testBaseURL

Correct Answer : baseURL

Question : Which Playwright configuration option defines which test reporter is used?

reporter

testReporter

reporting

outputReporter

Correct Answer : reporter

Question : A test needs to locate a button whose text may change slightly but whose accessible role and name remain stable. What is the recommended approach?

Use a role-based locator with the accessible name

Use a fixed XPath based on the button's DOM position

Use a CSS selector containing generated class names

Use a fixed wait followed by clicking the first button

Correct Answer : Use a role-based locator with the accessible name

Question : A test sometimes fails because an element appears asynchronously. What is the preferred Playwright approach?

Use locator-based actions or web-first assertions that automatically wait

Add page.waitForTimeout() before every action

Use setTimeout() to delay the test

Reload the page until the element appears

Correct Answer : Use locator-based actions or web-first assertions that automatically wait

Question : A test needs to select a specific "Delete" button belonging to one particular product row. What is the best practice?

Locate the product row first, then locate its Delete button

Click the first Delete button on the page

Use a fixed nth() index based on the current page layout

Use a long XPath based on multiple ancestor levels

Correct Answer : Locate the product row first, then locate its Delete button

Question : A test needs to verify that a page displays a user's name after an API call completes. What is the best practice?

Use a web-first assertion on the user's name

Wait a fixed number of seconds before checking the name

Use a hard-coded sleep before every assertion

Use page.evaluate() to repeatedly inspect the DOM

Correct Answer : Use a web-first assertion on the user's name

Question : A test must verify that a login request succeeds and the dashboard is displayed. What is the best practice for synchronization?

Start waiting for the relevant response or page state before triggering the login action

Add a fixed five-second delay after clicking Login

Poll page.url() inside a manual loop

Reload the page after clicking Login

Correct Answer : Start waiting for the relevant response or page state before triggering the login action

No comments:

Post a Comment

popular posts