Skip to content

Instantly share code, notes, and snippets.

@slawekradzyminski
Created April 17, 2021 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slawekradzyminski/3cb6f3d0cb9140252aa4ea3005da84cf to your computer and use it in GitHub Desktop.
Save slawekradzyminski/3cb6f3d0cb9140252aa4ea3005da84cf to your computer and use it in GitHub Desktop.
/// <reference types="cypress" />
context('Register tests', () => {
beforeEach(() => {
cy.visit('/register')
})
it('Should register', () => {
cy.get('[name=firstName]').type(getRandomString())
cy.get('[name=lastName]').type(getRandomString())
cy.get('[name=username]').type(getRandomString())
cy.get('[name=password]').type(getRandomString())
cy.get('.btn-primary').click()
cy.url().should('include', 'login')
cy.get('.alert').should('have.text', 'Registration successful')
})
it('register should not work - empty fields validation', () => {
cy.get('.btn-primary').click()
cy.get(".form-group").first().find('.invalid-feedback').contains('First Name is required')
cy.get(".form-group").eq(1).find('.invalid-feedback').contains('Last Name is required')
cy.get(".form-group").eq(2).find('.invalid-feedback').contains('Username is required')
cy.get(".form-group").eq(3).find('.invalid-feedback').contains('Password is required')
cy.get(".invalid-feedback").should('have.length', 4)
cy.get("[name=firstName]").should('have.class', 'is-invalid')
cy.get("[name=lastName]").should('have.class', 'is-invalid')
cy.get("[name=username]").should('have.class', 'is-invalid')
cy.get("[name=password]").should('have.class', 'is-invalid')
})
function getRandomString() {
return Math.random().toString(36).substring(7)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment