Test using Cypress can be only ran via Test Runner. To open Cypress Test Runner enter the below command from your project directory
.\node_modules\.bin\cypress open
This will open the Test Running, but by default the Test Runner will start on the lite version of Chromium browser named Electron.
This is a stripped down version of the Google Chrome. Test Runner also has supports Chrome which we will see in the upcoming section.
Create and Save a js file named Test with Below code
Test.js
describe('My First Test Suite', function(){
it('My FirstTestCase',function(){
cy.visit("https://en.wikipedia.org/wiki/Ghost_in_the_Shell_(2017_film)");
cy.title().should('eq', 'Carolina Panthers Official Shop | Jerseys, Shirts, Hats & Accessories');
})
})
By Default when project starts it will create us some sample test to work upon. It will be available under the base directory\interaction\examples. Create this Test script under the example folder which will open a browser and visit a page as well a validate its title. We have encapsulated the test inside Mocha(Javascript framework)
Save this script and refresh the Test Runner, you will find your script listen down. Just click the file to start the Test.
When clicked it will open default Electron and execute the test. Depending open the test we have two operation. 1. Visit an URL 2. Validate its Title. Each of which is listed in the left site with the step no.
You can also find following,
1. Restart all the Test - Press 'R' inside Electron.
2. No of Test Passed - Count in Green on top
3. No of Test Failed - Count in Red on top
4. Time Taken to Complete Test - Time in seconds beside failed test count.
5. Snap shot of the result between each test step - Click the step to view it in Right Side.
Inside the Terminal you can also find the API request and response for the current test.
Actually there are other ways to run your cypress test, that is via command line,
.\node_modules\.bin\cypress run
This will call the test to run by calling the API not the browsers and you can see their result in the console itself.
This following command will run the test under the browser(Electron) and we can also specify a single test with the argument named --spec.
.\node_modules\.bin\cypress run --headed
or
.\node_modules\.bin\cypress run --headed --spec 'cypress/integration/user/**/*
There are several other argument for CLI like defining a browser, path to the project or to whether record our project or not..etc. For more information check this link - Click to Open