# Automated Tests
Automated Tests can be added to your scenarios to verify they are working as expected. Each time the scenario is changed, the tests are re-run and the results displayed in the dashboard.
# Cypress
https://www.cypress.io/ is a complete end-to-end testing experience which can be used to verify that the Katacoda scenarios are working as expected.
You can learn more about Cypress at https://docs.cypress.io/guides/overview/why-cypress.html
# Cypress Test Helpers
A collection of Cypress test helpers have been created to take the heavy lifting out of creating tests for your scenarios. These helpers capture the core functionality required to
Function | Details | Example |
---|---|---|
startScenario | Trigger the start of the scenario navigation. This will automatically go to the scenario being tested on Katacoda | cy.startScenario() |
terminalType | Type and execute commands within the Terminal | cy.terminalType("uname"); |
terminalShouldContain | Asset the terminal commands certain text | cy.terminalShouldContain('Linux'); |
contains | Asset the scenario steps contains certain text | cy.contains('Start Scenario'); |
editFile | Open a file in the editor | cy.editFile('app.js') |
writeToEditor | Use the editor to write to a file | cy.writeToEditor('Start Scenario'); |
These helpers can be combined with the built-in functionality of Cypress to meet your requirements. More details of the built-in helpers can be found at https://docs.cypress.io/api/api/table-of-contents.html
# Creating The First Test
- Within the scenario you want to test, add a folder called
.cypress
. - Create a file with the suffix
_spec.js
such astest1_spec.js
. This will contain your Cypress tests you want to run. Katacoda supports splitting your tests over multiple files but subdirectories are not supported. - Create your Cypress test using the helpers above. Ensure that
cy.startScenario()
is called to load your scenario. - Commit the test to Git and push to the remote Git Repository to trigger Katacoda re-processing.
- Visit the Dashboard to view the results.
A complete example can be found at https://github.com/katacoda/scenario-examples/tree/main/automatedtest
# Example
Below is an example of a test to verify the Katacoda scenario.
describe('My First Test', () => {
before(() => {
cy.startScenario() // This would automatically go to the scenario being tested. Without this the test will fail.
});
it('finds the content "Start Scenario"', () => {
cy.contains('Start Scenario');
});
it('finds can run commands', () => {
cy.terminalType("uname");
cy.terminalShouldContain('Linux');
})
})
A complete example can be found at https://github.com/katacoda/scenario-examples/tree/main/automatedtest
More examples of using Cypress can be found at https://docs.cypress.io/examples/examples/recipes.html#Fundamentals
# View Results
The results of the test execution can be viewed in the Dashboard at https://dashboard.katacoda.com/content/testruns. From the dashboard, you can also re-run all of your tests at once.
When you go into the testruns logs you will see the output from Cypress execution so if a failure happens, you will be able to debug the issue.
# Under the Covers
What is happening under the covers? See the video of a test execution below.
This is happening on every change to make sure your scenarios and environments are ready for your learners.