New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

dotenv-processor

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dotenv-processor

This project demonstrates how to use `.env` files to manage environment variables in a Playwright project.

latest
npmnpm
Version
0.1.7
Version published
Weekly downloads
1
-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

Playwright Project with .env File Support

This project demonstrates how to use .env files to manage environment variables in a Playwright project.

Table of Contents

  • Introduction
  • Setup
  • Usage
  • Contributing
  • License

Introduction

This repository shows how to manually load environment variables from a .env file using Node.js built-in modules in a Playwright project.

Setup

Prerequisites

  • Node.js (version 12 or higher)
  • Playwright

Installation

Install dependencies:

npm install dotenv-processor@latest

or

yarn add dotenv-processor@latest

Environment Variables

  • Create a .env file at the root of the project. Add your environment variables in the format KEY=VALUE. For example:

    BASE_URL=https://example.com
    API_KEY=your_api_key_here
    

Usage

Loading Environment Variables

  • Modify your Playwright configuration file (e.g., playwright.config.ts) to load the environment variables by importing the loadEnv method from the dotenv-processor library and calling it as demonstrated below:

    import { defineConfig } from '@playwright/test';
    import { loadEnv } from "dotenv-processor";
    
    // Load environment variables
    loadEnv();
    
    export default defineConfig({
      use: {
        baseURL: process.env.BASE_URL,
        // other Playwright configurations
      },
      // other configurations
    });
    

Writing Tests

Use the environment variables in your test files as follows:

// example.spec.ts
import { test, expect } from '@playwright/test';

test('example test', async ({ page }) => {
  await page.goto(process.env.BASE_URL as string);
  // Perform actions and assertions using environment variables
});

FAQs

Package last updated on 18 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts