Hi! I'm trying to expand my cypress project to te...
# best-practices
b
Hi! I'm trying to expand my cypress project to test API too, since Cypress can do it with ease. I am currently organizing my project from a page object model perspective. I could do it the same way from API perspective... Like:
Copy code
javascript
class InvoicesApi {
    createInvoice(body) {
    ...
    }
    
    printInvoice(id) {
    ...
    }
    
    deleteInvoice(id) {    
    ...
    }
    
    getInvoice(id) {    
    }
}

export default new InvoicesApi();
And on the tests, just invoke the "page object", the same way we do from UI.
Copy code
javascript

it("create invoice and check default values", () => {
    invoicesApi.createInvoice(invoiceBody).then((response) => {
        expect(response.status).to.eq(201);
        let invoiceId = response.body;
        invoicesApi.getInvoice(invoiceId)        
        ....                
    });
});
It would allow me to gain some maintenance points, but this model is made for UI (pages), not API. I wonder if there is any model to use on API to allow reuse. What you guys think about it?
3 Views