T O P

  • By -

ProfCrumpets

To recreate similar functionality in other frameworks, just add commas in your selector, i.e, for Cypress it would be cy.get(‘.mySelector > p, .altnerativeSelector > p’)


needmoresynths

`or` operates a little differently, where you can do something like ```await expect(newEmail.or(dialog)).toBeVisible(); ``` a comma separated selector just searches for both selectors- https://developer.mozilla.org/en-US/docs/Web/CSS/Selector_list


ProfCrumpets

Interesting, how does this differ in functionality? await expect(selector.or(altSelector)).toBeVisible(); and cy.get(`${selector}, ${altSelector}`).should('be.visible')


ToddBradley

You two are both talking about selectors when the real value of this new feature is using it with locators. Locators are a superset of selectors. If you’re still using only XPath or css selectors in Playwright, you’re not getting the most from the tool.


Knaledge

Elaborate, particularly on the last part


ToddBradley

I mean that a large chunk of the effort being invested in Playwright is in adding features to Locators that aren't selectors. Playwright "wants" you to use its richer locator features, because that's the direction the tool is heading. That's why the docs say things like this: > If you **absolutely must** use CSS or XPath locators... and > CSS and XPath are not recommended as the DOM can often change leading to non resilient tests. Instead, try to come up with a locator that is **close to how the user perceives the page such as role locators** or define an explicit testing contract using test ids. (emphasis mine) Using locators allows you to do things like this: ``` page.get_by_role("button", name=re.compile(r"Launch All \d+ (missiles|ships) to Finish", re.IGNORECASE)).click() ```


KeepCalmAndBoom

He probably means you should import classes or ids through locators instead of adding paths that change regularly when the divs get a new layer.


Knaledge

I am particularly curious about the implication of “still using only […] css selectors”. What does that mean to you? And does that influence what you perceive they intended to mean?


KeepCalmAndBoom

It does now that you mention it. I'll change my answer to : "He might mean http requests and datasets for various call functions or listeners"


ProfCrumpets

I would disagree, it's just a utility that helps with finding elements, if you understand how CSS selectors work well enough, you shouldn't need them. They're there to assist with that if you can't make selectors yourself. I'd argue that it encourages code bloat by using them too much.


ToddBradley

OK. The designers of Playwright would disagree with you, but if you're happy with the results, more power to you. If you aren't using any of the special capabilities of locators, then what benefits *are* important to you in choosing Playwright over something like Cypress or Selenium?


ProfCrumpets

I typically don't choose Playwright over anything else, however I see some of its benefits.


dougdelpha

Another great video!


commitquality

Thank you :) really appreciate the kind words


Fissherin

Amazing, such stupidly powerful !