Vladi95
Vladi95

Reputation: 41

CypressJS automated CrossBrowserTesting

I've installed cypress framework on my project.

I already have multiple viewports tests running successively on my app.

Is it possible to automate cross browser testing, so I don't have to select a browser extension to run my test on?

Thanks in advance! :-)

Upvotes: 2

Views: 163

Answers (1)

Muditha Perera
Muditha Perera

Reputation: 1252

Yes, it is possible. In this case, there can be scenarios that you can run concurrently and there can be scenarios you need to run sequentially. I'll add the solution which I found for both problems.

For this, we need the package.json file. ( If you don't have it do an npm init ) and it will guide you through making the pachage.json

Then let's say we have two test files 1 can be run concurrently, and the other one should not be executed concurrently. let's name them as concurrently.js and sequentially.js

To run the tests sequentially ad your cypress command inside the scripts JSON object. Ex:

  "scripts": {
    "cy:sequence:chrome": "cypress run --browser chrome --spec **/sequentially.js",
    "cy:sequence:firefox": "cypress run --browser firefox --spec **/sequentially.js",
  }

Now you just need to run npm run command to sequence execution, in this case, it will be

npm run cy:sequence:chrome && npm run cy:sequence:firefox

Then if you need concurrent execution, we need to add an npm package [concurently][1]

You can install it with npm i concurrently Now like we did before we need to add the concurrently.js execution commands to scripts. Here we are using the concurrently package notations to add it. ( check the above URL )

so our final scripts package looks like,

  "scripts": {
    "cy.concurent:run" : "concurrently \"cypress run --browser chrome --spec **/concurrently.js\" \"cypress run --browser firefox --spec **/concurrently.js\"",
    "cy:sequence:chrome": "cypress run --browser chrome --spec **/sequentially.js",
    "cy:sequence:firefox": "cypress run --browser firefox --spec **/sequentially.js",
  }

if the above addition is not clear, we need to add the commands as quotes with concurrently word being the first word. it should be like

"concurrently "command1" "command2" "

Now if you need to run the tests concurrently in multiple browsers, you just need to run

npm run cy.concurent:run

My only doubt is about the reporting, you might need to add an additional config to save browser-specific videos and reports. If not it might save the data of last execution.

Hope this helps, Cheers. [1]: https://www.npmjs.com/package/concurrently

Upvotes: 1

Related Questions