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
66.52k stars 3.64k forks source link

[Feature] Adapt the codegen feature to generate Page Object Model files #12330

Open maxandrezils opened 2 years ago

maxandrezils commented 2 years ago

Add a flag to the codegen feature (i.e. --pom=true) that allows one to generate Page Object Model files for your tests based on the clicked elements.

AlexKomanov commented 2 years ago

Upvoting this one!

NikkTod commented 2 years ago

This one is needed.

GeorgeFischhof commented 2 years ago

Hi, I wanted to say almost exactly the same :) It is all the same for me how to switch it on, but like the --pom / --pom=true switches, also a button is good for me on recorder ui.

I created a POC POM ;) in Python, I think some similar would be good, that is for PyTest, files are attached in zip UI_POM_POC.ZIP

BR, George

NerdishShah commented 1 year ago

Upvoting, any ETA for it?

dgisq commented 1 year ago

+1

renjujv commented 1 year ago

+1. Absolutely a great feature to have.

vitalets commented 1 year ago

Could anybody show an example how generated test will look like?

infinitejest69 commented 11 months ago

+1, not sure if the complexity is generating a test as well as a POM at the same time. i would settle for a POM only mode as most of the time the recorded tests needs to be re-written to use existing POM's. a POM only mode would save so much time standing up new projects or pages.

marekbrtkwcz commented 7 months ago

Great feature for me

thatpeskylimey commented 7 months ago

This would be very helpful!

refactoreric commented 4 months ago

This would be super-complex to implement. How would Playwright know which things belong together in which POMs? Do we create one POM per URL? In many cases that would create lots of duplicate POMs with all the elements for the whole page(s) (including all the common components). So the generator would need to be intelligent enough to know which are the unique pages, and which things on the page are components. What complicates the matter further is that Web UI components are often a random group of HTML elements, and how you can identify them as a component differs per UI library. Besides all this complexity, the generator would need to be able to both create new as wel as update existing POMs. And there are different preferences on POM design, so each project does it differently.

I think this is pretty impossible, but if some commercial party would implement it, they may make good money with it. Probably this would require AI.

Evilweed commented 4 months ago

Should be good enough to fast-track beautiful code generation.

GeorgeFischhof commented 4 months ago

Hi @refactoreric @Evilweed yeah, really it seems to be complicated, but going on with @Evilweed 's idea, perhaps playwright could contain several templates to allow the user to select from them, also user could send in / create similar templates, that would be good (yes, requires human resources, but for example they could be "community given / created" stuff, which could be browsed in a repo.

POM / URL the similar thing: user could be able to define which URL part gives the the same page, and which does not. Like to REST API's URLs https://base_url/api_version/item/{ID}/sub_item/{ID}?page={Number}&page_length={Number} points to same page

BR, George