applitools / cypress-applitools-webinar

Companion Code to "Functional and Visual Testing with Cypress.io and Applitools" webinar

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cypress-applitools-webinar

Companion Code to "Functional and Visual Testing with Cypress.io and Applitools" webinar

Functional tests

Tests are in the folder cypress/integration

The test writing and organization are covered in slides at https://slides.com/bahmutov/flawless-tests

Test setup

  • installed Cypress with npm i -D cypress
  • scaffolded Cypress folder with npx @bahmutov/cly init
  • set the base url in cypress.json file
{
  "baseUrl": "http://localhost:4100"
}
  • manually made a test user account: tester@test.com password1234 and set the user profile picture to https://robohash.org/6FJ.png?set=set3&size=150x150

robot

  • looked at the login action. The user logs in via XHR call to POST http://localhost:3000/api/users/login which returns JWT and sets it in local storage under jwt key. The payload to login is {user: {email: "tester@test.com", password: "password1234"}}. Implemented the same functionality using cy.request by grabbing the user account object from cypress.json environment object
describe('Conduit', () => {
  beforeEach(() => {
    cy.request('POST', 'http://localhost:3000/api/users/login', {
      user: Cypress.env('user'),
    })
      .its('body.user.token')
      .should('exist')
      .then((token) => {
        localStorage.setItem('jwt', token)
      })

    cy.visit('/')
  })

  it('shows feeds', () => {
    cy.contains('a.nav-link', 'Your Feed').should('have.class', 'active')
    cy.contains('a.nav-link', 'Global Feed').should('not.have.class', 'active')
  })
})

And we are in business!

Shows feeds test

Tip: find different ways to quickly login in Logging in recipes.

About

Companion Code to "Functional and Visual Testing with Cypress.io and Applitools" webinar

License:MIT License


Languages

Language:JavaScript 50.0%Language:CSS 49.4%Language:HTML 0.6%