When using Playwright, there may arise a requirement to reuse a specific UUID that has been defined in one test within another

I have two separate tests running in parallel, each creating a different company in my test environment.

However, I need to access the uuid of both companies in later tests. I am looking for a way to store these uuids so they can be used across all subsequent tests.

While I am aware of playwright fixtures, it doesn't seem like they can be redefined within a test. This limitation is not explicitly mentioned in the documentation.

Although storing uuids goes against the principle of keeping each test separate, it is a business requirement in my case.

Answer №1

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());
  });
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Typescript: Extracting data from enum items using types

I am facing a challenge with an enum type called Currency. I am unable to modify it because it is automatically generated in a graphql schema. However, I need to utilize it for my data but I'm unsure of how to go about doing so. enum Currency { rub ...

Issue encountered with Ionic and ssh2: process.binding is not supported

I am currently delving into the world of Ionic and experimenting with creating a basic application that utilizes SSH2 to establish an ssh connection between the app and a server. Here is a breakdown of the steps I took to encounter the issue: Steps to Rep ...

Expanding Material UI functionality across various packages within a monorepository

Currently, I am using lerna to develop multiple UI packages. In my project, I am enhancing @material-ui/styles within package a by incorporating additional palette and typography definitions. Although I have successfully integrated the new types in packag ...

Make sure that every component in create-react-app includes an import for react so that it can be properly

Currently, I am working on a TypeScript project based on create-react-app which serves as the foundation for a React component that I plan to release as a standalone package. However, when using this package externally, I need to ensure that import React ...

What is the reason for sending a single file to the server?

A function called "import File" was developed to send multiple files to the server, but only one file is being received. Input: <input type="files" id="files" name="files" multiple onChange={ (e) => this.importFile(e.target.files) } ...

What methods can you use to identify obsolete or inactive code within an Angular project?

For over a year, my team and I have been dedicated to developing an innovative angular application. As we engage in the ongoing process of code refactoring, our objective is to eliminate any unnecessary or obsolete code from our repository. We are seeking ...

Building a hybrid application in Angular using UpgradeModule to manage controllers

I am currently in the process of upgrading a large AngularJS application using UpgradeModule to enable running AngularJS and Angular 6 simultaneously without going through the preparation phase, which typically involves following the AngularJS style guide. ...

Discovering the number of items that have been filtered in isotope-layout using React and Typescript

Currently, I am utilizing the isotope-layout library within a React (Typescript) project. Although I have successfully implemented filtering on my page, I am unsure of how to retrieve the count of the filtered items. Upon loading the page, Isotope is init ...

Modify typescript prior to typechecking

Consider the following TypeScript file: class A { private x? = 0; private y? = 0; f() { console.log(this.x, this.y); delete this.x; } } const a = new A(); a.f(); When building it in webpack using awesome-typescript-loader ...

JavaScript Looping through multiple files for upload will return the last file in the series

I'm currently working on implementing a multiple file upload feature using JavaScript. Within my HTML, I have the following input: <input type="file" (change)="fileChange($event,showFileNames)" multiple /> When the onChange event is triggere ...

Typescript - filtering out null values from JSON object

I am facing an issue with my service method that saves a date on the server. When this method sends the date to the server, it includes fields with null values in the JSON. How can I exclude these fields with null values? public create<T>(post: any) ...

Authentic property does not reveal its contents

Currently, I am utilizing Angular2 and my goal is to only display a component if a certain property is true. The issue arises when trying to show the <sci-company-form> element when the sci variable is set to true. When setting public sci: boolean = ...

How to toggle visibility of multiple div elements in ReactJS

When working in react-js, I encountered a situation where two div elements and two buttons were used. Clicking the first button displayed the first div and hid the second div. Conversely, clicking the second button showed the second div and hid the first d ...

What steps can be taken to implement jQuery within an Angular 15 npm package?

In my development process, I often create my own npm packages using Angular and Typescript. One of the packages I am currently working on is a PDF viewer service, which includes a file named pdf-viewer.service.ts with the following code: import { Behavior ...

The file could not be located on the server during the project build and upload process

Presently, I'm engrossed in a project involving Angular 9 and ASP Core 3. You can find the website at: Nevertheless, encountering an error when trying to access this URL: http://mag-testcpl.astromap.ir/assets/vendors/global/toastr.css The culprit ...

Entering information into fluctuating object fields

Suppose I have a dynamic object with a union type: data: {[key in 'num' | 'str' | 'obj']: number | string | object}; I set the object properties as follows: data.num = 1; data.str = 'text'; data.obj = {}; E ...

What causes the unexpected behavior of the rxjs share operator when used with an observable in a service?

I attempted to utilize the rxjs share operator in two distinct manners. Implementing it in the component Component: constructor() { const obs1 = interval(1000).pipe( tap(x => console.log('processing in comp1')), map(x => x ...

At what point do we employ providers within Angular 2?

In the Angular 2 documentation, they provide examples that also use HTTP for communication. import { HTTP_PROVIDERS } from '@angular/http'; import { HeroService } from './hero.service'; @Component({ selector: 'my-toh&ap ...

Tips for importing several makeStyles in tss-react

When upgrading from MUI4 to MUI5 using tss-react, we encountered a problem with multiple styles imports in some files. const { classes } = GridStyles(); const { classes } = IntakeTableStyles(); const { classes } = CommonThemeStyles(); This resulted in ...

Problem with Angular Slider

I'm in the process of creating a carousel component in Angular, but I'm facing an issue where the carousel is not appearing as it should. Below is the code for my carousel component. carousel.component.html: <div class="carousel"> ...