playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature] Allow custom command-line arguments in @playwright/test

Open jjeff opened this issue 3 years ago • 59 comments

When using the Playright test runner, I would like to be able to pass a command-line argument to my Playwright test, similar to this:

npx playwright test --build-path=/path/to/my/application/build/

However, this produces the following error:

error: unknown option '--build-path=/path/to/my/application/build/' 

There should be a way to pass custom command-line arguments to Playwright. This Stack Overflow thread shows that others are looking for this too.

Maybe I'm missing something, but it appears that right now, the only way to pass custom arguments is through environment variables, which seems like an awkward solution.

jjeff avatar Nov 16 '21 02:11 jjeff

Environment variables are currently the preferred solution.

JoelEinbinder avatar Nov 16 '21 18:11 JoelEinbinder

Environment variables are currently the preferred solution.

Fair enough.

jjeff avatar Nov 16 '21 18:11 jjeff

I'm also interested in custom parameters. From an internal requirements document: Various use cases need to be supported, without change to configuration. Preferably as simple as a command line parameter, since environment variables are not self-explanatory.

  • Testing from developer/tester machine
  • Testing from CI
  • Testing against different environments (master, wip, rc, production, etc.) (various variables are dependent on an environment 'profile')
  • Selecting a predefined type of tests to run (smoke, acceptance, technical release tests, …?)
  • Selecting a predefined area of tests to run (bookkeeping, payAndCollect, salesInvoicing, etc.)
  • Selecting specific tests.
  • Option to run without re-creating a company (useful in CI)

Several of these use cases could be solved with existing command line arguments. But some others can't.

Since Playwright does not have support for custom command line arguments, I was thinking to just create a wrapper script which sets the appropriate environment variables based on command line arguments and then calls 'playwright test'. But it's nicer if that's not needed.

The ideal solution would also display available arguments (for example with a --usage option) and would show a helpful error+usage message if some arguments were incorrect.

refactoreric avatar Feb 16 '22 19:02 refactoreric

I also believe custom command-line arguments would be helpful. I also respect the intent to be helpful and provide guidance to those learning to use the tool. However, to empower deeper integrations, even a single new command-line argument named --custom for example would be a welcome addition. With something like that, we could pass some JSON.

Thank you.

chadcampbell avatar Mar 02 '22 17:03 chadcampbell

Custom command-line arguments feature is much needed, since even in protractor we lot of dependency with this command line arguments. So expecting this feature to be introduced, so it will be added advantage

saurabh4888 avatar Mar 16 '22 16:03 saurabh4888

+1 this is a must, when we have multiple MFEs and we want to do e2e tests we need to pass variables to configure how we want the tests to run. I will try to submit a PR with these changes as soon as possible so you can review.

brunomartinspro avatar Jun 21 '22 10:06 brunomartinspro

+1 to have custom command-line arguments feature. For example, base-url is dynamic in our application and changed every pull-request(PR number is dynamic part of url). So, we need to pass PR number as argument to change base-url. Of course we can do it with scripts, but it would be nice to pass such custom arguments via command-line. @brunomartinspro any updates about it?

tsheptitskiy avatar Aug 30 '22 17:08 tsheptitskiy

+1 . For me it would be great if I can pass arguments to properly configure the test we want to run. One example, I need it to test against different environments + select specific tests

duartmig avatar Oct 06 '22 08:10 duartmig

+1. I would use custom arguments to be passed to handle some browserstack related stuff.

anandhaprakash-mani avatar Oct 19 '22 20:10 anandhaprakash-mani

+1 Definitely ability to pass custom arguments to test suites

QAscoop avatar Nov 16 '22 00:11 QAscoop

+1. Would be very very useful and avoid having a proliferation of .spec.js files for every single config tweak you want to use for a different scope of tests.

vrseraphin avatar Nov 21 '22 17:11 vrseraphin

+1. This would be very useful.

MMark4 avatar Dec 11 '22 08:12 MMark4

+1 - this is frustrating without this ability

HuckleberryCarignan avatar Dec 15 '22 19:12 HuckleberryCarignan

Does a solution exist today to scour the data for example: 2 with process.args?

playwright test myfile 2

Lineaire avatar Dec 26 '22 18:12 Lineaire

+1. This would be very useful.

mykhailo-kobylianskyi avatar Jan 19 '23 18:01 mykhailo-kobylianskyi

+1

iklimchuk avatar Feb 11 '23 20:02 iklimchuk

+1

nancytran avatar Mar 02 '23 14:03 nancytran

+1

jurasek18 avatar Mar 09 '23 15:03 jurasek18

+1

parsch avatar Mar 09 '23 15:03 parsch

+1

ranjisept9 avatar Mar 17 '23 06:03 ranjisept9

+1

kamilulianowski-qa avatar Mar 24 '23 13:03 kamilulianowski-qa

+1

kamilulianowski-qa avatar Apr 03 '23 15:04 kamilulianowski-qa

+1

andliu-swi avatar Apr 06 '23 00:04 andliu-swi

+1, this is must feature

skumar09 avatar Apr 08 '23 06:04 skumar09

+1 To give an example - we would sometimes like to run with soft exceptions and sometimes with hard (particularly for screenshots) - we assumed we could do this with a custom command line arg and look for the arg in a wrapper function in our own code. IMO Env vars are a little messier (is it set? is it still set? did someone set it and forget it?)

JonMarbach avatar Apr 28 '23 21:04 JonMarbach

+1 I love to pass environment variables from command line option, something like

npx playwright test -Denv=dev

python012 avatar May 29 '23 09:05 python012

+1

tonextone avatar Jun 08 '23 08:06 tonextone

+1

RefaelEX avatar Jun 22 '23 14:06 RefaelEX

not yet? :( +1

jfibarra avatar Jun 27 '23 16:06 jfibarra

+1

kelseyaubrecht avatar Jul 21 '23 22:07 kelseyaubrecht