Portal uses Cypress for automated testing.
Cypress is a next generation front end testing tool built for the modern web. It address the key pain points developers and QA engineers face when testing modern applications. For more information check offical documentation here.
Cypress make it possible to:
- Set up tests
- Write tests
- Run tests
- Debug Tests
This enables you to write faster, easier and more reliable tests.
Cypress enables you to write all types of tests:
- End-to-end tests
- Integration tests
- Unit tests
Cypress can test anything that runs in a browser.
-
Tasks:
- Visit the page at
/posts/new
. - Find the
<input>
with class post-title. - Type
"My First Post"
into it. - Find the
<input>
with class post-body. - Type
"Hello, world!"
into it. - Click the element containing the text
Submit
. - Grab the browser URL, ensure it includes
/posts/my-first-post
. - Find the
h1 tag
, ensure it contains the text"My First Post"
.
- Visit the page at
-
Your test case look like:
describe('Post Resource', () => { it('Creating a New Post', () => { cy.visit('/posts/new') // 1. cy.get('input.post-title') // 2. .type('My First Post') // 3. cy.get('input.post-body') // 4. .type('Hello, world!') // 5. cy.contains('Submit') .click() // 6. cy.url() // 7. .should('include', '/posts/my-first-post') cy.get('h1') // 8. .should('contain', 'My First Post') }) })
-
Copy
cypress.json.example
ascypress.json
in the same directory.cp cypress.json.example cypress.json
For more configuration options please refer here.
-
Run the following command to run cypress
- Headless mode
npm run cypress
- GUI mode
npm run cypress-open
- Headless mode