microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
67.16k stars 3.69k forks source link

[Bug]: Inspector will not highlight locators that are placed inside locators #31407

Open james-potter-CeraCare opened 5 months ago

james-potter-CeraCare commented 5 months ago

Version

1.44.1

Steps to reproduce

Using the code below the test passes the first assertion as expected and fails on the second assertion citing locator('html').locator(locator('body')) as the locator.

Normally the locator cited can be copied into the inspector to check the locator, however it does not recognise locator('html').locator(locator('body'))

You need to manipulate this locator string to this: locator('html').locator('body')

test('test', async ({ page }) => {
  await page.goto('https://www.google.com/');

  let html = page.locator("html")
  let body = page.locator("body")

  let bodyCombined = html.locator(body)

  //Passes
  await expect(bodyCombined).toContainText("About")

  //Fails citing "locator('html').locator(locator('body'))"
  await expect(bodyCombined).toContainText("About1111")
});

Expected behavior

I expect locator('html').locator(locator('body')) to highlight the element in the playwright inspector

OR

The locator cited in the error to show locator('html').locator('body') (this is less perferrable)

Actual behavior

locator('html').locator(locator('body')) cited in the error returns nothing when using it in the playwright inspector

Additional context

No response

Environment

System:
    OS: Windows 10 10.0.19045
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i7-13700H
    Memory: 12.54 GB / 31.68 GB
  Binaries:
    Node: 20.14.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.7.0 - C:\Program Files\nodejs\npm.CMD
  npmPackages:
    @playwright/test: ^1.44.1 => 1.44.1 
    playwright: ^1.44.1 => 1.44.1 
    playwright-qase-reporter: ^2.0.4 => 2.0.4
marekpla commented 1 month ago

Similar problem occurs when using or() method on locator, eg. locator.or(locator2).

In such case, locator is found in test but not highlighted in inspector.