playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature] Add assertion in codegen: recording window should have a button to add assertion to code

Open GeorgeFischhof opened this issue 2 years ago • 5 comments

Hi,

it would be good to have an assertion type code generation, not just action type. For example to check a text, I can not locator.has_text so I should use some other locator and add it to expect.has_text.

firstly I wanted to write that recorder should have this function, but I found this issue #13900 (separate selector generator) and I think this feature would be much better in a separate selector generator

BR, George

GeorgeFischhof avatar Jun 16 '22 12:06 GeorgeFischhof

It's worth noting that the cypress team has abandoned their code editor

unlikelyzero avatar Jun 16 '22 18:06 unlikelyzero

I did not use cypress, maybe there was some issue with that editor, and people did not use that. I do not know. But this editor is quite good, I think It worth to use and worth to develop further ;) I know about other not used editors ...

GeorgeFischhof avatar Jun 17 '22 08:06 GeorgeFischhof

@unlikelyzero Nope cypress studio is back. https://www.cypress.io/blog/2022/08/30/how-to-use-studio-in-cypress-10-7/ It can modify existing tests and do assertions using right click.

bugzpodder avatar Sep 12 '22 05:09 bugzpodder

Assertions to codegen would be a great addition. Here is an example use case:

  1. The subject matter expert of the application (who isn't familiar with coding) knows the critical workflows, can record the steps for a new test candidate
  2. They usually know which details are most important, eg. a VAT-code value that should be asserted. But they can't do it in codegen.
  3. If codegen would have assertion functionalities, they could generate the assertions as well.

Wilhop avatar Sep 15 '22 07:09 Wilhop

This feature exist in Selenium IDE and makes life much easier )

ysparrow avatar Sep 18 '22 10:09 ysparrow

+1

agilevic avatar Oct 10 '22 14:10 agilevic

It's worth noting that the cypress team has abandoned their code editor

Cypress has a Studio that supports assertion (right click on element shows assertion popup)

polRk avatar Oct 12 '22 12:10 polRk

+1

NikkTod avatar Nov 24 '22 22:11 NikkTod

This would be very useful! +1

Jannik-KJ avatar Nov 29 '22 12:11 Jannik-KJ

+1

patrick-mota avatar Dec 05 '22 13:12 patrick-mota

+1

Would also like to be able to generate the screenshot command (page or element) from the code-gen UI.

github-daniel-mcdonald avatar Dec 16 '22 19:12 github-daniel-mcdonald

+1 Also being able to set a priority order to selectors in the codegen or exclude elements like id when these are always dynamic.

Attic0n avatar Dec 19 '22 12:12 Attic0n

+1

I like the way it was implemented for https://testproject.io. Without assertions, generated code is like a record and play macro and not a test.

Btw, thank you for all the great work so far! Loving Playwright!

arpan-patelia avatar Dec 25 '22 17:12 arpan-patelia

+1

cfritschi avatar Dec 31 '22 15:12 cfritschi

+1

ch4r-ch4r avatar Jan 17 '23 05:01 ch4r-ch4r

+1

logicalpath avatar Jan 19 '23 22:01 logicalpath

How I see it:

  • while recording there is a shortcut to record expect on that element, for example Ctrl + Left mouse or what ever suits Dev team and it's not in collision with browsers shortcuts and button on Codegen editor
  • after expect is called you can elevate expect assertion methods for user to choose one with most frequently used on top like toBeVisible, toHaveText, toBe..

lmlikota avatar Jan 26 '23 12:01 lmlikota

Sounds good :)

GeorgeFischhof avatar Jan 26 '23 13:01 GeorgeFischhof

Is it possible to expand codegen by creating plugins etc? I would want to generate the PageObjectModal type of code using the playwright.

rahulbansal16 avatar Jan 26 '23 15:01 rahulbansal16

+1, about Cypress: Update as of August 30, 2022: Cypress Studio has been reimplemented in Cypress 10 as of version 10.7.0! I find it very useful and make assertions pretty easy :)

Kees0 avatar Jan 28 '23 14:01 Kees0

+1

mkosak avatar Feb 19 '23 23:02 mkosak

+1

dnascimento avatar Feb 20 '23 07:02 dnascimento

+1

github-daniel-mcdonald avatar Mar 29 '23 15:03 github-daniel-mcdonald

I can build this feature, but I need to understand. How it will be used in the workflow? If you want me to build this, set up a 15 min call https://calendly.com/rabansal/15min I can take it forward from there.

rahulbansal16 avatar Apr 15 '23 06:04 rahulbansal16

very important feature!

chensce avatar Jun 08 '23 08:06 chensce

Very needed feature!

nielsNocore avatar Jul 28 '23 13:07 nielsNocore

I use this for now: https://marketplace.visualstudio.com/items?itemName=csbun.playwright-extend https://github.com/csbun/playwright-vscode

Works great, it's based on playwright extension and add in vscode a new submenu in "Testing" with Assert, Wait.

I have to install playwright official extension, then this one, then uninstall the official one, reload and install the official one again to have the menu appear.

patrick-mota avatar Sep 13 '23 09:09 patrick-mota

Released in v1.40.0.

dgozman avatar Nov 16 '23 23:11 dgozman