Skip to main content

Examples

Here are some example projects and use cases that demonstrate how to use Chathai effectively.

Basic Login Test Suite

This example shows how to create a basic login test suite:

// Generated Cypress test script
describe('Login Tests', () => {
  it('should login with valid credentials', () => {
    cy.visit('/login');
    cy.get('[data-test=username]').type('validuser');
    cy.get('[data-test=password]').type('validpass');
    cy.get('[data-test=login-button]').click();
    cy.url().should('include', '/dashboard');
  });

  it('should show error with invalid credentials', () => {
    cy.visit('/login');
    cy.get('[data-test=username]').type('invaliduser');
    cy.get('[data-test=password]').type('invalidpass');
    cy.get('[data-test=login-button]').click();
    cy.get('[data-test=error-message]').should('be.visible');
  });
});

E-commerce Test Suite

Example of a more complex e-commerce test suite:

// Generated Cypress test script
describe('E-commerce Tests', () => {
  it('should add item to cart', () => {
    cy.visit('/products');
    cy.get('[data-test=product-card]').first().click();
    cy.get('[data-test=add-to-cart]').click();
    cy.get('[data-test=cart-count]').should('have.text', '1');
  });

  it('should complete checkout process', () => {
    cy.visit('/cart');
    cy.get('[data-test=checkout-button]').click();
    cy.get('[data-test=shipping-form]').within(() => {
      cy.get('[name=address]').type('123 Main St');
      cy.get('[name=city]').type('Anytown');
      cy.get('[name=zip]').type('12345');
    });
    cy.get('[data-test=payment-form]').within(() => {
      cy.get('[name=card]').type('4111111111111111');
      cy.get('[name=expiry]').type('12/25');
      cy.get('[name=cvv]').type('123');
    });
    cy.get('[data-test=place-order]').click();
    cy.url().should('include', '/confirmation');
  });
});

API Testing Example

Example of API testing with Chathai:

// Generated Cypress test script
describe('API Tests', () => {
  it('should get user profile', () => {
    cy.request({
      method: 'GET',
      url: '/api/users/1',
      headers: {
        'Authorization': 'Bearer token123'
      }
    }).then((response) => {
      expect(response.status).to.eq(200);
      expect(response.body).to.have.property('name');
      expect(response.body).to.have.property('email');
    });
  });

  it('should create new user', () => {
    cy.request({
      method: 'POST',
      url: '/api/users',
      body: {
        name: 'John Doe',
        email: 'john@example.com'
      }
    }).then((response) => {
      expect(response.status).to.eq(201);
      expect(response.body).to.have.property('id');
    });
  });
});