Prachit Patil
Prachit Patil

Reputation: 461

Need help in cypress to read data from excel/csv

I am trying to read the test cases from excel and then pass it to cypress to execute it.

What I want is that my excel will be consist of all sites

abc.com, example.com ,xyz.com

like 50 to 100 such a sites

and then pass it to cypress and cypress will execute each site for 100 sites.

I tried to this by reading cypress plugins but not so sure on how I can do this. Any guidance will be very helpful

My goal is to run test cases like the site is loading for more than 100 sites

Any suggestions?

Upvotes: 0

Views: 2596

Answers (1)

Zach Bloomquist
Zach Bloomquist

Reputation: 5881

You could use the Cypress Module API to do this programmatically, by changing the baseUrl of the tests each time.

Something like this should work, just as a Node script:

const cypress = require('cypress')

const baseUrlList = loadSitesFromExcel()

// create a recursive Promise chain
function runTests(i = 0) {
  if (i == baseUrlList.length) {
    return Promise.resolve()
  }

  return cypress.run({
    config: {
      baseUrl: baseUrlList[i]
    }
  })
  .then((results) => {
    // do something with results, then run next test
    return runTests(i + 1)
  })
}

// begin
runTests()

Upvotes: 1

Related Questions