UNPKG

cypress-bootstrap

Version:

Cypress Bootstrap is a project scaffolding tool that sets up a Cypress automation framework with a standardized folder structure and Page Object Model (POM) design. It helps teams quickly start testing with built-in best practices and sample specs.

54 lines (50 loc) 2.37 kB
import { apiEndpoints } from '../../testbase/apiEndpoints'; import { HttpMethod, StatusCodes } from '../../support/Enums'; import { ProductResponses } from '../../testbase/modals/responses/ProductResponses'; import ProductTypesClient from '../../testbase/apiClients/ProductTypesClient'; import { PRODUCT_TYPE_DETAILS } from '../../testdata/dataObjects/ProductTypes'; import { ProductRequests } from '../../testbase/modals/requests/ProductRequests'; import { PRODUCT_DETAILS } from '../../testdata/dataObjects/Product'; describe('Product API Test Suite', () => { it('Get all products', { tags: ['@products', '@smoke'] }, () => { cy.sendApiRequestDef(apiEndpoints.products, HttpMethod.GET, null, StatusCodes.OK).then( response => { expect(response).to.be.an('array'); expect(response).to.have.length.greaterThan(0); Cypress.env('productId', response[0].id); } ); }); it('Get product by Id', { tags: ['@products', '@smoke'] }, () => { cy.sendApiRequestDef( apiEndpoints.productById(Cypress.env('productId')), HttpMethod.GET, null, StatusCodes.OK ).then(response => { const responseBody = response as ProductResponses.ProductResponse; expect(responseBody).to.have.property('id'); expect(responseBody.id).to.eq(Cypress.env('productId')); expect(responseBody).to.have.property('name'); expect(responseBody).to.have.property('productTypeId'); expect(responseBody).to.have.property('price'); }); }); it('Create product', { tags: ['@products', '@smoke'] }, () => { // At this point, I am using the product type client to create a product type easily. No redundant code, just calling the client with test data. ProductTypesClient.createProductType(PRODUCT_TYPE_DETAILS).then(response => { const productTypeResponse = response as ProductResponses.ProductResponse; //Then create a product request using the modal (eliminate human error) const productRequest = new ProductRequests.Request(); const productRequestBody = productRequest.createProductRequest(PRODUCT_DETAILS); productRequestBody.productTypeId = productTypeResponse.id; cy.sendApiRequestDef( apiEndpoints.products, HttpMethod.POST, null, StatusCodes.CREATED, productRequestBody ); }); }); });