Hello guys, I'd like to ask your best practice abo...
# best-practices
b
Hello guys, I'd like to ask your best practice about a problem: I have an API that returns me 2 values. ID and Code I want to invoke this function several times during my test run, and I want to save all the IDs and Codes and work with them inside my tests for invoking other APIs. I was thinking the following solution to differentiate them and use them with the
this.
keyword inside the test:
Copy code
ts
createIdAndCode() {
...
cy.wrap(response.body.data.id).as(`id${response.body.data.code}`);
cy.wrap(response.body.data.code).as(`code${?????}`);
...
}
I don't know how to differentiate the different ID and Codes when invoking inside test:
Copy code
ts
it('test', () => {

ApiHandler.createIdAndCode()
ApiHandler.createIdAndCode()

ApiHandler.useIdInRequest(...) // first ID
ApiHandler.useCodeInRequest(...) // first code

ApiHandler.useIdInRequest(...) // second ID
ApiHandler.useCodeInRequest(...) // second code
});
Whats the best practice to achieve this? I really don't want to pass a parameter for the two functions for naming those two values, since i want it to be generally used, and the "stored" names should be the "same" (except the dynamic value) across the fw.
3 Views