question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Passing parameters to cypress using cli

See original GitHub issue

Hi,

Is There a way we can pass command line arguments to a cypress script in order to make it truly scalable .

To explain in detail , We have a script a.js That selects some values from list boxes(As of now these values are hardcode) . If there is a way we can parametrize these values , then the same script can be used to select multiple values

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
must-git-goodcommented, Apr 24, 2019

krishvv,

I’m pretty sure you can already achieve what you want here through the use of environment variables (which you can specify in the command line). While your use case is slightly different, see https://on.cypress.io/configuration-api#Usage for a general example.

We, for example, load up a bunch of different configurations depending on our environment. You can extend this beyond just route/visit. The note at the end of the page is especially important to remember…it’s just js, so you can make things as programmatically variable as you’d like.

So, loosely, in your case, you might have a cypress/config/ folder which contains (in .js or json, depending on your setup) a legalname.js, releaselevel.js, (etc). Which config context is invoked here is called (from the example above) from the cli when you open Cypress.

Then within that file you define variable that are different for each setup. So your code becomes:

it('.select() - select an option in a element', () => {
  cy.get(  ${Cypress.config('releaseVersion')}  )
    .select( ${Cypress.config('graphicsDriverOptions')} ) 
 })

Of course that’s just a general abstraction after a brief glance at what you need. But it should give an idea of how to accomplish what you want. It’s probably not the only solution, but it’s the one that seems to be the easiest ‘fit’ for your situation. Hope it helps.

2reactions
jennifer-shehanecommented, Apr 24, 2019

Issues in our GitHub repo are reserved for potential bugs or feature requests. This issue will be closed since it appears to be neither a bug nor a feature request.

We recommend questions relating to how to use Cypress be asked in our community chat. Also try searching our existing GitHub issues, reading through our documentation, or searching Stack Overflow for relevant answers.

Alternatively, signing up for any of you paid plans gives you access to our team for support via email. If you would like something higher touch, we also offer screen sharing and workshops with our premium support options.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Command Line - Cypress Documentation
When calling a command using npm run , you need to pass the command's arguments using the -- string. For example, if you...
Read more >
How do I pass Cypress CLI arguments in the --env with a space?
From the documentation, it says "Pass several variables using commas and no spaces". So, off the bat, it sounds like what you're trying...
Read more >
How to pass command line options to Cypress? - Knapsack Pro
IMPORTANT: Only argument listed in Cypress CLI options list work. If you want to pass options related to Node you should use NODE_OPTIONS...
Read more >
Command Line - cypress - w3resource
json file and then call it from an npm run script. Whenever you call a command using npm run, you will have to...
Read more >
Part 21 - Run Cypress Tests from Command Line - YouTube
Part 21 - Run Cypress Tests from Command Line | Pass Environment Variables from Command Line.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found