Today, I made a breakthrough discovery - the power of utilizing the .env file. Surprisingly, I found that with playwright, I can modify an environment variable (previously assumed to be read-only) to suit my needs.
After creating my company and setting up my desired variables, I seamlessly carried out my test procedures without the need for manual cleanup or resetting at the end of each session.
I have omitted the details of the setter and getter functions as they are readily available in the playwright documentation, but let me know if you require them.
Here's a snippet from my .env file:
UUID_COMPANY_1=uuid_of_the_first_company
Below is a portion of my code implementation:
test.describe('Create and test stuff in my company 1', () => {
const context = getInitializedContext();
// First test scenario
test('Create and configure Company 1', async ({ page }, workerInfo) => {
console.log(retrieveUuidCompany1());
const email = new emailManager();
const baseUrl = workerInfo.project.use.baseURL;
let locatorConfiguration = retrieveLocatorConfiguration(context);
// Creating a company with a first user
await logInAdmin(page, baseUrl, locatorConfiguration);
const companyAndFirstUser = await createCompanyAndFirstUser(
page,
locatorConfiguration,
USER_1,
COMPANY_1_CONFIGURATION,
email,
context,
);
const uuidNewCompany = companyAndFirstUser['uuidCompany'];
setUuidCompany1(uuidNewCompany);
console.log(retrieveUuidCompany1());
// Additional test codes go here
});
// Second test scenario
test('Uuid company 1', async ({ page }, workerInfo) => {
console.log(retrieveUuidCompany1());
});
});