Coder Social home page Coder Social logo

Comments (2)

pavelfeldman avatar pavelfeldman commented on May 10, 2024

It is unlikely that we make steps for sync operations since e2e tests are inherently async and there is an await workaround. Closing as out of scope for Playwright.

Btw, this.page.locator('.task-item').filter({ has: / * some other complex locators */}) isn't really "getting" the locator, it just builds a selector string in memory for this locator.

from playwright.

alvaromartmart avatar alvaromartmart commented on May 10, 2024

It is unlikely that we make steps for sync operations since e2e tests are inherently async and there is an await workaround. Closing as out of scope for Playwright.

Fair enough. I was actually wondering, while writing the issue, if a synchronous test.step could actually break functionality in reporter(s), for instance. It was a QoL ask anyway.

Btw, this.page.locator('.task-item').filter({ has: / * some other complex locators */}) isn't really "getting" the locator, it just builds a selector string in memory for this locator.

I understand how Playwright locators work 😄 - I don't see what's wrong with my statement or example code, the method does return a Locator. It just encapsulates the logic inside a POM method so the person developing the test doesn't need to remember how to build that specific locator.

This is what I would normally do, with the -supported- async test.step

// POM
class TodoPage {
    // [...]
   getLocatorForTask(contents: string): Promise<Locator> {
     return test.step(`[TodoPage] get locator for task containing "${contents}" in either name or description`, () => {
       return this.page.locator('.task-item').filter({ has: / * some other complex locators */});
     });
   }
}
// test
await expect(await todoPage.getLocatorForTask('foo')).toBeVisible();

(I can of course get rid of the cosmetic test.step and make the method syncrhonous, but that wasn't the main point - maybe I didn't pick the best example)

from playwright.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.